Pagination
Move between pages of results.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- Built on native elements
- 2 parts, named exports
- A nav landmark; each page is a button named "Page N" and the current one has aria-current=page.
- Prev and Next are disabled at the ends.
- The gap marker is hidden from assistive tech.
- Styles in one file:
18-navigation.css
Import
import '@monoline/css';
import {Pagination} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add pagination
Usage
import {useState} from 'react';
import {Pagination} from '@monoline/react';
function Demo1() {
const [page, setPage] = useState(5);
return <Pagination page={page} pageCount={20} onPageChange={setPage} />;
}
<Demo1 />
Anatomy
Import the parts you need and nest them like this.
import {Pagination, pageWindow} from '@monoline/react';
<Pagination>
<pageWindow />
</Pagination>
Examples
With gaps
Props
PaginationProps
| Prop | Type | Default | Description |
|---|---|---|---|
page | number | – | Current page, 1-based, when controlled. Pair with `onPageChange`. |
defaultPage | number | 1 | The starting page when uncontrolled. Default 1. |
pageCount required | number | – | Total number of pages. |
onPageChange | ((page: number) => void) | – | Called with the new 1-based page number when the user picks a page or presses Prev or Next. |
siblings | number | 1 | How many numbers to show on each side of the current page. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[aria-current="page"] | 18-navigation.css |
[aria-current="step"] | 18-navigation.css |
[aria-selected="true"] | 18-navigation.css |
[data-state="done"] | 18-navigation.css |
CSS classes
| Class | Stylesheet |
|---|---|
.brand | 18-navigation.css |
.crumbs | 18-navigation.css |
.pager | 18-navigation.css |
.step | 18-navigation.css |
.steps | 18-navigation.css |
.tab | 18-navigation.css |
.tabpanel | 18-navigation.css |
.topbar | 18-navigation.css |
.topbar-nav | 18-navigation.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.brand {
border-color: var(--accent);
}
.brand[aria-current="page"] {
background: var(--wash);
}
Accessibility
- A nav landmark; each page is a button named "Page N" and the current one has aria-current=page.
- Prev and Next are disabled at the ends.
- The gap marker is hidden from assistive tech.