{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tabs-indicator",
  "title": "Tabs indicator",
  "description": "Tabs whose indicator glides between tabs on a shared-layout spring (underline with hover highlight, pill, or segmented with icons), with arrow-key navigation and panels that slide in the direction of travel while the height eases to fit.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/number-flow.json"
  ],
  "files": [
    {
      "path": "registry/components/navigation/tabs-indicator.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion, type Transition } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { GooduiTokens, spring as springs } from \"@/lib/goodui-motion\"\nimport { NumberFlow } from \"@/components/goodui/number-flow\"\n\nexport type TabsIndicatorItem = {\n  /** Unique key of the tab; this is what value and onValueChange use. */\n  value: string\n  label: React.ReactNode\n  /** Icon component (e.g. a lucide icon), rendered at 16px before the label. */\n  icon?: React.ComponentType<{ className?: string }>\n  /** Small count or tag shown after the label. */\n  badge?: React.ReactNode\n  disabled?: boolean\n  /** Panel content. When any item has content, a panel that slides in the direction of travel is rendered. */\n  content?: React.ReactNode\n}\n\nexport type TabsIndicatorProps = Omit<React.ComponentProps<\"div\">, \"defaultValue\" | \"onChange\"> & {\n  /** The tabs, in order. Give items content to get built-in panels. */\n  items: TabsIndicatorItem[]\n  /** Selected tab value (controlled). */\n  value?: string\n  /** Initially selected tab when uncontrolled; defaults to the first enabled item. */\n  defaultValue?: string\n  /** Called with the new value on click or arrow-key selection. */\n  onValueChange?: (value: string) => void\n  /** underline: line under the active tab plus a hover highlight. pill: filled primary pill. segmented: raised thumb in a muted track. */\n  variant?: \"underline\" | \"pill\" | \"segmented\"\n  /** Stretch the tabs into equal columns. */\n  fullWidth?: boolean\n  /** Accessible name of the tab list. */\n  listLabel?: string\n  /** Classes for the tablist element. */\n  listClassName?: string\n  /** Classes for the tab panel (only rendered when items have content). */\n  panelClassName?: string\n}\n\nfunction useControllable<T>(value: T | undefined, defaultValue: T, onChange?: (v: T) => void) {\n  const [inner, setInner] = React.useState(defaultValue)\n  const controlled = value !== undefined\n  const current = controlled ? value : inner\n  const set = React.useCallback(\n    (next: T) => {\n      if (!controlled) setInner(next)\n      onChange?.(next)\n    },\n    [controlled, onChange],\n  )\n  return [current, set] as const\n}\n\nconst LIST = {\n  underline: \"flex gap-1 shadow-[inset_0_-1px_0_var(--border)]\",\n  pill: \"flex gap-1\",\n  segmented: \"inline-flex rounded-xl bg-muted p-1 shadow-[var(--pc-well)]\",\n}\n\nconst TAB = {\n  underline: \"h-10 rounded-md px-3 focus-visible:ring-inset text-muted-foreground hover:text-foreground aria-selected:text-foreground\",\n  pill: \"h-9 rounded-full px-4 focus-visible:ring-inset text-muted-foreground hover:bg-muted hover:text-foreground aria-selected:text-primary-foreground aria-selected:hover:bg-transparent\",\n  segmented: \"h-8 rounded-lg px-3 text-foreground/65 hover:text-foreground aria-selected:text-foreground\",\n}\n\nconst INDICATOR = {\n  underline: \"absolute inset-x-2 bottom-0 h-0.5 rounded-full bg-primary\",\n  pill: \"absolute inset-0 bg-primary bg-[image:var(--pc-sheen)] shadow-[inset_0_1px_var(--pc-edge-t),inset_0_-1px_var(--pc-edge-b),0_1px_2px_rgb(0_0_0/.2)]\",\n  segmented: \"absolute inset-0 bg-background shadow-[var(--pc-e1)] dark:bg-input\",\n}\n\nconst BADGE = {\n  underline: \"bg-muted text-foreground/75 group-aria-selected:bg-primary/10 group-aria-selected:text-primary\",\n  pill: \"bg-muted text-foreground/75 group-aria-selected:bg-primary-foreground/20 group-aria-selected:text-primary-foreground\",\n  segmented: \"bg-background/70 text-foreground/75 dark:bg-white/10\",\n}\n\n/** Animates its own height to the measured height of its content. */\nfunction AutoHeight({ children, transition, className }: { children: React.ReactNode; transition: Transition; className?: string }) {\n  const ref = React.useRef<HTMLDivElement>(null)\n  const [height, setHeight] = React.useState<number | \"auto\">(\"auto\")\n  React.useEffect(() => {\n    const el = ref.current\n    if (!el) return\n    const ro = new ResizeObserver(([entry]) => entry && setHeight(entry.contentRect.height))\n    ro.observe(el)\n    return () => ro.disconnect()\n  }, [])\n  return (\n    <motion.div className={cn(\"relative overflow-hidden\", className)} initial={false} animate={{ height }} transition={transition}>\n      <div ref={ref}>{children}</div>\n    </motion.div>\n  )\n}\n\n/**\n * Tabs with a shared-layout indicator that glides between tabs (underline, pill or segmented), arrow-key\n * navigation and a panel that slides in the direction of travel.\n */\nexport function TabsIndicator({\n  items,\n  value,\n  defaultValue,\n  onValueChange,\n  variant = \"underline\",\n  fullWidth = false,\n  listLabel,\n  listClassName,\n  panelClassName,\n  className,\n  ...props\n}: TabsIndicatorProps) {\n  const uid = React.useId()\n  const reduce = useReducedMotion() ?? false\n  const [current, setCurrent] = useControllable(value, defaultValue ?? items.find((i) => !i.disabled)?.value ?? \"\", onValueChange)\n  const index = Math.max(0, items.findIndex((i) => i.value === current))\n  const active = items[index]\n  const hasPanels = items.some((i) => i.content !== undefined)\n  const tabRefs = React.useRef<(HTMLButtonElement | null)[]>([])\n  const listRef = React.useRef<HTMLDivElement>(null)\n  // Right-to-left layout flips arrow keys and the panel slide; read after mount so SSR output is unchanged.\n  const [rtl, setRtl] = React.useState(false)\n  React.useEffect(() => {\n    if (listRef.current) setRtl(getComputedStyle(listRef.current).direction === \"rtl\")\n  }, [])\n\n  // Direction of travel, derived when the index changes (also for controlled updates).\n  const [prevIndex, setPrevIndex] = React.useState(index)\n  const [direction, setDirection] = React.useState(1)\n  if (prevIndex !== index) {\n    setDirection(index > prevIndex ? 1 : -1)\n    setPrevIndex(index)\n  }\n\n  // Hover highlight for the underline variant: one element that glides under the pointer.\n  const [hover, setHover] = React.useState<{ x: number; w: number; visible: boolean; glide: boolean }>({ x: 0, w: 0, visible: false, glide: false })\n  const onTabEnter = (i: number) => {\n    if (variant !== \"underline\") return\n    const el = tabRefs.current[i]\n    if (!el || items[i]?.disabled) return\n    setHover((h) => ({ x: el.offsetLeft, w: el.offsetWidth, visible: true, glide: h.visible }))\n  }\n\n  const spring: Transition = reduce ? { duration: 0 } : springs.snap\n\n  const enabled = items.map((item, i) => ({ item, i })).filter((x) => !x.item.disabled)\n  const onKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>, i: number) => {\n    const pos = enabled.findIndex((x) => x.i === i)\n    let next: (typeof enabled)[number] | undefined\n    const isRtl = getComputedStyle(e.currentTarget).direction === \"rtl\"\n    const forward = isRtl ? \"ArrowLeft\" : \"ArrowRight\"\n    const back = isRtl ? \"ArrowRight\" : \"ArrowLeft\"\n    if (e.key === forward) next = enabled[(pos + 1) % enabled.length]\n    else if (e.key === back) next = enabled[(pos - 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    setCurrent(next.item.value)\n    tabRefs.current[next.i]?.focus()\n  }\n\n  const slide = reduce ? 0 : rtl ? -28 : 28\n  const panelVariants = {\n    enter: (d: number) => ({ x: d * slide, opacity: 0, filter: reduce ? \"none\" : \"blur(4px)\" }),\n    center: { x: 0, opacity: 1, filter: reduce ? \"none\" : \"blur(0px)\" },\n    exit: (d: number) => ({ x: -d * slide, opacity: 0, filter: reduce ? \"none\" : \"blur(4px)\" }),\n  }\n\n  return (\n    <div data-slot=\"tabs-indicator\" className={cn(\"flex flex-col gap-4\", className)} {...props}>\n      <GooduiTokens />\n      <div className={cn(\"max-w-full overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\", variant !== \"segmented\" && \"w-full\", fullWidth && \"w-full\")}>\n        <div\n          ref={listRef}\n          role=\"tablist\"\n          aria-orientation=\"horizontal\"\n          aria-label={listLabel}\n          className={cn(\"relative\", LIST[variant], fullWidth ? \"w-full\" : variant === \"segmented\" ? \"\" : \"w-max min-w-full\", listClassName)}\n          onPointerLeave={() => setHover((h) => ({ ...h, visible: false }))}\n        >\n          {variant === \"underline\" && (\n            <motion.span\n              aria-hidden=\"true\"\n              className=\"pointer-events-none absolute top-1 bottom-1.5 left-0 rounded-md bg-muted\"\n              initial={false}\n              animate={{ x: hover.x, width: hover.w, opacity: hover.visible ? 1 : 0 }}\n              transition={{\n                x: hover.glide ? spring : { duration: 0 },\n                width: hover.glide ? spring : { duration: 0 },\n                opacity: { duration: reduce ? 0 : 0.15 },\n              }}\n            />\n          )}\n          {items.map((item, i) => {\n            const selected = i === index\n            const Icon = item.icon\n            return (\n              <button\n                key={item.value}\n                ref={(el) => {\n                  tabRefs.current[i] = el\n                }}\n                id={`${uid}-tab-${i}`}\n                type=\"button\"\n                role=\"tab\"\n                aria-selected={selected}\n                aria-controls={hasPanels && selected ? `${uid}-panel` : undefined}\n                tabIndex={selected ? 0 : -1}\n                disabled={item.disabled}\n                onClick={() => setCurrent(item.value)}\n                onKeyDown={(e) => onKeyDown(e, i)}\n                onPointerEnter={() => onTabEnter(i)}\n                className={cn(\n                  \"pc-press pc-press-soft group relative inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 text-sm font-medium whitespace-nowrap transition-colors outline-none select-none focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-40\",\n                  TAB[variant],\n                  fullWidth && \"flex-1\",\n                )}\n              >\n                {selected && (\n                  <motion.span\n                    layoutId={`${uid}-indicator`}\n                    aria-hidden=\"true\"\n                    className={INDICATOR[variant]}\n                    style={{ borderRadius: variant === \"pill\" ? 9999 : variant === \"segmented\" ? 8 : 9999 }}\n                    transition={spring}\n                  />\n                )}\n                <span className=\"relative z-10 inline-flex items-center gap-2\">\n                  {Icon && <Icon className=\"size-4 shrink-0\" />}\n                  {item.label}\n                  {item.badge !== undefined && (\n                    <span className={cn(\"rounded-full px-1.5 py-px text-[11px] leading-4 font-semibold tabular-nums transition-colors\", BADGE[variant])}>\n                      {typeof item.badge === \"number\" ? <NumberFlow value={item.badge} /> : item.badge}\n                    </span>\n                  )}\n                </span>\n              </button>\n            )\n          })}\n        </div>\n      </div>\n\n      {hasPanels && (\n        <AutoHeight transition={reduce ? { duration: 0 } : springs.snap}>\n          <AnimatePresence mode=\"popLayout\" initial={false} custom={direction}>\n            <motion.div\n              key={active?.value}\n              id={`${uid}-panel`}\n              role=\"tabpanel\"\n              aria-labelledby={`${uid}-tab-${index}`}\n              tabIndex={0}\n              custom={direction}\n              variants={panelVariants}\n              initial=\"enter\"\n              animate=\"center\"\n              exit=\"exit\"\n              transition={reduce ? { duration: 0 } : { ...springs.ui, opacity: { duration: 0.18 } }}\n              className={cn(\"rounded-md outline-none focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:ring-inset\", panelClassName)}\n            >\n              {active?.content}\n            </motion.div>\n          </AnimatePresence>\n        </AutoHeight>\n      )}\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/tabs-indicator.tsx"
    }
  ],
  "categories": [
    "components",
    "navigation"
  ],
  "type": "registry:component"
}
