Pagination

Buttons for moving between the pages of a long list or table.

Usage

Code
import { Pagination } from '@leverui/components';
Code
<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.

Code
<Pagination.Items />

Same as:

Code
<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 Button component sizes.

Variants

Use the variant prop to control the variant of the pagination items and ellipsis.

The variant matches the Button component 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.

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

PropDefaultTypeDescription
boundaryCount1numberPages shown at the start and at the end.
defaultPage1numberStarting page, when uncontrolled.
defaultPageSize10numberStarting items per page, when uncontrolled.
siblingCount1numberPages shown on each side of the active page.
type'button''button' | 'link'Render the triggers as buttons or links.
asChild—Solid render functionRender your own element with the root's props.
count—numberTotal number of items.
getPageUrl—(details: PageUrlDetails) => stringReturns each link's href. Only when type is "link".
ids—Element ID mapIds of the pagination elements.
onPageChange—(details: PageChangeDetails) => voidCalled when the page number changes.
onPageSizeChange—(details: PageSizeChangeDetails) => voidCalled when the page size changes.
page—numberActive page, when you control it.
pageSize—numberItems per page, when you control it.
translations—IntlTranslationsTranslated text for assistive technology.
unstyled—booleanTurn 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.