package showcase
import "github.com/templui/templui/components/pagination"
templ PaginationDefault() {
@pagination.Pagination(pagination.Props{
Class: "mt-8",
}) {
@pagination.Content() {
@pagination.Item() {
@pagination.Previous(pagination.PreviousProps{
Href: "?page=1",
Disabled: false,
Label: "Previous",
})
}
@pagination.Item() {
@pagination.Link(pagination.LinkProps{
Href: "?page=1",
}) {
1
}
}
@pagination.Item() {
@pagination.Link(pagination.LinkProps{
Href: "?page=2",
IsActive: true,
}) {
2
}
}
@pagination.Item() {
@pagination.Link(pagination.LinkProps{
Href: "?page=3",
}) {
3
}
}
@pagination.Item() {
@pagination.Ellipsis()
}
@pagination.Item() {
@pagination.Next(pagination.NextProps{
Href: "?page=3",
Label: "Next",
})
}
}
}
}
Installation
templui add paginationimport "github.com/templui/templui/components/pagination"Examples
With Helper
package showcase
import (
"fmt"
"github.com/templui/templui/components/pagination"
)
templ PaginationWithHelper() {
{{ p := pagination.CreatePagination(5, 20, 3) }}
@pagination.Pagination() {
@pagination.Content() {
@pagination.Item() {
@pagination.Previous(pagination.PreviousProps{
Href: fmt.Sprintf("?page=%d", p.CurrentPage-1),
Disabled: !p.HasPrevious,
Label: "Previous",
})
}
// First page with ellipsis if needed
if p.Pages[0] > 1 {
@pagination.Item() {
@pagination.Link(pagination.LinkProps{
Href: "?page=1",
}) {
1
}
}
if p.Pages[0] > 2 {
@pagination.Item() {
@pagination.Ellipsis()
}
}
}
// Visible pages
for _, page := range p.Pages {
@pagination.Item() {
@pagination.Link(pagination.LinkProps{
Href: fmt.Sprintf("?page=%d", page),
IsActive: page == p.CurrentPage,
}) {
{ fmt.Sprint(page) }
}
}
}
// Last page with ellipsis if needed
if p.Pages[len(p.Pages)-1] < p.TotalPages {
if p.Pages[len(p.Pages)-1] < p.TotalPages-1 {
@pagination.Item() {
@pagination.Ellipsis()
}
}
@pagination.Item() {
@pagination.Link(pagination.LinkProps{
Href: fmt.Sprintf("?page=%d", p.TotalPages),
}) {
{ fmt.Sprint(p.TotalPages) }
}
}
}
@pagination.Item() {
@pagination.Next(pagination.NextProps{
Href: fmt.Sprintf("?page=%d", p.CurrentPage+1),
Disabled: !p.HasNext,
Label: "Next",
})
}
}
}
}
API Reference
Pagination
Root navigation container for pagination controls.
| Name | Type | Default |
|---|---|---|
Unique identifier for the pagination nav element. | | - |
Additional CSS classes to apply to the pagination container. | | - |
Additional HTML attributes to apply to the pagination element. | | - |
Content
List container that holds pagination items.
| Name | Type | Default |
|---|---|---|
Unique identifier for the content list element. | | - |
Additional CSS classes to apply to the content list. | | - |
Additional HTML attributes to apply to the content element. | | - |
Item
Individual list item that wraps pagination links or buttons.
| Name | Type | Default |
|---|---|---|
Unique identifier for the item element. | | - |
Additional CSS classes to apply to the item. | | - |
Additional HTML attributes to apply to the item element. | | - |
Link
Clickable link or button for page navigation.
| Name | Type | Default |
|---|---|---|
Unique identifier for the link element. | | - |
Additional CSS classes to apply to the link. | | - |
Additional HTML attributes to apply to the link element. | | - |
URL for the page link. Required for functional links. | | - |
Whether this page link represents the current page. | | |
Whether the link is disabled and non-clickable. | | |
Previous
Navigation button for going to the previous page.
| Name | Type | Default |
|---|---|---|
Unique identifier for the previous button. | | - |
Additional CSS classes to apply to the button. | | - |
Additional HTML attributes to apply to the button element. | | - |
URL for the previous page. | | - |
Whether the previous button is disabled (e.g., on first page). | | |
Text label to display alongside the chevron icon. | | - |
Next
Navigation button for going to the next page.
| Name | Type | Default |
|---|---|---|
Unique identifier for the next button. | | - |
Additional CSS classes to apply to the button. | | - |
Additional HTML attributes to apply to the button element. | | - |
URL for the next page. | | - |
Whether the next button is disabled (e.g., on last page). | | |
Text label to display alongside the chevron icon. | | - |