{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "trail-tabs",
  "title": "Trail Tabs",
  "description": "Tabs that fold down to their icons; the picked tab opens to show its name, its icon moves, and panels slide in.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "components/ui/trail-tabs.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\n\nimport { iconGestures, iconRest, springs, type IconGesture } from \"@/lib/afterglow\"\nimport { cn } from \"@/lib/utils\"\n\ntype TrailTab = {\n  value: string\n  label: React.ReactNode\n  icon?: React.ReactNode\n  /** how the icon moves when its tab is picked: a bell rings, a gear turns. defaults to a small pop */\n  iconGesture?: IconGesture\n  /** the panel shown when this tab is active */\n  content?: React.ReactNode\n  disabled?: boolean\n}\n\ntype TrailTabsProps = Omit<\n  React.ComponentProps<\"div\">,\n  \"defaultValue\" | \"onChange\"\n> & {\n  tabs: TrailTab[]\n  value?: string\n  defaultValue?: string\n  onValueChange?: (value: string) => void\n  /** classes for the tab strip, when panels sit below it */\n  listClassName?: string\n  /** \"active\" folds every other tab down to its icon; \"all\" always shows every label */\n  labels?: \"active\" | \"all\"\n}\n\nfunction TrailTabs({\n  tabs,\n  value,\n  defaultValue,\n  onValueChange,\n  className,\n  listClassName,\n  labels = \"active\",\n  ...props\n}: TrailTabsProps) {\n  const id = React.useId()\n  const reduceMotion = useReducedMotion()\n  const [internal, setInternal] = React.useState(\n    defaultValue ?? tabs.find((tab) => !tab.disabled)?.value\n  )\n  // which way the panels slide: forward when moving right along the tabs\n  const [direction, setDirection] = React.useState(1)\n  const [panelHeight, setPanelHeight] = React.useState<number>()\n  const panelRef = React.useRef<HTMLDivElement>(null)\n  const tabRefs = React.useRef(new Map<string, HTMLButtonElement>())\n  const active = value ?? internal\n  const current = tabs.find((tab) => tab.value === active)\n  const hasPanels = tabs.some((tab) => tab.content !== undefined)\n\n  // the panel area follows the height of whichever panel is showing\n  React.useEffect(() => {\n    const node = panelRef.current\n    if (!node) return\n    const observer = new ResizeObserver(([entry]) => {\n      setPanelHeight(entry.borderBoxSize[0].blockSize)\n    })\n    observer.observe(node)\n    return () => observer.disconnect()\n  }, [])\n\n  function select(next: string) {\n    if (next === active) return\n    const index = (v?: string) => tabs.findIndex((tab) => tab.value === v)\n    setDirection(index(next) > index(active) ? 1 : -1)\n    if (value === undefined) setInternal(next)\n    onValueChange?.(next)\n  }\n\n  function handleKeyDown(event: React.KeyboardEvent, from: string) {\n    const enabled = tabs.filter((tab) => !tab.disabled)\n    const index = enabled.findIndex((tab) => tab.value === from)\n    const target = {\n      ArrowRight: enabled[(index + 1) % enabled.length],\n      ArrowLeft: enabled[(index - 1 + enabled.length) % enabled.length],\n      Home: enabled[0],\n      End: enabled[enabled.length - 1],\n    }[event.key]\n    if (!target) return\n    event.preventDefault()\n    select(target.value)\n    tabRefs.current.get(target.value)?.focus()\n  }\n\n  const list = (\n    <div\n      role=\"tablist\"\n      aria-orientation=\"horizontal\"\n      className={cn(\n        \"relative isolate inline-flex items-center gap-1 rounded-full border border-foreground/[0.08] bg-foreground/[0.06] p-[3px]\",\n        hasPanels ? listClassName : cn(listClassName, className)\n      )}\n      {...(hasPanels ? {} : { \"data-slot\": \"trail-tabs\", ...props })}\n    >\n      {tabs.map((tab) => {\n        const selected = tab.value === active\n        return (\n          <button\n            key={tab.value}\n            ref={(node) => {\n              if (node) tabRefs.current.set(tab.value, node)\n              else tabRefs.current.delete(tab.value)\n            }}\n            id={`${id}-tab-${tab.value}`}\n            type=\"button\"\n            role=\"tab\"\n            aria-selected={selected}\n            aria-controls={tab.content !== undefined ? `${id}-panel` : undefined}\n            tabIndex={selected ? 0 : -1}\n            disabled={tab.disabled}\n            data-state={selected ? \"active\" : \"inactive\"}\n            className=\"relative inline-flex h-9 min-w-9 cursor-pointer items-center justify-center rounded-full px-2.5 text-sm font-medium text-foreground/60 outline-none transition-[color,scale] duration-150 ease-out hover:text-foreground motion-safe:active:scale-[0.97] motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-40 aria-selected:text-foreground [&_svg]:size-4 [&_svg]:shrink-0\"\n            onClick={() => select(tab.value)}\n            onKeyDown={(event) => handleKeyDown(event, tab.value)}\n          >\n            {selected && (\n              <motion.span\n                layoutId={`${id}-indicator`}\n                aria-hidden\n                className=\"absolute inset-0 rounded-[inherit] border border-foreground/[0.08] bg-background/75 shadow-[0_1px_2px_oklch(0_0_0/0.08)] dark:bg-foreground/[0.14]\"\n                transition={\n                  reduceMotion ? { duration: 0 } : { type: \"spring\", visualDuration: 0.3, bounce: 0 }\n                }\n              />\n            )}\n\n            {/* labels sit above every tab's pill, so the sliding pill passes under them */}\n            {tab.icon && (\n              <motion.span\n                aria-hidden\n                className={cn(\n                  \"relative z-10 grid place-items-center transition-colors duration-150\",\n                  tab.iconGesture === \"ring\" && \"origin-top\",\n                  selected && \"text-glow\"\n                )}\n                initial={false}\n                // the same target either way, so server and client agree; reduced motion only skips the timing\n                animate={selected ? iconGestures[tab.iconGesture ?? \"pop\"] : iconRest}\n                transition={reduceMotion ? { duration: 0 } : { duration: 0.5, ease: [0.2, 0.8, 0.2, 1] }}\n              >\n                {tab.icon}\n              </motion.span>\n            )}\n            {/* only the picked tab shows its name; the others fold down to their icon */}\n            <motion.span\n              className=\"relative z-10 overflow-hidden whitespace-nowrap\"\n              initial={false}\n              animate={\n                selected || labels === \"all\" || !tab.icon\n                  ? { width: \"auto\", opacity: 1 }\n                  : { width: 0, opacity: 0 }\n              }\n              transition={reduceMotion ? { duration: 0 } : { type: \"spring\", visualDuration: 0.32, bounce: 0 }}\n            >\n              <span className={cn(\"block pr-1\", tab.icon && \"pl-1.5\")}>{tab.label}</span>\n            </motion.span>\n          </button>\n        )\n      })}\n    </div>\n  )\n\n  if (!hasPanels) return list\n\n  return (\n    <div data-slot=\"trail-tabs\" className={cn(\"flex flex-col gap-4\", className)} {...props}>\n      {list}\n      {/* the height glides between panels; the padding keeps focus rings and shadows unclipped */}\n      <motion.div\n        className=\"-m-1 overflow-hidden\"\n        initial={false}\n        animate={{ height: panelHeight ?? \"auto\" }}\n        transition={reduceMotion ? { duration: 0 } : { type: \"spring\", ...springs.soft }}\n      >\n        <div ref={panelRef} className=\"relative p-1\">\n          {/* the new panel slides in from the side you moved toward; the old one leaves fast */}\n          <AnimatePresence mode=\"popLayout\" initial={false} custom={direction}>\n            <motion.div\n              key={active}\n              id={`${id}-panel`}\n              role=\"tabpanel\"\n              aria-labelledby={`${id}-tab-${active}`}\n              tabIndex={0}\n              className=\"outline-none\"\n              custom={direction}\n              variants={{\n                enter: (dir: number) => ({ opacity: 0, x: reduceMotion ? 0 : dir * 8, filter: \"blur(2px)\" }),\n                center: { opacity: 1, x: 0, filter: \"blur(0px)\" },\n                exit: (dir: number) => ({\n                  opacity: 0,\n                  x: reduceMotion ? 0 : dir * -8,\n                  filter: \"blur(2px)\",\n                  transition: { duration: 0.1, ease: \"easeOut\" },\n                }),\n              }}\n              initial=\"enter\"\n              animate=\"center\"\n              exit=\"exit\"\n              transition={{ type: \"spring\", visualDuration: 0.3, bounce: 0 }}\n            >\n              {current?.content}\n            </motion.div>\n          </AnimatePresence>\n        </div>\n      </motion.div>\n    </div>\n  )\n}\n\nexport { TrailTabs, type TrailTab, type TrailTabsProps }\n",
      "type": "registry:ui"
    },
    {
      "path": "lib/afterglow.ts",
      "content": "import type { CSSProperties } from \"react\"\nimport type { TargetAndTransition, Transition } from \"motion/react\"\n\n// shared spring presets, every component picks from these\nexport const springs = {\n  snappy: { stiffness: 520, damping: 34, mass: 0.6 },\n  soft: { stiffness: 260, damping: 26, mass: 0.8 },\n  glide: { stiffness: 120, damping: 20, mass: 1 },\n} as const\n\nexport type SpringName = keyof typeof springs\n\nexport function spring(name: SpringName): Transition {\n  return { type: \"spring\", ...springs[name] }\n}\n\n// how a glow fades once its source moves away: slow, with a long tail\nexport const afterglow = {\n  linger: 0.9,\n  ease: [0.22, 1, 0.36, 1],\n} as const satisfies { linger: number; ease: Transition[\"ease\"] }\n\n// paints only the padding ring of an element, used for glowing borders\nexport const ringMask: CSSProperties = {\n  WebkitMask:\n    \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  WebkitMaskComposite: \"xor\",\n  mask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  maskComposite: \"exclude\",\n}\n\n// small icon gestures, played when a control is pressed or selected\nexport const iconGestures = {\n  pop: { scale: [1, 1.2, 1] },\n  ring: { rotate: [0, -18, 14, -9, 4, 0], scale: [1, 1.12, 1] },\n  // a gear looks the same after half a turn, so it can rest there and snap back unseen\n  turn: { rotate: [0, 180], scale: [1, 1.12, 1] },\n  hop: { y: [0, -3, 0], scale: [1, 1.1, 1] },\n  nudge: { x: [0, 2.5, 0], scale: [1, 1.1, 1] },\n} satisfies Record<string, TargetAndTransition>\n\nexport type IconGesture = keyof typeof iconGestures\n\n// leaving a gesture is instant: every gesture already ends at, or looks like, its resting pose\nexport const iconRest: TargetAndTransition = { scale: 1, rotate: 0, x: 0, y: 0, transition: { duration: 0 } }\n",
      "type": "registry:lib"
    }
  ],
  "cssVars": {
    "theme": {
      "color-glow": "var(--glow)",
      "color-glow-foreground": "var(--glow-foreground)",
      "color-glow-2": "var(--glow-2)",
      "color-glow-3": "var(--glow-3)",
      "color-glass": "var(--glass)",
      "color-gloss-highlight": "var(--gloss-highlight)",
      "shadow-gloss": "inset 0 1px 0 0 var(--gloss-highlight), inset 0 -1px 0 0 var(--gloss-shade), 0 0 0 1px var(--gloss-edge), 0 1px 2px 0 var(--gloss-depth), 0 4px 12px -4px var(--gloss-depth)",
      "shadow-glass": "inset 0 1px 0 0 var(--gloss-highlight), inset 0 -10px 24px -18px var(--gloss-shade), inset 0 0 0 1px var(--gloss-edge), 0 2px 6px -1px var(--gloss-depth), 0 18px 40px -12px var(--gloss-depth)",
      "shadow-well": "inset 0 1px 3px 0 var(--gloss-depth), inset 0 0 0 1px var(--gloss-edge), 0 1px 0 0 var(--gloss-highlight)"
    },
    "light": {
      "glow": "oklch(0.7 0.19 45)",
      "glow-foreground": "oklch(0.22 0.05 40)",
      "glow-2": "oklch(0.64 0.22 12)",
      "glow-3": "oklch(0.56 0.21 300)",
      "glass": "oklch(1 0 0 / 55%)",
      "gloss-highlight": "oklch(1 0 0 / 95%)",
      "gloss-shade": "oklch(0.3 0.03 285 / 10%)",
      "gloss-depth": "oklch(0.32 0.03 285 / 20%)",
      "gloss-edge": "oklch(0.22 0.02 285 / 10%)",
      "liquid-tint": "oklch(1 0 0 / 18%)",
      "liquid-fallback": "oklch(1 0 0 / 55%)",
      "liquid-rim": "oklch(1 0 0 / 95%)",
      "liquid-edge": "oklch(0.2 0.02 285 / 10%)",
      "liquid-shadow": "oklch(0.22 0.02 285 / 26%)",
      "liquid-glow": "oklch(1 0 0 / 55%)",
      "liquid-shade": "oklch(0.25 0.03 285 / 14%)"
    },
    "dark": {
      "glow": "oklch(0.8 0.16 55)",
      "glow-foreground": "oklch(0.22 0.05 40)",
      "glow-2": "oklch(0.7 0.2 15)",
      "glow-3": "oklch(0.65 0.2 300)",
      "glass": "oklch(0.19 0 0 / 55%)",
      "gloss-highlight": "oklch(1 0 0 / 16%)",
      "gloss-shade": "oklch(0 0 0 / 30%)",
      "gloss-depth": "oklch(0.04 0 0 / 60%)",
      "gloss-edge": "oklch(1 0 0 / 9%)",
      "liquid-tint": "oklch(0.2 0 0 / 22%)",
      "liquid-fallback": "oklch(0.2 0 0 / 45%)",
      "liquid-rim": "oklch(1 0 0 / 60%)",
      "liquid-edge": "oklch(1 0 0 / 10%)",
      "liquid-shadow": "oklch(0 0 0 / 50%)",
      "liquid-glow": "oklch(1 0 0 / 24%)",
      "liquid-shade": "oklch(0 0 0 / 28%)"
    }
  },
  "type": "registry:ui"
}