Pagination
Previous and next buttons for stepping through pages of a list.
import { PaginationControls } from "@unkey/ui";
import { useState } from "react";
const TOTAL = 50;
const PAGE_SIZE = 15;
const LAST_PAGE = Math.ceil(TOTAL / PAGE_SIZE) - 1;
export default function PaginationBasic() {
const [page, setPage] = useState(0);
const start = page * PAGE_SIZE;
const end = Math.min(start + PAGE_SIZE, TOTAL);
return (
<div className="mx-auto flex h-10 w-full max-w-sm items-center justify-between rounded-lg border pr-2 pl-4 text-grayA-9 text-xs">
<span className="tabular-nums">
{start + 1}–{end} of {TOTAL}
</span>
<PaginationControls
label="Variables pagination"
hasPrevious={page > 0}
hasNext={page < LAST_PAGE}
onPrevious={() => setPage(page - 1)}
onNext={() => setPage(page + 1)}
/>
</div>
);
}
Anatomy
PaginationControlsrenders a labellednavwith previous and next buttons. Children render between the two buttons.PaginationFooterpinsPaginationControlsto the bottom of a table page, with page numbers as its children.
Best practices
Label
Give each PaginationControls a label that names the list it pages, so two pagers on one screen are distinct.
Placement
Use PaginationFooter for a full-page table. Use PaginationControls inline when a card or a section pages its own rows.