Pagination

One component pages through a long list: each page a button, or a link to its address, the current one outlined, dots for the pages left out, and chevrons for previous and next.

import { Pagination } from "@produkto/ui/Pagination";
import { useState } from "react";

const Example = () => {
  const [page, setPage] = useState(1);
  return <Pagination onPageChange={setPage} page={page} pages={10} />;
};

export default Example;

Usage

import { Pagination } from "@produkto/ui/Pagination";
<Pagination page={2} pages={10} href="/items" />

Examples

Sizes

size sets every page, chevron and the dots at a Button's height, sm 32px, base 40px (the default) or lg 48px, and the gap between them to match.

import { Label } from "@produkto/ui/Label";
import { Pagination, type PaginationSize } from "@produkto/ui/Pagination";

const variants: { size: PaginationSize; label: string }[] = [
  { size: "sm", label: "Small" },
  { size: "base", label: "Base" },
  { size: "lg", label: "Large" },
];

const Example = () => (
  <div className="flex w-full flex-col gap-4">
    {variants.map((variant) => (
      <div className="flex flex-col items-center gap-2" key={variant.size}>
        <Label id={`pagination-size-${variant.size}`}>{variant.label}</Label>
        <Pagination
          aria-labelledby={`pagination-size-${variant.size}`}
          page={1}
          pages={10}
          size={variant.size}
        />
      </div>
    ))}
  </div>
);

export default Example;

Border radius

borderRadius sets the corners of every page and chevron as a Button's, on the kit's one scale: none, xs 4px, sm 6px, base 8px (the default), lg 12px, xl 16px, or full to round them.

import { Label } from "@produkto/ui/Label";
import {
  Pagination,
  type PaginationBorderRadius,
} from "@produkto/ui/Pagination";

const variants: { borderRadius: PaginationBorderRadius; label: string }[] = [
  { borderRadius: "none", label: "None" },
  { borderRadius: "xs", label: "xs" },
  { borderRadius: "sm", label: "sm" },
  { borderRadius: "base", label: "base" },
  { borderRadius: "lg", label: "lg" },
  { borderRadius: "xl", label: "xl" },
  { borderRadius: "full", label: "full" },
];

const Example = () => (
  <div className="flex w-full flex-col gap-4">
    {variants.map((variant) => (
      <div
        className="flex flex-col items-center gap-2"
        key={variant.borderRadius}
      >
        <Label id={`pagination-radius-${variant.borderRadius}`}>
          {variant.label}
        </Label>
        <Pagination
          aria-labelledby={`pagination-radius-${variant.borderRadius}`}
          page={1}
          pages={10}
          borderRadius={variant.borderRadius}
        />
      </div>
    ))}
  </div>
);

export default Example;

Page

page is the current one of pages, outlined, its neighbours kept from sm up and a run of two or more pages left out folded into dots; the chevron at either end is off on the first and the last page.

import { Pagination } from "@produkto/ui/Pagination";

const pages: number[] = [1, 12, 24];

const Example = () => (
  <div className="flex w-full flex-col gap-4">
    {pages.map((page) => (
      <Pagination key={page} page={page} pages={24} />
    ))}
  </div>
);

export default Example;

Href

href makes every page a link to that address, from page 2 on with ?page= and its number added (param names it), where without one each page is a button heard by onPageChange.

import { Pagination } from "@produkto/ui/Pagination";

const Example = () => <Pagination href="#" page={1} pages={5} />;

export default Example;

Disabled

disabled turns every page and chevron off, beside a pagination as it is by default.

import { Pagination } from "@produkto/ui/Pagination";

const Example = () => (
  <div className="flex w-full flex-col gap-4">
    <Pagination page={1} pages={5} />
    <Pagination disabled page={1} pages={5} />
  </div>
);

export default Example;

API Reference

Pagination

PaginationProps · components/Pagination/Pagination.types.ts
PropTypeDefault
pagerequirednumber-
pagesrequirednumber-
hrefstring-
paramstring"page"
onPageChange(page: number) => void-
sizePaginationSize"sm" | "base" | "lg""base"
borderRadiusPaginationBorderRadius"none" | "xs" | "sm" | "base" | "lg" | "xl" | "full""base"
disabledbooleanfalse

It also takes the props of <nav>.