{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"animated-tabs","type":"registry:ui","title":"Animated Tabs","description":"Tab bar with a springy shared-layout indicator and panels that slide and blur in the direction of travel.","dependencies":["motion"],"registryDependencies":[],"files":[{"path":"registry/ui/animated-tabs.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useId, useRef, useState, type KeyboardEvent, type ReactNode } from \"react\";\nimport { AnimatePresence, LayoutGroup, motion, useReducedMotion } from \"motion/react\";\n\nexport interface AnimatedTab {\n  id: string;\n  label: string;\n  icon?: ReactNode;\n  content: ReactNode;\n}\n\nexport interface AnimatedTabsProps {\n  tabs: AnimatedTab[];\n  /** Id of the tab selected at first render. Defaults to the first tab. */\n  defaultTab?: string;\n  /** Indicator style. */\n  variant?: \"pill\" | \"underline\";\n  /** How panels enter: slide in from the side of travel, or just crossfade. */\n  transition?: \"slide\" | \"fade\";\n  /** Spring bounce of the indicator, 0 (none) to 0.5. */\n  bounce?: number;\n  onChange?: (id: string) => void;\n  className?: string;\n}\n\nexport function AnimatedTabs({\n  tabs,\n  defaultTab,\n  variant = \"pill\",\n  transition = \"slide\",\n  bounce = 0.2,\n  onChange,\n  className,\n}: AnimatedTabsProps) {\n  const [active, setActive] = useState(defaultTab ?? tabs[0]?.id);\n  // Direction of travel (+1 right, -1 left) so the panel slides the way the indicator moves.\n  const [dir, setDir] = useState(1);\n  const reduce = useReducedMotion();\n  const uid = useId();\n  const btns = useRef<(HTMLButtonElement | null)[]>([]);\n\n  const index = Math.max(0, tabs.findIndex((t) => t.id === active));\n  const current = tabs[index];\n\n  const select = (i: number) => {\n    const t = tabs[i];\n    if (!t || t.id === active) return;\n    setDir(i > index ? 1 : -1);\n    setActive(t.id);\n    onChange?.(t.id);\n  };\n\n  const onKey = (e: KeyboardEvent<HTMLDivElement>) => {\n    const n = tabs.length;\n    const map: Record<string, number> = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: n - 1 };\n    if (!(e.key in map)) return;\n    e.preventDefault();\n    const i = (map[e.key] + n) % n;\n    select(i);\n    btns.current[i]?.focus();\n  };\n\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, bounce, duration: 0.5 };\n  const shift = transition === \"slide\" && !reduce ? 28 : 0;\n\n  return (\n    <div className={`flex w-full flex-col gap-4 ${className ?? \"\"}`}>\n      <LayoutGroup id={uid}>\n        <div\n          role=\"tablist\"\n          aria-orientation=\"horizontal\"\n          onKeyDown={onKey}\n          className={`relative flex w-fit max-w-full self-center overflow-x-auto ${\n            variant === \"pill\" ? \"gap-1 rounded-full border border-border bg-card/70 p-1 backdrop-blur\" : \"gap-2 border-b border-border\"\n          }`}\n        >\n          {tabs.map((t, i) => {\n            const on = t.id === current?.id;\n            return (\n              <button\n                key={t.id}\n                ref={(el) => {\n                  btns.current[i] = el;\n                }}\n                id={`${uid}-tab-${t.id}`}\n                role=\"tab\"\n                type=\"button\"\n                aria-selected={on}\n                aria-controls={`${uid}-panel`}\n                tabIndex={on ? 0 : -1}\n                onClick={() => select(i)}\n                className={`relative flex shrink-0 items-center gap-2 whitespace-nowrap px-4 py-2 text-sm font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring ${\n                  variant === \"pill\" ? \"rounded-full\" : \"rounded-md\"\n                } ${on ? (variant === \"pill\" ? \"text-primary-foreground\" : \"text-foreground\") : \"text-muted-foreground hover:text-foreground\"}`}\n              >\n                {on && (\n                  <motion.span\n                    layoutId=\"indicator\"\n                    aria-hidden\n                    transition={spring}\n                    className={\n                      variant === \"pill\"\n                        ? \"absolute inset-0 rounded-full bg-primary shadow-[0_4px_18px_-6px_rgba(0,0,0,.5)]\"\n                        : \"absolute inset-x-2 -bottom-px h-0.5 rounded-full bg-foreground\"\n                    }\n                  />\n                )}\n                {t.icon && <span className=\"relative z-10 grid size-4 place-items-center [&>svg]:size-full\">{t.icon}</span>}\n                <span className=\"relative z-10\">{t.label}</span>\n              </button>\n            );\n          })}\n        </div>\n      </LayoutGroup>\n\n      <div className=\"relative grid overflow-hidden\">\n        <AnimatePresence initial={false} custom={dir}>\n          <motion.div\n            key={current?.id}\n            id={`${uid}-panel`}\n            role=\"tabpanel\"\n            aria-labelledby={`${uid}-tab-${current?.id}`}\n            custom={dir}\n            variants={{\n              enter: (d: number) => ({ opacity: 0, x: d * shift, filter: reduce ? \"none\" : \"blur(6px)\" }),\n              center: { opacity: 1, x: 0, filter: \"blur(0px)\" },\n              exit: (d: number) => ({ opacity: 0, x: -d * shift, filter: reduce ? \"none\" : \"blur(6px)\" }),\n            }}\n            initial=\"enter\"\n            animate=\"center\"\n            exit=\"exit\"\n            transition={reduce ? { duration: 0 } : { duration: 0.35, ease: [0.2, 0.7, 0.2, 1] }}\n            style={{ gridArea: \"1 / 1\" }}\n          >\n            {current?.content}\n          </motion.div>\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n"}]}