{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pagination",
  "type": "registry:ui",
  "title": "Pagination",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Kinetic spring-animated pagination component featuring a sliding active selection capsule, smart ellipsis windowing, jump-to-page input, and full arrow-key keyboard navigation.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/pagination.tsx",
      "content": "\"use client\";\n\nimport React, { useState, useId, useMemo, useEffect, useRef } from \"react\";\nimport { motion, useReducedMotion } from \"framer-motion\";\nimport { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface PaginationProps extends React.HTMLAttributes<HTMLElement> {\n  /** Total number of pages */\n  totalPages?: number;\n  /** Controlled current page (1-indexed) */\n  currentPage?: number;\n  /** Initial page for uncontrolled usage */\n  defaultPage?: number;\n  /** Number of sibling page buttons visible on each side of the active page. Default: 1 */\n  siblingCount?: number;\n  /** Callback fired when the active page changes */\n  onPageChange?: (page: number) => void;\n  /** Whether to show previous/next buttons */\n  showControls?: boolean;\n  /** Whether to show first/last page skip buttons */\n  showEdgeControls?: boolean;\n  /** Whether to display a jump-to-page direct input */\n  showQuickJumper?: boolean;\n  /** Total number of items (optional, displays \"Showing X-Y of Z items\") */\n  totalItems?: number;\n  /** Page size when totalItems is provided. Default: 10 */\n  pageSize?: number;\n  /** Spring stiffness coefficient. Default: 380 */\n  stiffness?: number;\n  /** Spring damping coefficient. Default: 28 */\n  damping?: number;\n  /** Custom Tailwind classes */\n  className?: string;\n}\n\nexport function Pagination({\n  totalPages = 10,\n  currentPage: controlledPage,\n  defaultPage = 1,\n  siblingCount = 1,\n  onPageChange,\n  showControls = true,\n  showEdgeControls = true,\n  showQuickJumper = false,\n  totalItems,\n  pageSize = 10,\n  stiffness = 380,\n  damping = 28,\n  className,\n  ...props\n}: PaginationProps) {\n  const [internalPage, setInternalPage] = useState(defaultPage);\n  const [jumpInput, setJumpInput] = useState(\"\");\n  const instanceId = useId();\n  const shouldReduceMotion = useReducedMotion();\n  const containerRef = useRef<HTMLDivElement>(null);\n\n  const activePage =\n    controlledPage !== undefined ? controlledPage : internalPage;\n\n  const setPage = (page: number) => {\n    const clamped = Math.max(1, Math.min(page, totalPages));\n    if (clamped === activePage) return;\n\n    if (controlledPage === undefined) {\n      setInternalPage(clamped);\n    }\n    onPageChange?.(clamped);\n  };\n\n  // Keyboard navigation when pagination container is focused\n  const handleKeyDown = (e: React.KeyboardEvent) => {\n    if (e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      setPage(activePage - 1);\n    } else if (e.key === \"ArrowRight\") {\n      e.preventDefault();\n      setPage(activePage + 1);\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      setPage(1);\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      setPage(totalPages);\n    }\n  };\n\n  // Build page numbers array with ellipses\n  const pageRange = useMemo(() => {\n    const totalNumbers = siblingCount * 2 + 5; // siblingCount + first + last + current + 2 dots\n    if (totalNumbers >= totalPages) {\n      return Array.from({ length: totalPages }, (_, i) => i + 1);\n    }\n\n    const leftSiblingIndex = Math.max(activePage - siblingCount, 1);\n    const rightSiblingIndex = Math.min(activePage + siblingCount, totalPages);\n\n    const shouldShowLeftDots = leftSiblingIndex > 2;\n    const shouldShowRightDots = rightSiblingIndex < totalPages - 1;\n\n    if (!shouldShowLeftDots && shouldShowRightDots) {\n      const leftItemCount = 3 + 2 * siblingCount;\n      const leftRange = Array.from({ length: leftItemCount }, (_, i) => i + 1);\n      return [...leftRange, \"dots-right\", totalPages];\n    }\n\n    if (shouldShowLeftDots && !shouldShowRightDots) {\n      const rightItemCount = 3 + 2 * siblingCount;\n      const rightRange = Array.from(\n        { length: rightItemCount },\n        (_, i) => totalPages - rightItemCount + i + 1\n      );\n      return [1, \"dots-left\", ...rightRange];\n    }\n\n    const middleRange = Array.from(\n      { length: rightSiblingIndex - leftSiblingIndex + 1 },\n      (_, i) => leftSiblingIndex + i\n    );\n    return [1, \"dots-left\", ...middleRange, \"dots-right\", totalPages];\n  }, [totalPages, siblingCount, activePage]);\n\n  const handleJumpSubmit = (e: React.FormEvent) => {\n    e.preventDefault();\n    const parsed = parseInt(jumpInput, 10);\n    if (!isNaN(parsed) && parsed >= 1 && parsed <= totalPages) {\n      setPage(parsed);\n      setJumpInput(\"\");\n    }\n  };\n\n  const startItem = (activePage - 1) * pageSize + 1;\n  const endItem = Math.min(activePage * pageSize, totalItems || activePage * pageSize);\n\n  return (\n    <nav\n      role=\"navigation\"\n      aria-label=\"Pagination Navigation\"\n      onKeyDown={handleKeyDown}\n      tabIndex={0}\n      className={cn(\n        \"flex flex-wrap items-center justify-center gap-2 select-none focus:outline-none focus-visible:ring-2 focus-visible:ring-neutral-400 dark:focus-visible:ring-neutral-600 rounded-xl p-2\",\n        className\n      )}\n      {...props}\n    >\n      {/* Optional total items counter */}\n      {totalItems !== undefined && (\n        <span className=\"text-xs text-neutral-500 mr-2 dark:text-neutral-400\">\n          Showing <span className=\"font-semibold text-neutral-900 dark:text-white\">{startItem}-{endItem}</span> of{\" \"}\n          <span className=\"font-semibold text-neutral-900 dark:text-white\">{totalItems}</span>\n        </span>\n      )}\n\n      {/* First Page Skip Button */}\n      {showEdgeControls && (\n        <button\n          type=\"button\"\n          onClick={() => setPage(1)}\n          disabled={activePage === 1}\n          aria-label=\"Go to first page\"\n          className=\"flex h-9 w-9 items-center justify-center rounded-lg border border-neutral-200/80 bg-white text-neutral-600 shadow-sm transition-all hover:bg-neutral-50 hover:text-neutral-950 disabled:opacity-40 disabled:pointer-events-none active:scale-95 dark:border-neutral-800 dark:bg-neutral-900 dark:text-neutral-400 dark:hover:bg-neutral-800 dark:hover:text-white\"\n        >\n          <ChevronsLeft className=\"h-4 w-4\" />\n        </button>\n      )}\n\n      {/* Previous Page Button */}\n      {showControls && (\n        <button\n          type=\"button\"\n          onClick={() => setPage(activePage - 1)}\n          disabled={activePage === 1}\n          aria-label=\"Go to previous page\"\n          className=\"flex h-9 w-9 items-center justify-center rounded-lg border border-neutral-200/80 bg-white text-neutral-600 shadow-sm transition-all hover:bg-neutral-50 hover:text-neutral-950 disabled:opacity-40 disabled:pointer-events-none active:scale-95 dark:border-neutral-800 dark:bg-neutral-900 dark:text-neutral-400 dark:hover:bg-neutral-800 dark:hover:text-white\"\n        >\n          <ChevronLeft className=\"h-4 w-4\" />\n        </button>\n      )}\n\n      {/* Page Numbers with Spring Active Pill */}\n      <div\n        ref={containerRef}\n        className=\"flex items-center gap-1 rounded-xl border border-neutral-200/70 bg-neutral-50/70 p-1 backdrop-blur-sm dark:border-neutral-800/80 dark:bg-neutral-900/60\"\n      >\n        {pageRange.map((item, idx) => {\n          if (typeof item === \"string\") {\n            const isLeft = item === \"dots-left\";\n            return (\n              <button\n                key={`${item}-${idx}`}\n                type=\"button\"\n                onClick={() => setPage(isLeft ? activePage - 4 : activePage + 4)}\n                aria-label={isLeft ? \"Jump 4 pages backward\" : \"Jump 4 pages forward\"}\n                className=\"group flex h-8 w-8 items-center justify-center text-xs font-mono text-neutral-400 hover:text-neutral-950 dark:text-neutral-500 dark:hover:text-white\"\n              >\n                <span className=\"group-hover:hidden\">…</span>\n                <span className=\"hidden group-hover:inline text-[11px] font-sans\">\n                  {isLeft ? \"«\" : \"»\"}\n                </span>\n              </button>\n            );\n          }\n\n          const pageNum = item as number;\n          const isActive = pageNum === activePage;\n\n          return (\n            <button\n              key={pageNum}\n              type=\"button\"\n              onClick={() => setPage(pageNum)}\n              aria-label={`Page ${pageNum}`}\n              aria-current={isActive ? \"page\" : undefined}\n              className={cn(\n                \"relative flex h-8 w-8 items-center justify-center rounded-lg text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-400 dark:focus-visible:ring-neutral-600\",\n                isActive\n                  ? \"text-white dark:text-neutral-950 font-bold\"\n                  : \"text-neutral-600 hover:text-neutral-950 dark:text-neutral-400 dark:hover:text-white\"\n              )}\n            >\n              {/* Spring Active Indicator Capsule */}\n              {isActive && (\n                <motion.div\n                  layoutId={`pagination-pill-${instanceId}`}\n                  className=\"absolute inset-0 rounded-lg bg-neutral-950 shadow-md dark:bg-white -z-10\"\n                  transition={\n                    shouldReduceMotion\n                      ? { duration: 0 }\n                      : { type: \"spring\", stiffness, damping }\n                  }\n                />\n              )}\n              <span>{pageNum}</span>\n            </button>\n          );\n        })}\n      </div>\n\n      {/* Next Page Button */}\n      {showControls && (\n        <button\n          type=\"button\"\n          onClick={() => setPage(activePage + 1)}\n          disabled={activePage === totalPages}\n          aria-label=\"Go to next page\"\n          className=\"flex h-9 w-9 items-center justify-center rounded-lg border border-neutral-200/80 bg-white text-neutral-600 shadow-sm transition-all hover:bg-neutral-50 hover:text-neutral-950 disabled:opacity-40 disabled:pointer-events-none active:scale-95 dark:border-neutral-800 dark:bg-neutral-900 dark:text-neutral-400 dark:hover:bg-neutral-800 dark:hover:text-white\"\n        >\n          <ChevronRight className=\"h-4 w-4\" />\n        </button>\n      )}\n\n      {/* Last Page Skip Button */}\n      {showEdgeControls && (\n        <button\n          type=\"button\"\n          onClick={() => setPage(totalPages)}\n          disabled={activePage === totalPages}\n          aria-label=\"Go to last page\"\n          className=\"flex h-9 w-9 items-center justify-center rounded-lg border border-neutral-200/80 bg-white text-neutral-600 shadow-sm transition-all hover:bg-neutral-50 hover:text-neutral-950 disabled:opacity-40 disabled:pointer-events-none active:scale-95 dark:border-neutral-800 dark:bg-neutral-900 dark:text-neutral-400 dark:hover:bg-neutral-800 dark:hover:text-white\"\n        >\n          <ChevronsRight className=\"h-4 w-4\" />\n        </button>\n      )}\n\n      {/* Optional Quick Jumper */}\n      {showQuickJumper && (\n        <form onSubmit={handleJumpSubmit} className=\"flex items-center gap-1.5 ml-2\">\n          <span className=\"text-xs text-neutral-500 dark:text-neutral-400\">Go to</span>\n          <input\n            type=\"number\"\n            min={1}\n            max={totalPages}\n            value={jumpInput}\n            onChange={(e) => setJumpInput(e.target.value)}\n            placeholder={`${activePage}`}\n            aria-label=\"Jump to page number\"\n            className=\"h-8 w-12 rounded-lg border border-neutral-200 bg-white px-1 text-center text-xs text-neutral-900 shadow-sm focus:border-neutral-950 focus:outline-none dark:border-neutral-800 dark:bg-neutral-900 dark:text-white\"\n          />\n        </form>\n      )}\n    </nav>\n  );\n}\n\nexport default Pagination;\n",
      "type": "registry:ui",
      "target": "components/ui/pagination.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
