Many Pages
The first and last page stay; gaps fold into an ellipsis.
<Pagination totalPages={20} defaultPage={10}>
<Pagination.Previous />
<Pagination.Items />
<Pagination.Next />
</Pagination>Steps through content split across numbered pages.
<Pagination totalPages={10} defaultPage={1}>
<Pagination.Previous />
<Pagination.Items />
<Pagination.Next />
</Pagination>pnpm add @usefragments/uiThe npm package stays managed by your package manager. Import styles once from @usefragments/ui/styles. See the installation guide for framework and theme setup.
Import Pagination once, then compose its parts with dot notation.
Pagination.PreviousPagination.NextPagination.ItemsNeighbours around the current page, ends always reachable.
<Pagination totalPages={10} defaultPage={1}>
<Pagination.Previous />
<Pagination.Items />
<Pagination.Next />
</Pagination>The first and last page stay; gaps fold into an ellipsis.
<Pagination totalPages={20} defaultPage={10}>
<Pagination.Previous />
<Pagination.Items />
<Pagination.Next />
</Pagination>Drops the neighbours when space is tight.
<Pagination totalPages={20} defaultPage={10} siblingCount={0}>
<Pagination.Previous />
<Pagination.Items />
<Pagination.Next />
</Pagination>You hold the page number in state.
<Pagination totalPages={5} page={3}>
<Pagination.Previous />
<Pagination.Items />
<Pagination.Next />
</Pagination>Each page is a link to its own URL.
<Pagination totalPages={8} defaultPage={3} renderLink={(page) => <a href={`?page=${page}`} />}>
<Pagination.Previous />
<Pagination.Items />
<Pagination.Next />
</Pagination>Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | React.ReactNode | Not set | Pagination.Previous, Pagination.Items and Pagination.Next |
defaultPage | number | undefined | 1 | Default page (uncontrolled) |
onPageChange | ((page: number) => void) | undefined | Not set | Called when page changes |
page | number | undefined | Not set | Controlled current page (1-indexed) |
renderLink | ((page: number) => React.ReactElement) | undefined | Not set | Makes every page a link: (page) => the element to render, such as an anchor or a router link. Pressing it still calls onPageChange |
siblingCount | number | undefined | 1 | Pages shown on each side of the current one; the first and last page always show |
size | PaginationSize | undefinedsmmd | Not set | Item size; resolves through ComponentDefaults when omitted |
totalPagesRequired | number | Not set | Total number of pages; renders nothing when there are none |