Motion paginations
Five paginations where the active-page indicator travels instead of jumping: a spring slide, a scaling pop, a cross-fade, a loose bounce and a shape morph. 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-motionDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/pagination-motion.tsx"use client"
import * as React from "react"
import { ChevronLeft, ChevronRight, MoreHorizontal } from "lucide-react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Motion pagination family: 5 paginators where the active-page indicator moves
between pages WITH ANIMATION. The technique differs: a slide with layoutId,
pop (scale), fade, bounce (a springy hop) and morph (changing shape).
The layoutId derives from React.useId() - so that when several paginations are
rendered on the same page the indicators do not fly into each other. All motion
is gated on useReducedMotion(): in reduced there is no transform and the
indicator lands instantly. Color comes only from semantic tokens; alpha via
color-mix. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
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"
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
}
/* Shared shell: the indicator renders with each variant's own technique. */
function MotionShell({
props,
renderIndicator,
radius = "rounded-full",
}: {
props: PaginationProps
renderIndicator: (uid: string, reduce: boolean) => React.ReactNode
radius?: string
}) {
const { className, size = "md", total = 8, defaultPage = 1 } = props
const reduce = useReducedMotion() ?? false
const { current, total: n, goto } = usePageState(total, defaultPage)
const items = pageRange(current, n)
const uid = React.useId()
return (
<nav
data-slot="styled-pagination"
aria-label="Pagination"
className={cn("inline-flex items-center gap-1", className)}
>
<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>
{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],
radius,
it === current
? "text-primary-foreground"
: "text-foreground hover:bg-[color-mix(in_oklab,var(--color-foreground)_8%,transparent)]"
)}
>
{it === current ? renderIndicator(uid, reduce) : null}
<span className="relative">{it}</span>
</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>
</nav>
)
}
/* Slide: gosterge sayfalar arasinda yayla kayar (layoutId). */
export function SlidePagination(props: PaginationProps) {
return (
<MotionShell
props={props}
renderIndicator={(uid, reduce) => (
<motion.span
layoutId={reduce ? undefined : `${uid}-slide`}
aria-hidden="true"
transition={reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 520, damping: 36 }}
className="absolute inset-0 rounded-full bg-primary"
/>
)}
/>
)
}
/* Pop: the indicator also does a scale "pop" while it slides. */
export function PopPagination(props: PaginationProps) {
return (
<MotionShell
props={props}
renderIndicator={(uid, reduce) => (
<motion.span
layoutId={reduce ? undefined : `${uid}-pop`}
aria-hidden="true"
initial={reduce ? false : { scale: 0.4 }}
animate={reduce ? {} : { scale: 1 }}
transition={reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 700, damping: 20 }}
className="absolute inset-0 rounded-full bg-primary"
/>
)}
/>
)
}
/* Fade: gosterge eski sayfada soner, yenisinde belirir (transform yok). */
export function FadePagination(props: PaginationProps) {
return (
<MotionShell
props={props}
radius="rounded-lg"
renderIndicator={(uid, reduce) => (
<AnimatePresence initial={false}>
<motion.span
key={uid}
aria-hidden="true"
initial={{ opacity: reduce ? 1 : 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={reduce ? { duration: 0 } : { duration: 0.22, ease: "easeOut" }}
className="absolute inset-0 rounded-lg bg-primary"
/>
</AnimatePresence>
)}
/>
)
}
/* Bounce: a low-damping spring, so the indicator stops with a slight hop at its
target. */
export function BouncePagination(props: PaginationProps) {
return (
<MotionShell
props={props}
renderIndicator={(uid, reduce) => (
<motion.span
layoutId={reduce ? undefined : `${uid}-bounce`}
aria-hidden="true"
transition={reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 420, damping: 12, mass: 0.8 }}
className="absolute inset-0 rounded-full bg-primary"
/>
)}
/>
)
}
/* Morph: gosterge kayarken kare ile daire arasinda sekil degistirir. */
export function MorphPagination(props: PaginationProps) {
return (
<MotionShell
props={props}
radius="rounded-lg"
renderIndicator={(uid, reduce) => (
<motion.span
layoutId={reduce ? undefined : `${uid}-morph`}
aria-hidden="true"
initial={reduce ? false : { borderRadius: "50%" }}
animate={reduce ? {} : { borderRadius: "0.5rem" }}
transition={reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 380, damping: 30 }}
className="absolute inset-0 bg-primary"
/>
)}
/>
)
}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.
Slide
The indicator springs across to the new page.
import { SlidePagination } from "@/components/ui/pagination-motion"
<SlidePagination />Pop
The indicator scales up as it travels.
import { PopPagination } from "@/components/ui/pagination-motion"
<PopPagination />Fade
The indicator cross-fades between pages, no transform.
import { FadePagination } from "@/components/ui/pagination-motion"
<FadePagination />Bounce
A loose spring lets the indicator settle with a bounce.
import { BouncePagination } from "@/components/ui/pagination-motion"
<BouncePagination />Morph
The indicator morphs between a circle and a rounded square.
import { MorphPagination } from "@/components/ui/pagination-motion"
<MorphPagination />ai2 Motion paginations: 5 styled variations on the token system
The ai2 Motion paginations are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around page navigation controls with an animated active indicator. 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 moves the indicator between pages with a shared layout animation. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the indicator appears on the active page instantly with no transform.
What is in the ai2 Motion paginations?
5 exports in one file: Slide, Pop, Fade, Bounce and Morph. 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 moves the indicator between pages with a shared layout animation.
- Reduced-motion aware: Under prefers-reduced-motion, the indicator appears on the active page instantly with no transform.
- 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 Motion 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.