package views import ( "strconv" "strings" g "maragu.dev/gomponents" . "maragu.dev/gomponents/html" ) // PageInfo is the pagination state of a list view. // URLTemplate contains "{page}" as the placeholder for the page number, // e.g. "/repo/issues?status=open&page={page}". type PageInfo struct { Page int TotalPages int URLTemplate string } // Pagination renders previous/next links. It renders nothing for one page. func Pagination(p PageInfo) g.Node { if p.TotalPages <= 1 { return nil } url := func(n int) string { return strings.ReplaceAll(p.URLTemplate, "{page}", strconv.Itoa(n)) } return Nav(Class("pagination"), Aria("label", "Pagination"), Div(Class("pagination-prev"), g.If(p.Page > 1, A(Href(url(p.Page-1)), Class("pagination-btn"), g.Text("← Previous"))), ), Span(Class("pagination-info"), g.Text("Page "+strconv.Itoa(p.Page)+" of "+strconv.Itoa(p.TotalPages))), Div(Class("pagination-next"), g.If(p.Page < p.TotalPages, A(Href(url(p.Page+1)), Class("pagination-btn"), g.Text("Next →"))), ), ) }