{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "animated-tabs",
  "title": "Animated Tabs",
  "description": "Switch segmented options with a fluid shared-layout indicator.",
  "dependencies": [
    "motion"
  ],
  "files": [
    {
      "path": "src/registry/components/animated-tabs/animated-tabs.tsx",
      "content": "\"use client\";\n\nimport { MotionConfig, motion } from \"motion/react\";\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport type AnimatedTab = {\n\tvalue: string;\n\tlabel: React.ReactNode;\n};\n\nexport type AnimatedTabsProps = Omit<\n\tReact.ComponentProps<\"div\">,\n\t\"defaultValue\" | \"role\"\n> & {\n\ttabs: readonly AnimatedTab[];\n\t/** Controlled active tab value. */\n\tvalue?: string;\n\t/** Initial active tab value when uncontrolled. Defaults to the first tab. */\n\tdefaultValue?: string;\n\t/** Fired when the active tab changes. */\n\tonValueChange?: (value: string) => void;\n\t/** Shared-layout id for the active indicator. */\n\tlayoutId?: string;\n};\n\nconst INDICATOR_SPRING = {\n\ttype: \"spring\",\n\tduration: 0.35,\n\tbounce: 0.12,\n} as const;\n\nconst INSTANT_TRANSITION = { duration: 0 } as const;\n\nexport function AnimatedTabs({\n\ttabs,\n\tvalue,\n\tdefaultValue,\n\tonValueChange,\n\tlayoutId,\n\tclassName,\n\tonKeyDown,\n\t...props\n}: AnimatedTabsProps) {\n\tconst generatedLayoutId = React.useId();\n\tconst [internalValue, setInternalValue] = React.useState(\n\t\tdefaultValue ?? tabs[0]?.value,\n\t);\n\tconst requestedValue = value ?? internalValue;\n\tconst active = tabs.some((tab) => tab.value === requestedValue)\n\t\t? requestedValue\n\t\t: tabs[0]?.value;\n\tconst indicatorLayoutId = layoutId ?? `animated-tabs-${generatedLayoutId}`;\n\tconst tabRefs = React.useRef(new Map<string, HTMLButtonElement>());\n\tconst instantValueRef = React.useRef<string | null>(null);\n\n\tfunction selectTab(nextValue: string, animate = true) {\n\t\tinstantValueRef.current = animate ? null : nextValue;\n\t\tif (value === undefined) setInternalValue(nextValue);\n\t\tonValueChange?.(nextValue);\n\t}\n\n\tfunction handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {\n\t\tonKeyDown?.(event);\n\t\tif (event.defaultPrevented) return;\n\n\t\tconst index = tabs.findIndex((tab) => tab.value === active);\n\t\tif (index === -1 || tabs.length === 0) return;\n\n\t\tlet nextTab: AnimatedTab | undefined;\n\t\tif (event.key === \"ArrowRight\" || event.key === \"ArrowDown\") {\n\t\t\tnextTab = tabs[(index + 1) % tabs.length];\n\t\t} else if (event.key === \"ArrowLeft\" || event.key === \"ArrowUp\") {\n\t\t\tnextTab = tabs[(index - 1 + tabs.length) % tabs.length];\n\t\t} else if (event.key === \"Home\") {\n\t\t\tnextTab = tabs[0];\n\t\t} else if (event.key === \"End\") {\n\t\t\tnextTab = tabs[tabs.length - 1];\n\t\t} else {\n\t\t\treturn;\n\t\t}\n\n\t\tevent.preventDefault();\n\t\tif (!nextTab) return;\n\n\t\tselectTab(nextTab.value, false);\n\t\ttabRefs.current.get(nextTab.value)?.focus();\n\t}\n\n\tif (tabs.length === 0) return null;\n\n\treturn (\n\t\t<MotionConfig reducedMotion=\"user\">\n\t\t\t<div\n\t\t\t\t{...props}\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"relative inline-flex items-center gap-1 rounded-md bg-muted/60 p-1\",\n\t\t\t\t\tclassName,\n\t\t\t\t)}\n\t\t\t\tdata-slot=\"animated-tabs\"\n\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\trole=\"radiogroup\"\n\t\t\t>\n\t\t\t\t{tabs.map((tab) => {\n\t\t\t\t\tconst selected = tab.value === active;\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-checked={selected}\n\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\"relative inline-flex h-6 flex-1 cursor-pointer touch-manipulation items-center justify-center rounded-md px-3 font-medium text-sm transition-[color,transform] ease-[cubic-bezier(0.23,1,0.32,1)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 active:scale-[0.98]\",\n\t\t\t\t\t\t\t\tinstantValueRef.current === active\n\t\t\t\t\t\t\t\t\t? \"duration-0\"\n\t\t\t\t\t\t\t\t\t: \"duration-160\",\n\t\t\t\t\t\t\t\tselected\n\t\t\t\t\t\t\t\t\t? \"text-primary-foreground\"\n\t\t\t\t\t\t\t\t\t: \"text-muted-foreground hover:text-foreground\",\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\tdata-slot=\"animated-tabs-trigger\"\n\t\t\t\t\t\t\tdata-state={selected ? \"active\" : \"inactive\"}\n\t\t\t\t\t\t\tkey={tab.value}\n\t\t\t\t\t\t\tonClick={() => selectTab(tab.value)}\n\t\t\t\t\t\t\tref={(node) => {\n\t\t\t\t\t\t\t\tif (node) tabRefs.current.set(tab.value, node);\n\t\t\t\t\t\t\t\telse tabRefs.current.delete(tab.value);\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\trole=\"radio\"\n\t\t\t\t\t\t\ttabIndex={selected ? 0 : -1}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{selected ? (\n\t\t\t\t\t\t\t\t<motion.span\n\t\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 rounded-md bg-primary shadow-sm\"\n\t\t\t\t\t\t\t\t\tdata-slot=\"animated-tabs-indicator\"\n\t\t\t\t\t\t\t\t\tlayoutId={indicatorLayoutId}\n\t\t\t\t\t\t\t\t\ttransition={\n\t\t\t\t\t\t\t\t\t\tinstantValueRef.current === active\n\t\t\t\t\t\t\t\t\t\t\t? INSTANT_TRANSITION\n\t\t\t\t\t\t\t\t\t\t\t: INDICATOR_SPRING\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t<span className=\"relative z-10\">{tab.label}</span>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t);\n\t\t\t\t})}\n\t\t\t</div>\n\t\t</MotionConfig>\n\t);\n}\n\nexport default AnimatedTabs;\n",
      "type": "registry:component",
      "target": "@components/animated-tabs.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-07-21",
    "image": "https://cdn.tentui.com/images/components/animated-tabs",
    "video": "https://cdn.tentui.com/videos/components/animated-tabs"
  },
  "docs": "https://tentui.com/components/animated-tabs",
  "categories": [
    "navigation"
  ],
  "type": "registry:component"
}