# Pagination

A paged table's footer: the range showing, rows per page and the pages.

Live variants: https://design.arcadia.is/components/pagination

```tsx
import { Pagination, useFitRows } from "@arcadia/ui";
```

Page through the turn log or change how many turns appear at once.

```tsx
import { useState } from "react";
import { Pagination, Table } from "@arcadia/ui";

function Turns() {
  const [page, setPage] = useState(0);
  const [size, setSize] = useState(3);
  return (
    <div {...stylex.props(s.log)}>
      <Table caption="Turn log" columns={TURN_COLUMNS} rows={TURN_ROWS.slice(page * size, (page + 1) * size)} />
      <div {...stylex.props(s.pages)}>
        <Pagination page={page} pageSize={size} pageSizes={[3, 5, 8]} total={TURN_ROWS.length} noun={["turn", "turns"]}
          onPageChange={setPage} onPageSizeChange={(n) => { setSize(n); setPage(0); }} />
      </div>
    </div>
  );
}
```

## Accessibility

A navigation landmark named by `label` ("Pages" by default). Previous and Next are named buttons that disable at the ends rather than vanish, so focus never jumps. The range is a polite live region: changing the page or the rows per page announces the new range. The Rows picker is a segmented control with arrow-key focus.

A `more` foot pages nothing, so it is no navigation landmark: it is the count, a polite live region that announces each page that arrives, and one button that disables while its page is read.

## API reference

### Pagination

- `page` (`number`, default `0`): The current page, from 0. Out of range reads as the last page. Left out with a `more` foot.
- `pageSize` (`number`, default `25`): Rows per page. Left out with a `more` foot.
- `total` (`number`, default `0`): Every row there is, across pages. Left out with a `more` foot: a cursor list never knows its total.
- `onPageChange` (`(page: number) => void`): Turns the page. Left out with a `more` foot.
- `pageSizes` (`readonly number[]`, default `[10, 25, 50]`): The row-count choices; with `onPageSizeChange`, a "Rows" picker appears.
- `onPageSizeChange` (`(size: number) => void`)
- `noun` (`readonly [one: string, many: string]`, default `["row", "rows"]`): What a row is, singular and plural, for the range ("1 to 10 of 351 turns"). Default: `row`.
- `label` (`string`, default `"Pages"`): Names the navigation landmark. Default: "Pages". A `more` foot draws none.
- `showPage` (`boolean`, default `true`): "Page 2 of 6" between the arrows. False for a list that fits its page: the range already says where you are, and the footer keeps to one line beside a meter.
- `more` (`{ shown: number; onMore: () => void; hasMore?: boolean; loading?: boolean; label?: string; error?: ReactNode }`): A cursor list, which reads one page at a time and never knows how many there are: the foot says how many rows are showing ("40 cards") and offers the one quiet control that reads more, in place of the pages. `shown` is how many are showing and `onMore` reads the next page; `hasMore` false takes the control away at the end, `loading` puts its spinner in the label's place, `label` names it ("Show more cards", the noun's plural), and `error` shows the product's own line and Try again where it stood. Leave `page`, `pageSize`, `total` and `onPageChange` out.
- `rootStyle` (`PaginationStyle`): Pagination has no knobs of its own: place it with `rootStyle`.

Rest props go to `HTMLAttributes<HTMLElement>`.
