Pagination
Buttons for moving between the pages of a long list or table.
Usage
import { Pagination } from '@leverui/components';
<Pagination.Root>
<Pagination.PrevTrigger />
<Pagination.Ellipsis />
<Pagination.Item />
<Pagination.PageText />
<Pagination.NextTrigger />
</Pagination.Root>
Shortcuts
PaginationItems
Renders the page numbers. The page count comes from count and pageSize.
<Pagination.Items />
Same as:
<Pagination.Context>
{(pagination) => (
<For each={pagination().pages}>
{(page, index) =>
page.type === 'page' ? (
<Pagination.Item {...page} />
) : (
<Pagination.Ellipsis index={index()} />
)
}
</For>
)}
</Pagination.Context>
Examples
Sizes
Use the size prop to change the size of the pagination.
The pagination sizes are mapped to the
Buttoncomponent sizes.
Variants
Use the variant prop to control the variant of the pagination items and ellipsis.
The variant matches the
Buttoncomponent variant.
Controlled
Use the page and onPageChange props to control the current page.
Sibling Count
Use siblingCount to control the number of sibling pages to show before and after the current page.
Compact
Use the Pagination.PageText to create a compact pagination. This can be useful for mobile views.
As Link
Here's an example of rendering the pagination as links.
Attached
Here's an example of composing the pagination with the Group component to attach the pagination items and triggers.
Count Text
Pass format="long" to the Pagination.PageText component to show the count text.
Custom Page Text
Pass a function to the format prop of Pagination.PageText to customize or localize the page text.
Data Driven
Here's an example of controlling the pagination state and using the state to chunk the data.
Support ticket 1
Support ticket 2
Support ticket 3
Support ticket 4
Support ticket 5
Props
Root
| Prop | Default | Type | Description |
|---|---|---|---|
boundaryCount | 1 | number | Pages shown at the start and at the end. |
defaultPage | 1 | number | Starting page, when uncontrolled. |
defaultPageSize | 10 | number | Starting items per page, when uncontrolled. |
siblingCount | 1 | number | Pages shown on each side of the active page. |
type | 'button' | 'button' | 'link' | Render the triggers as buttons or links. |
asChild | — | Solid render function | Render your own element with the root's props. |
count | — | number | Total number of items. |
getPageUrl | — | (details: PageUrlDetails) => string | Returns each link's href. Only when type is "link". |
ids | — | Element ID map | Ids of the pagination elements. |
onPageChange | — | (details: PageChangeDetails) => void | Called when the page number changes. |
onPageSizeChange | — | (details: PageSizeChangeDetails) => void | Called when the page size changes. |
page | — | number | Active page, when you control it. |
pageSize | — | number | Items per page, when you control it. |
translations | — | IntlTranslations | Translated text for assistive technology. |
unstyled | — | boolean | Turn off the default styles. |
Pagination does not change your data. Show the current page's items yourself.
PageText format: compact by default, or short, long, or a function
that returns the text.
With more than one pagination on a page, give each its own accessible label.
Customize with CSS
Import @leverui/components/styles.css once for the default page text weight
and ellipsis look.
Classes: .leverui-pagination__root, .leverui-pagination__item,
.leverui-pagination__ellipsis, .leverui-pagination__prevTrigger,
.leverui-pagination__nextTrigger, and .leverui-pagination__page-text for
the page text.
Each part keeps its own attribute (such as data-pagination-item),
aria-current, and the disabled and link attributes up to date. Style with
these, class, and style.
Set unstyled on the root or on a part to turn off its default styles.