Pagination
Moves through a long list page by page: numbers with ellipses that fold into “Page 3 of 12” on a phone, or previous / next on a cursor.
Web et mobile — le même composant pour React et React Native. Bêta : son API peut encore changer à une version mineure.
Pourquoi il est là. Used by Orochia, Orazaka.
Quand l’utiliser
- Under a table or a grid of results the person reads page by page: an admin list, search results, invoices.
- With
getHrefwhen the page belongs in the address — a search engine and a shared link reach page 4. - In cursor mode (
hasPrevious/hasNext) when the API only knows the next page (a cursor, anextToken).
Quand ne pas l’utiliser
- For a feed people scroll without a goal: load more at the end of the list instead (an infinite list).
- To switch between views of the same page: tabs.À la place : Tabs
Installation
Installer
npm install @krizaka/ui @krizaka/tailwind @krizaka/tokens tailwindcssStyles
@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";Importer
import { Pagination, pageRange } from "@krizaka/ui/pagination";Exemples
Search results
Page numbers with ellipses and a status: the explore page of a video platform.
Table footer
Under an admin table: the rows per page, the range shown, and the pages.
Cursor
An API that only knows the next and previous pages: two buttons and the range.
Links in the address
getHref: every page is a link — crawlable, shareable, the state in the URL.
Props
Moves through a long list: page numbers (folded on a narrow screen) or previous / next on a cursor.
| Prop | Type | Défaut | Description |
|---|---|---|---|
boundaries | number | 1 | Pages always shown at each end. Default 1. |
disabled | boolean | — | Disables every control (a page is loading). |
getHref | ((page: number) => string) | — | The address of a page: the pages become links (crawlable, shareable, the state in the URL). |
hasNext | boolean | — | Cursor mode: whether there is a next page. |
hasPrevious | boolean | — | Cursor mode: whether there is a previous page. |
labels | Partial<PaginationLabels> | — | The words, passed translated; English by default. |
onNext | (() => void) | — | Cursor mode: called by the next control. |
onPageChange | ((page: number) => void) | — | Called with the page asked for (buttons). Ignored for the pages getHref turns into links. |
onPageSizeChange | ((size: number) => void) | — | Called with the size chosen. |
onPrevious | (() => void) | — | Cursor mode: called by the previous control. |
page | number | 1 | Pages mode: the current page, from 1. |
pageCount | number | — | Pages mode: how many pages there are. Without it, the pagination is in cursor mode. |
pageSize | number | — | The page size, with pageSizeOptions and onPageSizeChange: a select of rows per page. |
pageSizeOptions | readonly number[] | — | The sizes offered ([10, 20, 50]). |
siblings | number | 1 | Pages shown on each side of the current one. Default 1. |
status | ReactNode | — | A text beside the controls, read as is: "41–60 of 1,284", "12 results". |
Accessibilité
- A
navnamed bylabels.nav; the current page carriesaria-current="page". - Each number is named “Page 4” (
labels.page); the ellipses are hidden from assistive technology. - A disabled link is
aria-disabledwith nohref: it is skipped by the Tab key and read as unavailable.
Clavier
| Touches | Action |
|---|---|
| Tab | Reaches the previous control, each page, then the next control. |
Bonnes pratiques
- Say where the list stands with
status(“61–80 of 392 videos”): it is read next to the controls. - Prefer links (
getHref) for public lists; buttons (onPageChange) for a list inside an app screen. - Keep
siblingsat 1 on a list people browse; the container folds the numbers by itself under 28rem. - Disable the controls (
disabled) while the next page loads, and move the focus to the top of the list after.
Composants liés
Générée depuis le code de @krizaka/ui 3.9.0 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub