{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "icon-tabs",
  "title": "Icon Tabs",
  "description": "A segmented tab selector where only the active tab shows its icon, sliding in beside the label. Built on the Base UI Tabs.",
  "dependencies": [
    "@base-ui/react",
    "cn"
  ],
  "files": [
    {
      "path": "registry/notra/icon-tabs/components/icon-tabs.tsx",
      "content": "\"use client\";\n\nimport { Tabs as TabsPrimitive } from \"@base-ui/react/tabs\";\nimport { cn } from \"cn\";\nimport { useLayoutEffect, useRef } from \"react\";\n\nimport { ICON_TABS_INDICATOR_MS } from \"../constants/icon-tabs\";\nimport {\n  applyIndicatorBox,\n  easeOutQuint,\n  measureActiveTab,\n} from \"../lib/icon-tabs\";\nimport type {\n  IconTabsIndicatorBox,\n  IconTabsIndicatorProps,\n  IconTabsListProps,\n  IconTabsSlideInIconProps,\n  IconTabsTriggerProps,\n} from \"../types/icon-tabs\";\n\nfunction IconTabs({\n  className,\n  ...props\n}: Omit<TabsPrimitive.Root.Props, \"orientation\">) {\n  return (\n    <TabsPrimitive.Root\n      className={cn(\"flex flex-col gap-2\", className)}\n      data-slot=\"icon-tabs\"\n      {...props}\n    />\n  );\n}\n\n/**\n * Icon that only shows on the active tab: it widens and fades in beside the\n * label, so inactive tabs stay text-only. `pinned` keeps it visible anyway,\n * e.g. for a live scan spinner.\n */\nfunction SlideInIcon({ children, pinned = false }: IconTabsSlideInIconProps) {\n  return (\n    <span\n      aria-hidden=\"true\"\n      className={cn(\n        \"-me-1.5 flex w-0 shrink-0 items-center justify-center overflow-hidden opacity-0 transition-all duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] group-data-active/tab:me-0 group-data-active/tab:w-4 group-data-active/tab:opacity-100 motion-reduce:transition-none\",\n        pinned && \"me-0 w-4 opacity-100\"\n      )}\n    >\n      <span\n        className={cn(\n          \"flex scale-50 items-center transition-transform duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] group-data-active/tab:scale-100 motion-reduce:transition-none\",\n          pinned && \"scale-100\"\n        )}\n      >\n        {children}\n      </span>\n    </span>\n  );\n}\n\nfunction IconTabsIndicator({ value }: IconTabsIndicatorProps) {\n  const ref = useRef<HTMLSpanElement>(null);\n  const boxRef = useRef<IconTabsIndicatorBox | null>(null);\n\n  useLayoutEffect(() => {\n    const element = ref.current;\n    const list = element?.parentElement;\n    if (!(element && list)) {\n      return;\n    }\n\n    const from = boxRef.current;\n    const animate =\n      from !== null &&\n      !window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const effectStart = performance.now();\n    // The slide counts from its first painted frame, so a long render right\n    // after the click delays it instead of skipping it.\n    let start: number | null = null;\n    let frame = 0;\n\n    const nextFrame = () => {\n      frame = requestAnimationFrame((now) => {\n        start ??= now;\n        tick(now);\n      });\n    };\n\n    const tick = (now: number) => {\n      frame = 0;\n      const target = measureActiveTab(list);\n      if (!target) {\n        if (now - effectStart < ICON_TABS_INDICATOR_MS) {\n          frame = requestAnimationFrame(tick);\n        }\n        return;\n      }\n      const elapsed = start === null ? 0 : Math.max(0, now - start);\n      const progress = animate\n        ? Math.min(1, elapsed / ICON_TABS_INDICATOR_MS)\n        : 1;\n      const eased = easeOutQuint(progress);\n      const box =\n        from && progress < 1\n          ? {\n              left: from.left + (target.left - from.left) * eased,\n              top: target.top,\n              width: from.width + (target.width - from.width) * eased,\n              height: target.height,\n            }\n          : target;\n      boxRef.current = box;\n      applyIndicatorBox(element, box);\n      if (progress < 1) {\n        nextFrame();\n      }\n    };\n    tick(effectStart);\n\n    const observer = new ResizeObserver(() => {\n      if (frame !== 0) {\n        return;\n      }\n      const target = measureActiveTab(list);\n      if (target) {\n        boxRef.current = target;\n        applyIndicatorBox(element, target);\n      }\n    });\n    observer.observe(list);\n\n    return () => {\n      cancelAnimationFrame(frame);\n      observer.disconnect();\n    };\n  }, [value]);\n\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"bg-background dark:bg-foreground/10 pointer-events-none absolute top-0 left-0 z-0 rounded-md shadow-[0_1px_2px_rgba(0,0,0,0.08)]\"\n      ref={ref}\n    />\n  );\n}\n\nfunction IconTabsList({\n  className,\n  value,\n  children,\n  ...props\n}: IconTabsListProps) {\n  return (\n    <TabsPrimitive.List\n      className={cn(\n        \"bg-muted text-muted-foreground relative z-0 inline-flex h-8 w-fit items-center justify-center gap-0.5 rounded-lg p-0.5\",\n        className\n      )}\n      data-slot=\"icon-tabs-list\"\n      {...props}\n    >\n      <IconTabsIndicator value={value} />\n      {children}\n    </TabsPrimitive.List>\n  );\n}\n\nfunction IconTabsTrigger({\n  className,\n  icon,\n  iconPinned,\n  children,\n  ...props\n}: IconTabsTriggerProps) {\n  return (\n    <TabsPrimitive.Tab\n      className={cn(\n        \"group/tab text-muted-foreground/75 hover:text-muted-foreground data-active:text-foreground focus-visible:outline-ring relative z-1 inline-flex h-full flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-md px-2.5 text-sm font-medium whitespace-nowrap outline-2 outline-transparent transition-colors duration-200 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0\",\n        className\n      )}\n      data-slot=\"icon-tabs-trigger\"\n      {...props}\n    >\n      <SlideInIcon pinned={iconPinned}>{icon}</SlideInIcon>\n      {children}\n    </TabsPrimitive.Tab>\n  );\n}\n\nfunction IconTabsContent({ className, ...props }: TabsPrimitive.Panel.Props) {\n  return (\n    <TabsPrimitive.Panel\n      className={cn(\"flex-1 text-sm\", className)}\n      data-slot=\"icon-tabs-content\"\n      tabIndex={-1}\n      {...props}\n    />\n  );\n}\n\nexport { IconTabs, IconTabsContent, IconTabsList, IconTabsTrigger };\n",
      "type": "registry:component",
      "target": "components/icon-tabs/components/icon-tabs.tsx"
    },
    {
      "path": "registry/notra/icon-tabs/constants/icon-tabs.ts",
      "content": "export const ICON_TABS_INDICATOR_MS = 300;\n",
      "type": "registry:lib",
      "target": "components/icon-tabs/constants/icon-tabs.ts"
    },
    {
      "path": "registry/notra/icon-tabs/lib/icon-tabs.ts",
      "content": "import type { IconTabsIndicatorBox } from \"../types/icon-tabs\";\n\nexport function easeOutQuint(progress: number): number {\n  return 1 - (1 - progress) ** 5;\n}\n\nexport function measureActiveTab(\n  list: HTMLElement\n): IconTabsIndicatorBox | null {\n  const tab = list.querySelector<HTMLElement>('[role=\"tab\"][data-active]');\n  if (!tab) {\n    return null;\n  }\n  return {\n    left: tab.offsetLeft,\n    top: tab.offsetTop,\n    width: tab.offsetWidth,\n    height: tab.offsetHeight,\n  };\n}\n\nexport function applyIndicatorBox(\n  element: HTMLElement,\n  box: IconTabsIndicatorBox\n) {\n  element.style.transform = `translate(${box.left}px, ${box.top}px)`;\n  element.style.width = `${box.width}px`;\n  element.style.height = `${box.height}px`;\n}\n",
      "type": "registry:lib",
      "target": "components/icon-tabs/lib/icon-tabs.ts"
    },
    {
      "path": "registry/notra/icon-tabs/types/icon-tabs.ts",
      "content": "import type { Tabs as TabsPrimitive } from \"@base-ui/react/tabs\";\nimport type { ReactNode } from \"react\";\n\nexport interface IconTabsIndicatorProps {\n  /** Active tab value; a change starts the slide. */\n  value: string;\n}\n\nexport interface IconTabsIndicatorBox {\n  left: number;\n  top: number;\n  width: number;\n  height: number;\n}\n\nexport interface IconTabsSlideInIconProps {\n  children: ReactNode;\n  /** Keeps the icon visible on inactive tabs, e.g. for a live spinner. */\n  pinned?: boolean;\n}\n\nexport type IconTabsListProps = Omit<TabsPrimitive.List.Props, \"children\"> & {\n  /** Active tab value. Must match the `value` of the surrounding `IconTabs`. */\n  value: string;\n  children: ReactNode;\n};\n\nexport type IconTabsTriggerProps = TabsPrimitive.Tab.Props & {\n  /** Shown only on the active tab, sliding in beside the label. */\n  icon: ReactNode;\n  /** Keeps the icon visible on inactive tabs, e.g. for a live spinner. */\n  iconPinned?: boolean;\n};\n",
      "type": "registry:lib",
      "target": "components/icon-tabs/types/icon-tabs.ts"
    }
  ],
  "type": "registry:component"
}