Pagination
Previous and next buttons around the current page number.
2
import { useState } from "react"
import { Pagination } from "@dapplelight/signet-ui/components/pagination"
export function Demo() {
const [page, setPage] = useState(2)
return <Pagination page={page} totalPages={8} onPageChange={setPage} />
}Installation
npm i @dapplelight/signet-uiUsage
import { useState } from "react"
import { Pagination } from "@dapplelight/signet-ui/components/pagination"
const [page, setPage] = useState(1)
<Pagination page={page} totalPages={8} onPageChange={setPage} />Examples
With a list
- INV-1040
- INV-1041
- INV-1042
- INV-1043
Page 1 of 3
1
import { useState } from "react"
import { Pagination } from "@dapplelight/signet-ui/components/pagination"
const invoices = Array.from({ length: 12 }, (_, i) => `INV-${1040 + i}`)
export function InvoiceList() {
const [page, setPage] = useState(1)
const size = 4
const totalPages = Math.ceil(invoices.length / size)
return (
<>
<ul>
{invoices.slice((page - 1) * size, page * size).map((id) => (
<li key={id}>{id}</li>
))}
</ul>
<Pagination page={page} totalPages={totalPages} onPageChange={setPage} />
</>
)
}Single page
One page of results renders nothing:
import { Pagination } from "@dapplelight/signet-ui/components/pagination"
// Renders nothing when totalPages is 1 or less.
<Pagination page={1} totalPages={1} onPageChange={() => {}} />API Reference
Pagination
| Prop | Type | Default | Description |
|---|---|---|---|
| page | number | - | Current page, starting at 1. |
| totalPages | number | - | Total pages. Nothing renders at 1 or less. |
| onPageChange | (page: number) => void | - | Called with the new page, clamped to the range. |
| className | string | - | Class on the wrapper. |