Pagination
Numbered pages with a per-page select and a range label. Keeps one width as you page, via paginationRange.
import { Pagination, paginationRange } from '@objectifthunes/whiteboard'
<Pagination
page={page} // 1-based
pageCount={Math.ceil(total / perPage)}
onPageChange={setPage}
perPage={perPage}
perPageOptions={[10, 25, 50, 100]}
onPerPageChange={n => { setPerPage(n); setPage(1) }}
total={total} // turns on the "1–25 of 287" label
/>
// the windowing rule on its own
paginationRange(7, 20) // [1, 'gap', 6, 7, 8, 'gap', 20]paginationRange always returns the same number of slots once collapsing kicks in, so the control does not change width as you page through. Near either end it spends the gap slot on real page numbers instead of an ellipsis. Page through the demo and watch the array at the bottom.
The range label is the part users actually read to know where they are, so it needs both total and perPage. Changing per-page should reset to page 1 — that is the caller's job, since only you know whether the cursor means anything.
Use this when the dataset has a known size and users jump around it. When the source is a cursor feed with no total, use LoadMoreButton instead: numbered pages you cannot count are a lie.