{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "liquid-pill-tabs",
  "type": "registry:ui",
  "title": "Liquid Pill Tabs",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Segmented navigation tab bar with dual-layer spring layout projection for active and hover indicator pills and roving WAI-ARIA keyboard control.",
  "dependencies": [
    "framer-motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/liquid-pill-tabs.tsx",
      "content": "\"use client\";\n\nimport React, { useId, useRef, useState } from \"react\";\nimport { motion, useReducedMotion } from \"framer-motion\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface LiquidTabItem {\n  id: string;\n  label: string;\n  badge?: string | number;\n}\n\nexport interface LiquidPillTabsProps {\n  /** Array of tab definitions. Defaults to a 4-item studio view switcher. */\n  tabs?: LiquidTabItem[];\n  /** Controlled active tab ID */\n  activeTab?: string;\n  /** Initial active tab ID for uncontrolled usage */\n  defaultActiveTab?: string;\n  /** Spring stiffness coefficient for pill morphing. Default: 380 */\n  stiffness?: number;\n  /** Spring damping coefficient for pill morphing. Default: 26 */\n  damping?: number;\n  /** Callback fired when active tab changes */\n  onChange?: (id: string) => void;\n  className?: string;\n}\n\nconst DEFAULT_TABS: LiquidTabItem[] = [\n  { id: \"preview\", label: \"Preview\" },\n  { id: \"physics\", label: \"Spring Config\", badge: \"3\" },\n  { id: \"code\", label: \"Source\" },\n  { id: \"a11y\", label: \"Accessibility\" },\n];\n\nexport function LiquidPillTabs({\n  tabs = DEFAULT_TABS,\n  activeTab: controlledActive,\n  defaultActiveTab = \"preview\",\n  stiffness = 380,\n  damping = 26,\n  onChange,\n  className,\n}: LiquidPillTabsProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const instanceId = useId();\n  const [internalActive, setInternalActive] = useState<string>(\n    defaultActiveTab || tabs[0]?.id || \"\"\n  );\n  const [hoveredId, setHoveredId] = useState<string | null>(null);\n  const tabRefs = useRef<Array<HTMLButtonElement | null>>([]);\n\n  const currentActive =\n    controlledActive !== undefined ? controlledActive : internalActive;\n\n  const selectTab = (id: string) => {\n    if (controlledActive === undefined) {\n      setInternalActive(id);\n    }\n    onChange?.(id);\n  };\n\n  const handleKeyDown = (\n    index: number,\n    e: React.KeyboardEvent<HTMLButtonElement>\n  ) => {\n    if (e.key === \"ArrowRight\") {\n      e.preventDefault();\n      const nextIdx = (index + 1) % tabs.length;\n      const nextTab = tabs[nextIdx];\n      if (nextTab) {\n        selectTab(nextTab.id);\n        tabRefs.current[nextIdx]?.focus();\n      }\n    } else if (e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      const prevIdx = (index - 1 + tabs.length) % tabs.length;\n      const prevTab = tabs[prevIdx];\n      if (prevTab) {\n        selectTab(prevTab.id);\n        tabRefs.current[prevIdx]?.focus();\n      }\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      const first = tabs[0];\n      if (first) {\n        selectTab(first.id);\n        tabRefs.current[0]?.focus();\n      }\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      const lastIdx = tabs.length - 1;\n      const last = tabs[lastIdx];\n      if (last) {\n        selectTab(last.id);\n        tabRefs.current[lastIdx]?.focus();\n      }\n    }\n  };\n\n  return (\n    <div\n      role=\"tablist\"\n      aria-label=\"View mode tabs\"\n      onMouseLeave={() => setHoveredId(null)}\n      className={cn(\n        \"relative inline-flex flex-wrap items-center gap-1 rounded-2xl border border-neutral-200 bg-neutral-100/80 p-1.5 backdrop-blur-md dark:border-[#222222] dark:bg-[#0D0D0D]\",\n        className\n      )}\n    >\n      {tabs.map((tab, idx) => {\n        const isActive = currentActive === tab.id;\n        const isHovered = hoveredId === tab.id;\n\n        return (\n          <button\n            key={tab.id}\n            ref={(el) => {\n              tabRefs.current[idx] = el;\n            }}\n            type=\"button\"\n            role=\"tab\"\n            aria-selected={isActive}\n            tabIndex={isActive ? 0 : -1}\n            onClick={() => selectTab(tab.id)}\n            onMouseEnter={() => setHoveredId(tab.id)}\n            onKeyDown={(e) => handleKeyDown(idx, e)}\n            className={cn(\n              \"relative z-10 inline-flex items-center gap-2 rounded-xl px-3.5 py-2 text-xs font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black dark:focus-visible:ring-white\",\n              isActive\n                ? \"text-white dark:text-black\"\n                : \"text-neutral-600 hover:text-black dark:text-neutral-400 dark:hover:text-white\"\n            )}\n          >\n            {/* Hover Ghost Pill */}\n            {isHovered && !isActive && (\n              <motion.span\n                layoutId={`${instanceId}-hover-pill`}\n                aria-hidden=\"true\"\n                transition={\n                  shouldReduceMotion\n                    ? { duration: 0 }\n                    : { type: \"spring\", stiffness: 420, damping: 30 }\n                }\n                className=\"pointer-events-none absolute inset-0 -z-10 rounded-xl bg-neutral-200/70 dark:bg-[#1B1B1B]\"\n              />\n            )}\n\n            {/* Primary Active Liquid Pill */}\n            {isActive && (\n              <motion.span\n                layoutId={`${instanceId}-active-pill`}\n                aria-hidden=\"true\"\n                transition={\n                  shouldReduceMotion\n                    ? { duration: 0 }\n                    : {\n                        type: \"spring\",\n                        stiffness,\n                        damping,\n                        mass: 0.6,\n                      }\n                }\n                className=\"pointer-events-none absolute inset-0 -z-10 rounded-xl bg-black shadow-sm dark:bg-white\"\n              />\n            )}\n\n            <span>{tab.label}</span>\n\n            {tab.badge !== undefined && (\n              <span\n                className={cn(\n                  \"rounded-full px-1.5 py-0.2 text-[10px] font-bold tabular-nums transition-colors\",\n                  isActive\n                    ? \"bg-white/20 text-white dark:bg-black/15 dark:text-black\"\n                    : \"bg-neutral-200 text-neutral-700 dark:bg-[#1F1F1F] dark:text-neutral-300\"\n                )}\n              >\n                {tab.badge}\n              </span>\n            )}\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n\nexport default LiquidPillTabs;\n",
      "type": "registry:ui",
      "target": "components/ui/liquid-pill-tabs.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"
    }
  ]
}
