{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pagination","type":"registry:ui","title":"Pagination","description":"Page controls with fixed-width ellipsis logic, a spring-sliding active pill, and ellipses that turn into skip buttons on hover.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/ui/pagination.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useId, useState, type HTMLAttributes } from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight, MoreHorizontal } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\ntype Slot = number | \"start-ellipsis\" | \"end-ellipsis\";\n\n/**\n * Pages to show: `boundaries` at each end, `siblings` around the current page,\n * ellipses for the gaps. Always returns the same number of slots once the page\n * count exceeds it, so the bar never changes width while paging.\n */\nexport function paginationRange(page: number, total: number, siblings = 1, boundaries = 1): Slot[] {\n  const range = (a: number, z: number) => Array.from({ length: Math.max(0, z - a + 1) }, (_, i) => a + i);\n  const w = siblings * 2 + 1;\n  if (total <= 2 * boundaries + w + 2) return range(1, total);\n  if (page <= boundaries + siblings + 2) return [...range(1, boundaries + w + 1), \"end-ellipsis\", ...range(total - boundaries + 1, total)];\n  if (page >= total - boundaries - siblings - 1) return [...range(1, boundaries), \"start-ellipsis\", ...range(total - boundaries - w, total)];\n  return [...range(1, boundaries), \"start-ellipsis\", ...range(page - siblings, page + siblings), \"end-ellipsis\", ...range(total - boundaries + 1, total)];\n}\n\nexport interface PaginationProps extends Omit<HTMLAttributes<HTMLElement>, \"onChange\"> {\n  /** Number of pages. */\n  total: number;\n  /** Current page, 1-based (controlled). */\n  page?: number;\n  defaultPage?: number;\n  onPageChange?: (page: number) => void;\n  /** Pages shown on each side of the current one. */\n  siblings?: number;\n  /** Pages always shown at the start and end. */\n  boundaries?: number;\n  /** Show the Previous / Next buttons. */\n  showControls?: boolean;\n}\n\nconst item =\n  \"relative inline-flex h-9 min-w-9 items-center justify-center gap-1 rounded-lg px-2.5 text-sm font-medium tabular-nums outline-none transition-[color,background-color,scale] duration-150 focus-visible:ring-[3px] focus-visible:ring-ring/50 active:scale-95 disabled:pointer-events-none disabled:opacity-40 motion-reduce:transition-none\";\n\nexport function Pagination({\n  total,\n  page: pageProp,\n  defaultPage = 1,\n  onPageChange,\n  siblings = 1,\n  boundaries = 1,\n  showControls = true,\n  className,\n  ...props\n}: PaginationProps) {\n  const [inner, setInner] = useState(defaultPage);\n  const id = useId();\n  const reduce = useReducedMotion();\n  const count = Math.max(1, Math.floor(total));\n  const page = Math.min(Math.max(1, pageProp ?? inner), count);\n  const go = (p: number) => {\n    const next = Math.min(Math.max(1, p), count);\n    if (next === page) return;\n    if (pageProp === undefined) setInner(next);\n    onPageChange?.(next);\n  };\n  const jump = siblings * 2 + 1;\n\n  return (\n    <nav aria-label=\"Pagination\" {...props} className={cn(\"flex justify-center\", className)}>\n      <ul className=\"flex items-center gap-1\">\n        {showControls && (\n          <li>\n            <button type=\"button\" aria-label=\"Previous page\" disabled={page <= 1} onClick={() => go(page - 1)} className={cn(item, \"pr-3 text-foreground hover:bg-muted\")}>\n              <ChevronLeft className=\"size-4\" aria-hidden />\n              <span className=\"hidden sm:inline\">Previous</span>\n            </button>\n          </li>\n        )}\n        {paginationRange(page, count, siblings, boundaries).map((slot, i) => {\n          if (typeof slot === \"string\") {\n            const back = slot === \"start-ellipsis\";\n            const Icon = back ? ChevronsLeft : ChevronsRight;\n            return (\n              <li key={slot}>\n                {/* Dots morph into a chevron on hover/focus; clicking skips a window of pages. */}\n                <button\n                  type=\"button\"\n                  aria-label={back ? `Back ${jump} pages` : `Forward ${jump} pages`}\n                  onClick={() => go(page + (back ? -jump : jump))}\n                  className={cn(item, \"group text-muted-foreground hover:bg-muted hover:text-foreground\")}\n                >\n                  <MoreHorizontal aria-hidden className=\"size-4 transition-[opacity,scale] duration-200 group-hover:scale-50 group-hover:opacity-0 group-focus-visible:scale-50 group-focus-visible:opacity-0\" />\n                  <Icon aria-hidden className=\"absolute size-4 scale-50 opacity-0 transition-[opacity,scale] duration-200 group-hover:scale-100 group-hover:opacity-100 group-focus-visible:scale-100 group-focus-visible:opacity-100\" />\n                </button>\n              </li>\n            );\n          }\n          const current = slot === page;\n          return (\n            <li key={`p${i}`}>\n              <button\n                type=\"button\"\n                aria-label={`Page ${slot}`}\n                aria-current={current ? \"page\" : undefined}\n                onClick={() => go(slot)}\n                className={cn(item, current ? \"text-primary-foreground\" : \"text-foreground hover:bg-muted\")}\n              >\n                {current && (\n                  <motion.span\n                    aria-hidden\n                    layoutId={`${id}-active`}\n                    transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 36 }}\n                    className=\"absolute inset-0 rounded-lg bg-primary shadow-md shadow-primary/25\"\n                  />\n                )}\n                <span className=\"relative\">{slot}</span>\n              </button>\n            </li>\n          );\n        })}\n        {showControls && (\n          <li>\n            <button type=\"button\" aria-label=\"Next page\" disabled={page >= count} onClick={() => go(page + 1)} className={cn(item, \"pl-3 text-foreground hover:bg-muted\")}>\n              <span className=\"hidden sm:inline\">Next</span>\n              <ChevronRight className=\"size-4\" aria-hidden />\n            </button>\n          </li>\n        )}\n      </ul>\n    </nav>\n  );\n}\n"}]}