Navigation
Pagination
Table footer. Summary left, pages right; 32px page items, radius 8.
react-aria-componentslucide-react
Preview
"use client";
import { useState } from "react";
import { Pagination } from "@/components/ui/pagination";
export default function Example() {
const [page, setPage] = useState(1);
const from = (page - 1) * 25 + 1;
return (
<Pagination
className="w-full"
page={page}
pageCount={6}
onPageChange={setPage}
summary={`${from}–${Math.min(from + 24, 128)} of 128 prospects`}
/>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-components lucide-reactCreate a
pagination.tsxfile and paste the following code into it.src/components/ui/pagination.tsx"use client"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { Button as AriaButton } from "react-aria-components"; import { cx } from "@/utils/cx"; export interface PaginationProps { page: number; pageCount: number; onPageChange: (page: number) => void; /** Summary shown on the left, e.g. "1–25 of 128 prospects". */ summary?: string; className?: string; } function pages(current: number, count: number): (number | "…")[] { if (count <= 7) return Array.from({ length: count }, (_, i) => i + 1); const set = new Set([1, 2, current - 1, current, current + 1, count]); const sorted = [...set].filter((p) => p >= 1 && p <= count).sort((a, b) => a - b); const out: (number | "…")[] = []; sorted.forEach((p, i) => { if (i > 0 && p - sorted[i - 1]! > 1) out.push("…"); out.push(p); }); return out; } const item = "inline-flex size-8 cursor-default items-center justify-center rounded-sm text-sm font-medium tabular text-fg-secondary outline-none transition-colors " + "data-hovered:bg-muted data-hovered:text-fg data-focus-visible:shadow-focus data-disabled:text-fg-disabled [&_svg]:size-4"; /** Table footer. Summary left, pages right; 32px page items, radius 8. */ export function Pagination({ page, pageCount, onPageChange, summary, className }: PaginationProps) { return ( <nav aria-label="Pagination" className={cx("flex items-center justify-between gap-4", className)}> <span className="text-sm text-fg-muted">{summary}</span> <div className="flex items-center gap-1"> <AriaButton aria-label="Previous page" className={item} isDisabled={page <= 1} onPress={() => onPageChange(page - 1)}> <ChevronLeft /> </AriaButton> {pages(page, pageCount).map((p, i) => p === "…" ? ( <span key={`gap-${i}`} className="inline-flex size-8 items-center justify-center text-sm text-fg-muted">…</span> ) : ( <AriaButton key={p} aria-label={`Page ${p}`} aria-current={p === page ? "page" : undefined} onPress={() => onPageChange(p)} className={cx(item, p === page ? "bg-active text-fg" : "shadow-button bg-surface")} > {p} </AriaButton> ), )} <AriaButton aria-label="Next page" className={item} isDisabled={page >= pageCount} onPress={() => onPageChange(page + 1)}> <ChevronRight /> </AriaButton> </div> </nav> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.