Pagination

Free

Previous, every page and next as quiet buttons, with one glass marker that glides to the page you pick.

npx shadcn@latest add @pixilui/pagination

Preview

One glass marker glides from page to page.

When to use

Use it when

  • Paging a short list: run history, an audit log, eval results, a few pages of invoices.
  • Under a table whose row count is known up front.

Use something else when

  • More than about 7 pages: this shows every page; use a windowed pagination or a page input.
  • Feeds that grow as you read: load more on scroll or with a button.

Installation

Terminal
npx shadcn@latest add @pixilui/pagination

Adds pagination.tsx with button.tsx, and installs clsx and tailwind-merge. First PixilUI item in this app? Add the registry once, as in Installation.

Usage

example.tsx
import { Pagination } from "@/components/pixilui/pagination";

<Pagination
  pageCount={pageCount}
  previousIcon={previousIcon}
  nextIcon={nextIcon}
  onPageChange={onPageChange}
/>

As wide as its pages. Three to seven pages fit at 375 wide.

API reference

PropTypeDefault
pageCountRequirednumber–How many pages there are. Every page shows, so keep it to about 7.
previousIconRequiredReactNode–The previous icon (Lucide ArrowLeft).
nextIconRequiredReactNode–The next icon (Lucide ArrowRight).
pagenumber–The current page (from 1), controlled. Pair with onPageChange.
defaultPagenumber1The starting page when uncontrolled.
onPageChange(page: number) => void | Promise<void>–Runs with the page a person picked.
previousLabelstring"Previous page"Accessible name of the previous button.

Also takes every native <div> attribute except onChange, and a ref.

Keyboard

TabMoves through previous, each page and next.
EnterGoes to the focused page.
SpaceThe same as Enter, on release.

Accessibility

  • A navigation landmark named Pages (aria-label), holding native buttons.
  • The current page has aria-current="page".
  • Previous and next are named Previous page and Next page, and disable on the first and last page.
  • The marker is aria-hidden decoration.

Motion

  • The glass marker glides to the new page on the snappy spring, its width following the number.
  • On first paint and after the font loads the marker is placed at once, never sliding in from the start.
  • Reduced motion: the marker moves at once.

PixilUI Pro opens Thu 10 Dec. The first 20 licenses are $99.