{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"animated-tabs","type":"registry:ui","title":"Animated Tabs","description":"Tabs with a sliding indicator, panels that follow its direction and full keyboard support.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/animated-tabs.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { AnimatePresence, motion, useReducedMotion, type Variants } from \"motion/react\";\nimport { useId, useState, type KeyboardEvent, type ReactNode } from \"react\";\n\nexport type AnimatedTab = {\n  id: string;\n  label: ReactNode;\n  content: ReactNode;\n  disabled?: boolean;\n};\n\ntype AnimatedTabsProps = {\n  tabs: AnimatedTab[];\n  /** Tab shown first when uncontrolled. Defaults to the first enabled tab. */\n  defaultTab?: string;\n  /** Active tab id, for controlled use. */\n  value?: string;\n  onChange?: (id: string) => void;\n  variant?: \"pill\" | \"underline\";\n  /** Color of the sliding indicator. */\n  color?: string;\n  /** Accessible name of the tab list. */\n  label?: string;\n  className?: string;\n  panelClassName?: string;\n};\n\n/** Tabs with a sliding indicator, direction-aware panels and the full ARIA keyboard model. */\nexport function AnimatedTabs({\n  tabs,\n  defaultTab,\n  value,\n  onChange,\n  variant = \"pill\",\n  color = \"#ff784f\",\n  label = \"Tabs\",\n  className = \"\",\n  panelClassName = \"\",\n}: AnimatedTabsProps) {\n  const uid = useId();\n  const reduce = useReducedMotion();\n  const firstEnabled = tabs.find((t) => !t.disabled)?.id ?? \"\";\n  const [internal, setInternal] = useState(defaultTab ?? firstEnabled);\n  // Direction of the last switch, so the panel slides the same way as the indicator.\n  const [direction, setDirection] = useState(1);\n  const active = value ?? internal;\n  const activeIndex = tabs.findIndex((t) => t.id === active);\n  const activeTab = tabs[activeIndex];\n  const pill = variant === \"pill\";\n\n  const tabId = (id: string) => `${uid}-tab-${id}`;\n  const panelId = (id: string) => `${uid}-panel-${id}`;\n\n  function select(id: string) {\n    if (id === active) return;\n    setDirection(tabs.findIndex((t) => t.id === id) > activeIndex ? 1 : -1);\n    if (value === undefined) setInternal(id);\n    onChange?.(id);\n  }\n\n  function onKeyDown(e: KeyboardEvent<HTMLDivElement>) {\n    const enabled = tabs.filter((t) => !t.disabled);\n    if (enabled.length === 0) return;\n    const current = enabled.findIndex((t) => tabId(t.id) === (e.target as HTMLElement).id);\n    let next: AnimatedTab | undefined;\n    if (e.key === \"ArrowRight\") next = enabled[(current + 1) % enabled.length];\n    else if (e.key === \"ArrowLeft\") next = enabled[(current - 1 + enabled.length) % enabled.length];\n    else if (e.key === \"Home\") next = enabled[0];\n    else if (e.key === \"End\") next = enabled[enabled.length - 1];\n    if (!next) return;\n    e.preventDefault();\n    select(next.id);\n    document.getElementById(tabId(next.id))?.focus();\n  }\n\n  const distance = reduce ? 0 : 14;\n  const blur = reduce ? \"blur(0px)\" : \"blur(4px)\";\n  const panel: Variants = {\n    enter: (d: number) => ({ opacity: 0, x: d * distance, filter: blur }),\n    center: { opacity: 1, x: 0, filter: \"blur(0px)\" },\n    exit: (d: number) => ({ opacity: 0, x: d * -distance, filter: blur }),\n  };\n\n  return (\n    <div className={className}>\n      <div\n        role=\"tablist\"\n        aria-label={label}\n        aria-orientation=\"horizontal\"\n        onKeyDown={onKeyDown}\n        className={\n          pill\n            ? \"inline-flex max-w-full gap-1 rounded-full border border-ink-600 bg-ink-900 p-1\"\n            : \"flex max-w-full gap-1 border-b border-ink-600\"\n        }\n      >\n        {tabs.map((t) => {\n          const selected = t.id === active;\n          const focusable = selected || (activeIndex === -1 && t.id === firstEnabled);\n          return (\n            <button\n              key={t.id}\n              id={tabId(t.id)}\n              type=\"button\"\n              role=\"tab\"\n              aria-selected={selected}\n              aria-controls={panelId(t.id)}\n              tabIndex={focusable ? 0 : -1}\n              disabled={t.disabled}\n              onClick={() => select(t.id)}\n              className={`relative whitespace-nowrap px-4 text-sm font-semibold transition-colors disabled:cursor-not-allowed disabled:opacity-40 ${\n                pill ? \"rounded-full py-1.5\" : \"py-2.5\"\n              } ${selected ? (pill ? \"text-ink-950\" : \"text-bone\") : \"text-bone-dim hover:text-bone\"}`}\n            >\n              {selected ? (\n                <motion.span\n                  layoutId={`${uid}-indicator`}\n                  aria-hidden=\"true\"\n                  className={pill ? \"absolute inset-0 rounded-full\" : \"absolute inset-x-2 -bottom-px h-0.5 rounded-full\"}\n                  style={{ backgroundColor: color }}\n                  transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 420, damping: 34 }}\n                />\n              ) : null}\n              <span className=\"relative\">{t.label}</span>\n            </button>\n          );\n        })}\n      </div>\n\n      <div className={`relative mt-4 ${panelClassName}`}>\n        <AnimatePresence mode=\"wait\" initial={false} custom={direction}>\n          {activeTab ? (\n            <motion.div\n              key={activeTab.id}\n              id={panelId(activeTab.id)}\n              role=\"tabpanel\"\n              aria-labelledby={tabId(activeTab.id)}\n              tabIndex={0}\n              custom={direction}\n              variants={panel}\n              initial=\"enter\"\n              animate=\"center\"\n              exit=\"exit\"\n              transition={{ duration: reduce ? 0 : 0.2, ease: [0.22, 1, 0.36, 1] }}\n              className=\"rounded-xl\"\n            >\n              {activeTab.content}\n            </motion.div>\n          ) : null}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n"}]}