Installation
Add the component
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/pagination.jsonFirst component? Set up your project first
Frameworks
The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.
"use client";
import * as React from "react";
import { motion, useReducedMotion } from "motion/react";
import { ChevronLeft, ChevronRight } from "lucide-react";
import { cn } from "@/lib/utils";
export type PaginationProps = {
pages?: number;
defaultPage?: number;
page?: number;
onPageChange?: (page: number) => void;
className?: string;
};
const glide = { type: "spring", stiffness: 500, damping: 40 } as const;
export function Pagination({
pages = 5,
defaultPage = 1,
page,
onPageChange,
className,
}: PaginationProps) {
const [internal, setInternal] = React.useState(defaultPage);
const value = page ?? internal;
const reduce = useReducedMotion();
const layout = React.useId();
const go = (next: number) => {
const clamped = Math.min(pages, Math.max(1, next));
if (page === undefined) setInternal(clamped);
onPageChange?.(clamped);
};
return (
<nav aria-label="Pagination" className={cn("flex items-center gap-1", className)}>
<button
type="button"
aria-label="Previous page"
disabled={value === 1}
onClick={() => go(value - 1)}
className="flex size-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent disabled:opacity-40"
>
<ChevronLeft className="size-4" />
</button>
{Array.from({ length: pages }, (_, index) => index + 1).map((item) => (
<button
key={item}
type="button"
aria-current={item === value ? "page" : undefined}
onClick={() => go(item)}
className="relative flex size-8 items-center justify-center rounded-md text-[13px] font-medium"
>
{item === value && (
<motion.span
layoutId={`pagination-active-${layout}`}
className="absolute inset-0 rounded-md border bg-background shadow-sm"
transition={reduce ? { duration: 0 } : glide}
/>
)}
<span className={cn("relative", item === value ? "text-foreground" : "text-muted-foreground")}>
{item}
</span>
</button>
))}
<button
type="button"
aria-label="Next page"
disabled={value === pages}
onClick={() => go(value + 1)}
className="flex size-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent disabled:opacity-40"
>
<ChevronRight className="size-4" />
</button>
</nav>
);
}Install
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/pagination.jsonDependencies
motion lucide-reactThe registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.
Usage
Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.
import { Pagination } from "@/components/prequelui/pagination";
export default function Demo() {
return (
<Pagination>
{/* compose the parts exactly like the underlying primitive */}
</Pagination>
);
}import { Pagination } from "@/components/prequelui/pagination";
export function Variant() {
return (
<Pagination tempo={1.2}>
…
</Pagination>
);
}Animation
This primitive keeps the API and semantics of the underlying component and adds motion at the surface edges. Entrances are slower and more settled than exits, so closing never feels like waiting.
- Springs for position, scale and size; tweens for colour and opacity.
- The exit is shorter than the entrance, and keeps the current position as its starting point.
- All measurements are taken again when content or font metrics change.
- With reduced motion, the surface fades in place and never travels.
API Reference
Every part takes exactly the props of the Pagination primitive. The animated surface adds only motion props, so the accessibility tree and keyboard behaviour stay the same.
Pagination
| Prop | Type | Default |
|---|---|---|
| children | ReactNode | — |
| disabled | boolean | false |
| transition | Transition | spring.press |
| className | string | — |