Pagination
Previous, next, numbered pages, and skipped pages for long lists. Seven small parts you compose yourself, with plain links or router links.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/pagination.jsonCopies Pagination and the components it uses (Button) into your app, installs the packages, and adds the styles. Then import it from @/components/ui/pagination. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @hugeicons/core-free-icons @hugeicons/reactAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Add the components it uses: Button.
Copy and paste the following code into your project.
'use client'; import type { ComponentProps } from 'react'; import { ChevronLeftIcon } from '@/lib/sprout/icons/chevron-left-icon'; import { ChevronRightIcon } from '@/lib/sprout/icons/chevron-right-icon'; import { MoreIcon } from '@/lib/sprout/icons/more-icon'; import { cn } from '@/lib/sprout/classes'; import { Button, type ButtonProps, type ButtonSize } from '@/components/ui/button'; export type PaginationProps = ComponentProps<'nav'>; export function Pagination({ className, 'aria-label': label = 'pagination', ...props }: PaginationProps) { return ( <nav role="navigation" aria-label={label} data-slot="pagination" className={cn('sprout-pagination', className)} {...props} /> ); } export type PaginationContentProps = ComponentProps<'ul'>; export function PaginationContent({ className, ...props }: PaginationContentProps) { return <ul data-slot="pagination-content" className={cn('sprout-pagination-content', className)} {...props} />; } export type PaginationItemProps = ComponentProps<'li'>; export function PaginationItem({ className, ...props }: PaginationItemProps) { return <li data-slot="pagination-item" className={cn('sprout-pagination-item', className)} {...props} />; } export interface PaginationLinkProps extends Omit<ComponentProps<'a'>, 'className'> { className?: string; isActive?: boolean; size?: ButtonSize; disabled?: boolean; render?: ButtonProps['render']; } export function PaginationLink({ className, isActive, size = 'icon', render, ...props }: PaginationLinkProps) { return ( <Button variant={isActive ? 'outline' : 'ghost'} size={size} nativeButton={false} render={render} {...(props as ButtonProps)} aria-current={isActive ? 'page' : undefined} data-slot="pagination-link" data-active={isActive ? 'true' : undefined} className={cn('sprout-pagination-link', className)} /> ); } export interface PaginationDirectionProps extends PaginationLinkProps { text?: string; } export function PaginationPrevious({ className, text = 'Previous', ...props }: PaginationDirectionProps) { return ( <PaginationLink aria-label="Go to previous page" size="md" className={cn('sprout-pagination-previous', className)} {...props} > <ChevronLeftIcon data-icon="inline-start" aria-hidden="true" /> <span className="sprout-pagination-label">{text}</span> </PaginationLink> ); } export function PaginationNext({ className, text = 'Next', ...props }: PaginationDirectionProps) { return ( <PaginationLink aria-label="Go to next page" size="md" className={cn('sprout-pagination-next', className)} {...props} > <span className="sprout-pagination-label">{text}</span> <ChevronRightIcon data-icon="inline-end" aria-hidden="true" /> </PaginationLink> ); } export type PaginationEllipsisProps = ComponentProps<'span'>; export function PaginationEllipsis({ className, ...props }: PaginationEllipsisProps) { return ( <span aria-hidden="true" data-slot="pagination-ellipsis" className={cn('sprout-pagination-ellipsis', className)} {...props} > <MoreIcon /> <span className="sprout-pagination-sr-only">More pages</span> </span> ); }And the files it imports:
lib/sprout/icons/chevron-left-icon.tsxlib/sprout/icons/chevron-right-icon.tsxlib/sprout/icons/create-icon.tsxlib/sprout/icons/more-icon.tsx
Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-pagination { justify-content: center; width: 100%; margin-inline: auto; display: flex; } .sprout-pagination-content { flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px; margin: 0; padding: 0; list-style: none; display: flex; } .sprout-pagination-item { display: flex; } .sprout-pagination-link { font-variant-numeric: tabular-nums; } .sprout-pagination-link.sprout-pagination-previous { padding-inline-start: 6px; } .sprout-pagination-link.sprout-pagination-next { padding-inline-end: 6px; } .sprout-pagination-previous:dir(rtl) > svg, .sprout-pagination-next:dir(rtl) > svg { transform: scaleX(-1); } .sprout-pagination-ellipsis { width: var(--sprout-control-height); height: var(--sprout-control-height); color: var(--sprout-muted); justify-content: center; align-items: center; display: flex; } .sprout-pagination-content:has(.sprout-button-size-sm, .sprout-button-size-icon-sm) .sprout-pagination-ellipsis { width: calc(var(--sprout-control-height) - 4px); height: calc(var(--sprout-control-height) - 4px); } .sprout-pagination-content:has(.sprout-button-size-lg, .sprout-button-size-icon-lg) .sprout-pagination-ellipsis { width: calc(var(--sprout-control-height) + 4px); height: calc(var(--sprout-control-height) + 4px); } .sprout-pagination-ellipsis > svg { width: 16px; height: 16px; } .sprout-pagination-sr-only { clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; width: 1px; height: 1px; margin: -1px; padding: 0; position: absolute; overflow: hidden; } @media (width <= 639px) { .sprout-pagination-label { display: none; } .sprout-pagination-link:is(.sprout-pagination-previous, .sprout-pagination-next) { aspect-ratio: 1; padding-inline: 0; } } }Import it from
@/components/ui/pagination. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/pagination.
Page navigation
Previous, numbered pages, skipped pages, and next. The active page is outlined.
Page 1
Run history
Long lists keep the first, last, and nearby pages. Edges and loading disable links.
Runs 151–175 · page 7 of 24
Sizes
Page numbers take icon sizes; previous and next take the matching text size.
Router links
The render prop swaps the anchor for your router's link.
Route /inbox?page=2
Direction
Chevrons flip in right-to-left text.
Usage
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@tulipfarm/sprout/pagination";
<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="?page=1" />
</PaginationItem>
<PaginationItem>
<PaginationLink href="?page=1">1</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="?page=2" isActive>2</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationEllipsis />
</PaginationItem>
<PaginationItem>
<PaginationNext href="?page=3" />
</PaginationItem>
</PaginationContent>
</Pagination>Pagination is a nav labelled "pagination"; passaria-label to name it, such as "Run history pages".PaginationContent is a list and PaginationItem a list item. Which pages to show is your choice: the demo keeps the first, last, and nearby pages, and puts PaginationEllipsis in the gaps.
Links, sizes, and labels
<PaginationLink isActive render={<Link to="/inbox?page=2" />}>
2
</PaginationLink>
<PaginationLink size="icon-sm" href="#">3</PaginationLink>
<PaginationPrevious size="sm" disabled={page === 1} href="#" />
<PaginationNext text="Older" aria-label="Older runs" href="#" />PaginationLink is a Sprõut Button that renders ana. It is ghost, and outline witharia-current="page" when isActive is set. The Base UI render prop swaps the anchor for your router's link.size takes any button size: page numbers default toicon (32px), and previous and next default todefault. Pair icon-sm with sm oricon-lg with lg. disabled setsaria-disabled, removes the link from the tab order, and blocks clicks.
PaginationPrevious and PaginationNext show a chevron and a text label, "Previous" and "Next" by default. Below 640px only the chevron shows. Their names are "Go to previous page" and "Go to next page"; pass aria-label when you change the text.
Accessibility
Links show a focus ring and follow tab order. PaginationEllipsisis hidden from screen readers. Pair the control with a status line, such as "Page 3 of 24", so screen readers hear the change. Chevrons flip in right-to-left text. Color changes last 120ms and stop when reduced motion is requested.
Theme tokens
Page links use the button's --sprout-muted,--sprout-hover, and --sprout-text. The active page uses --sprout-input and --sprout-surface. The ellipsis uses --sprout-muted and the focus ring--sprout-focus.