Rich paginations
Five paginations that carry extra controls beside the page numbers: a rows-per-page selector, a total-results badge, a boxed per-page bar, a record-range readout and a full table footer. Each carries its own page state, is sized, token-driven and marks the active page with aria-current.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/pagination-richDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/pagination-rich.tsx"use client"
import * as React from "react"
import { ChevronLeft, ChevronRight, MoreHorizontal } from "lucide-react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Rich pagination family: 5 paginators that carry extra controls alongside page navigation: a per-page record selector, a total record counter, range information and a full bar combining all of them. Colour comes only from semantic tokens; alpha through color-mix. Motion is gated with useReducedMotion(); the framer layoutId derives from React.useId(). */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const controlSize: Record<StyledSize, string> = {
sm: "h-8 text-sm",
md: "h-9 text-sm",
lg: "h-10 text-sm",
xl: "h-12 text-base",
}
const iconSize: Record<StyledSize, string> = {
sm: "size-8",
md: "size-9",
lg: "size-10",
xl: "size-12",
}
const focusRing =
"outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50"
const btnBase =
"relative inline-flex shrink-0 select-none items-center justify-center font-medium whitespace-nowrap transition-colors [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
const arrowBtn = "rounded-lg border border-border text-foreground hover:bg-accent"
const selectBase =
"rounded-lg border border-border bg-background px-2 text-foreground"
interface PaginationProps {
className?: string
size?: StyledSize
total?: number
defaultPage?: number
}
/* Dahili sayfa durumu. */
function usePageState(total: number, defaultPage: number) {
const n = Math.max(total, 1)
const clamp = React.useCallback((p: number) => Math.min(Math.max(p, 1), n), [n])
const [current, setCurrent] = React.useState(() => clamp(defaultPage))
const goto = (p: number) => setCurrent(clamp(p))
return { current: clamp(current), total: n, goto }
}
function pageRange(current: number, total: number): (number | "ellipsis")[] {
if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1)
const out: (number | "ellipsis")[] = [1]
const left = Math.max(2, current - 1)
const right = Math.min(total - 1, current + 1)
if (left > 2) out.push("ellipsis")
for (let p = left; p <= right; p++) out.push(p)
if (right < total - 1) out.push("ellipsis")
out.push(total)
return out
}
/* Sayi butonlari serisi: aktif sayfa kayan primary vurgu ile. */
function PageNumbers({
current,
total,
goto,
size,
uid,
}: {
current: number
total: number
goto: (p: number) => void
size: StyledSize
uid: string
}) {
const reduce = useReducedMotion()
const items = pageRange(current, total)
return (
<>
{items.map((it, i) =>
it === "ellipsis" ? (
<span
key={`e${i}`}
aria-hidden="true"
className={cn(iconSize[size], "inline-flex items-center justify-center text-muted-foreground")}
>
<MoreHorizontal />
</span>
) : (
<button
key={it}
type="button"
aria-label={`Go to page ${it}`}
aria-current={it === current ? "page" : undefined}
onClick={() => goto(it)}
className={cn(
btnBase,
focusRing,
iconSize[size],
"rounded-lg",
it === current
? "text-primary-foreground"
: "text-foreground hover:bg-[color-mix(in_oklab,var(--color-foreground)_8%,transparent)]"
)}
>
{it === current && (
<motion.span
layoutId={reduce ? undefined : `${uid}-rich-active`}
aria-hidden="true"
transition={reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 500, damping: 34 }}
className="absolute inset-0 rounded-lg bg-primary"
/>
)}
<span className="relative">{it}</span>
</button>
)
)}
</>
)
}
const perPageOptions = [10, 20, 50, 100]
/* SizesPagination: sayfa basi kayit secici + sayi butonlari. */
export function SizesPagination({ className, size = "md", total = 12, defaultPage = 1 }: PaginationProps) {
const { current, total: n, goto } = usePageState(total, defaultPage)
const [perPage, setPerPage] = React.useState(20)
const uid = React.useId()
const selectId = React.useId()
return (
<nav
data-slot="styled-pagination"
aria-label="Pagination"
className={cn("flex flex-wrap items-center gap-3", className)}
>
<span className="inline-flex items-center gap-2">
<label htmlFor={selectId} className="text-sm text-muted-foreground">
Rows per page
</label>
<select
id={selectId}
value={perPage}
onChange={(e) => setPerPage(Number(e.target.value))}
className={cn(controlSize[size], selectBase, focusRing)}
>
{perPageOptions.map((o) => (
<option key={o} value={o}>
{o}
</option>
))}
</select>
</span>
<span className="inline-flex items-center gap-1">
<button
type="button"
aria-label="Go to previous page"
disabled={current <= 1}
onClick={() => goto(current - 1)}
className={cn(btnBase, focusRing, iconSize[size], arrowBtn)}
>
<ChevronLeft />
</button>
<PageNumbers current={current} total={n} goto={goto} size={size} uid={uid} />
<button
type="button"
aria-label="Go to next page"
disabled={current >= n}
onClick={() => goto(current + 1)}
className={cn(btnBase, focusRing, iconSize[size], arrowBtn)}
>
<ChevronRight />
</button>
</span>
</nav>
)
}
/* TotalPagination: toplam kayit sayisi rozeti + sayi butonlari. */
export function TotalPagination({ className, size = "md", total = 12, defaultPage = 1 }: PaginationProps) {
const { current, total: n, goto } = usePageState(total, defaultPage)
const uid = React.useId()
const rows = n * 20
return (
<nav
data-slot="styled-pagination"
aria-label="Pagination"
className={cn("flex flex-wrap items-center gap-3", className)}
>
<span
className={cn(
controlSize[size],
"inline-flex items-center rounded-full bg-[color-mix(in_oklab,var(--color-primary)_12%,transparent)] px-3 tabular-nums text-foreground"
)}
>
<span className="font-semibold">{rows}</span>
<span className="ml-1 text-muted-foreground">results</span>
</span>
<span className="inline-flex items-center gap-1">
<button
type="button"
aria-label="Go to previous page"
disabled={current <= 1}
onClick={() => goto(current - 1)}
className={cn(btnBase, focusRing, iconSize[size], arrowBtn)}
>
<ChevronLeft />
</button>
<PageNumbers current={current} total={n} goto={goto} size={size} uid={uid} />
<button
type="button"
aria-label="Go to next page"
disabled={current >= n}
onClick={() => goto(current + 1)}
className={cn(btnBase, focusRing, iconSize[size], arrowBtn)}
>
<ChevronRight />
</button>
</span>
</nav>
)
}
/* PerPagePagination: sayfa basi secici, secim degisince ilk sayfaya doner. */
export function PerPagePagination({ className, size = "md", total = 12, defaultPage = 1 }: PaginationProps) {
const { current, total: n, goto } = usePageState(total, defaultPage)
const [perPage, setPerPage] = React.useState(10)
const selectId = React.useId()
return (
<nav
data-slot="styled-pagination"
aria-label="Pagination"
className={cn(
"flex flex-wrap items-center gap-3 rounded-xl border border-border bg-card p-2",
className
)}
>
<span className="inline-flex items-center gap-2">
<label htmlFor={selectId} className="text-sm text-muted-foreground">
Show
</label>
<select
id={selectId}
value={perPage}
onChange={(e) => {
setPerPage(Number(e.target.value))
goto(1)
}}
className={cn(controlSize[size], selectBase, focusRing)}
>
{perPageOptions.map((o) => (
<option key={o} value={o}>
{o} per page
</option>
))}
</select>
</span>
<span className={cn(controlSize[size], "inline-flex items-center tabular-nums text-muted-foreground")}>
Page <span className="mx-1 font-medium text-foreground">{current}</span> of{" "}
<span className="ml-1 font-medium text-foreground">{n}</span>
</span>
<span className="inline-flex items-center gap-1">
<button
type="button"
aria-label="Go to previous page"
disabled={current <= 1}
onClick={() => goto(current - 1)}
className={cn(btnBase, focusRing, iconSize[size], arrowBtn)}
>
<ChevronLeft />
</button>
<button
type="button"
aria-label="Go to next page"
disabled={current >= n}
onClick={() => goto(current + 1)}
className={cn(btnBase, focusRing, iconSize[size], arrowBtn)}
>
<ChevronRight />
</button>
</span>
</nav>
)
}
/* InfoPagination: gosterilen kayit araligi bilgisi + sayi butonlari. */
export function InfoPagination({ className, size = "md", total = 12, defaultPage = 2 }: PaginationProps) {
const { current, total: n, goto } = usePageState(total, defaultPage)
const uid = React.useId()
const perPage = 10
const rows = n * perPage
const from = (current - 1) * perPage + 1
const to = Math.min(current * perPage, rows)
return (
<nav
data-slot="styled-pagination"
aria-label="Pagination"
className={cn("flex flex-wrap items-center gap-3", className)}
>
<span
aria-live="polite"
className={cn(controlSize[size], "inline-flex items-center tabular-nums text-muted-foreground")}
>
Showing
<span className="mx-1 font-medium text-foreground">
{from}-{to}
</span>
of <span className="ml-1 font-medium text-foreground">{rows}</span>
</span>
<span className="inline-flex items-center gap-1">
<button
type="button"
aria-label="Go to previous page"
disabled={current <= 1}
onClick={() => goto(current - 1)}
className={cn(btnBase, focusRing, iconSize[size], arrowBtn)}
>
<ChevronLeft />
</button>
<PageNumbers current={current} total={n} goto={goto} size={size} uid={uid} />
<button
type="button"
aria-label="Go to next page"
disabled={current >= n}
onClick={() => goto(current + 1)}
className={cn(btnBase, focusRing, iconSize[size], arrowBtn)}
>
<ChevronRight />
</button>
</span>
</nav>
)
}
/* FullPagination: range information plus a per-page selector plus number buttons plus first/last jumps. A complete bar for a table footer. */
export function FullPagination({ className, size = "md", total = 12, defaultPage = 3 }: PaginationProps) {
const { current, total: n, goto } = usePageState(total, defaultPage)
const [perPage, setPerPage] = React.useState(10)
const uid = React.useId()
const selectId = React.useId()
const rows = n * perPage
const from = (current - 1) * perPage + 1
const to = Math.min(current * perPage, rows)
const textBtn = cn(controlSize[size], "rounded-lg border border-border px-3 text-foreground hover:bg-accent")
return (
<nav
data-slot="styled-pagination"
aria-label="Pagination"
className={cn(
"flex flex-wrap items-center gap-3 rounded-xl border border-border bg-card p-2",
className
)}
>
<span
aria-live="polite"
className={cn(controlSize[size], "inline-flex items-center tabular-nums text-muted-foreground")}
>
<span className="font-medium text-foreground">
{from}-{to}
</span>
<span className="ml-1">of {rows}</span>
</span>
<span className="inline-flex items-center gap-2">
<label htmlFor={selectId} className="text-sm text-muted-foreground">
Rows
</label>
<select
id={selectId}
value={perPage}
onChange={(e) => {
setPerPage(Number(e.target.value))
goto(1)
}}
className={cn(controlSize[size], selectBase, focusRing)}
>
{perPageOptions.map((o) => (
<option key={o} value={o}>
{o}
</option>
))}
</select>
</span>
<span className="inline-flex items-center gap-1">
<button
type="button"
disabled={current <= 1}
onClick={() => goto(1)}
className={cn(btnBase, focusRing, textBtn)}
>
First
</button>
<button
type="button"
aria-label="Go to previous page"
disabled={current <= 1}
onClick={() => goto(current - 1)}
className={cn(btnBase, focusRing, iconSize[size], arrowBtn)}
>
<ChevronLeft />
</button>
<PageNumbers current={current} total={n} goto={goto} size={size} uid={uid} />
<button
type="button"
aria-label="Go to next page"
disabled={current >= n}
onClick={() => goto(current + 1)}
className={cn(btnBase, focusRing, iconSize[size], arrowBtn)}
>
<ChevronRight />
</button>
<button
type="button"
disabled={current >= n}
onClick={() => goto(n)}
className={cn(btnBase, focusRing, textBtn)}
>
Last
</button>
</span>
</nav>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Sizes
A rows-per-page selector next to the page numbers.
import { SizesPagination } from "@/components/ui/pagination-rich"
<SizesPagination />Total
A total-results badge next to the page numbers.
import { TotalPagination } from "@/components/ui/pagination-rich"
<TotalPagination />Per page
A boxed bar with a per-page selector that resets to page one.
import { PerPagePagination } from "@/components/ui/pagination-rich"
<PerPagePagination />Info
A showing X-Y of Z readout next to the page numbers.
import { InfoPagination } from "@/components/ui/pagination-rich"
<InfoPagination />Full
Range, per-page selector, numbers and first and last jumps in one bar.
import { FullPagination } from "@/components/ui/pagination-rich"
<FullPagination />ai2 Rich paginations: 5 styled variations on the token system
The ai2 Rich paginations are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around page navigation controls with per-page selectors and record counts. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: framer-motion slides the active highlight between pages. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the highlight jumps to the active page with no animation.
What is in the ai2 Rich paginations?
5 exports in one file: Sizes, Total, Per page, Info and Full. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: framer-motion slides the active highlight between pages.
- Reduced-motion aware: Under prefers-reduced-motion, the highlight jumps to the active page with no animation.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Rich paginations sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.