{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tabs",
  "title": "Tabs",
  "description": "Tabbed views with pill, underline and segment list styles and a travelling indicator, built on Radix.",
  "dependencies": [
    "class-variance-authority@^0.7.1",
    "radix-ui@^1.6.7"
  ],
  "registryDependencies": [
    "@pestoui/style",
    "@pestoui/utils"
  ],
  "files": [
    {
      "path": "pestoui/ui/tabs.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { Tabs as TabsPrimitive } from \"radix-ui\"\n\nimport { cn } from \"@/lib/utils\"\n\nfunction Tabs({\n  className,\n  orientation = \"horizontal\",\n  ...props\n}: React.ComponentProps<typeof TabsPrimitive.Root>) {\n  return (\n    <TabsPrimitive.Root\n      data-slot=\"tabs\"\n      data-orientation={orientation}\n      className={cn(\n        \"group/tabs flex gap-2 data-horizontal:flex-col\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\n/* Three shapes for the same machinery. `pill` is the original — a filled track\n   with a fully-round indicator. `underline` drops the track so the triggers sit\n   on the page and the indicator becomes a bar on the active trigger's edge.\n   `segment` keeps the fill, squares it back to the surface radius and tightens\n   the inset, so it reads as a segmented control. */\nconst tabsListVariants = cva(\n  \"group/tabs-list relative inline-flex w-fit items-center justify-center text-muted-foreground group-data-horizontal/tabs:h-11 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col\",\n  {\n    variants: {\n      variant: {\n        pill: \"rounded-full bg-secondary p-1\",\n        underline: \"gap-1 bg-transparent p-0\",\n        segment: \"rounded-lg bg-secondary p-0.5\",\n      },\n    },\n    defaultVariants: {\n      variant: \"pill\",\n    },\n  }\n)\n\n/* Reads the --indicator-* custom properties TabsList measures onto itself, so\n   the measurement stays one generic border-box for every variant.\n\n   The two filled variants consume all four values. The underline consumes three\n   and substitutes a fixed bar thickness for the fourth: it takes the measured\n   height only to find the trigger's far edge, then backs its own thickness off\n   that edge — half a spacing step, the same quantity the thickness utility\n   resolves to — so width and x travel while the bar never changes thickness.\n   Vertical lists mirror the pair: the bar takes the trailing edge, height\n   travels, and the thickness moves onto the other axis.\n   Both orientations are written out rather than overridden, because the\n   orientation variants resolve inside :where() and would otherwise tie with an\n   unscoped utility on specificity. */\nconst tabsIndicatorVariants = cva(\n  \"pointer-events-none absolute top-0 left-0 z-0 opacity-[var(--indicator-o,0)]\",\n  {\n    variants: {\n      variant: {\n        pill: \"h-[var(--indicator-h,0px)] w-[var(--indicator-w,0px)] translate-x-[var(--indicator-x,0px)] translate-y-[var(--indicator-y,0px)] rounded-full bg-card shadow-xs dark:border dark:border-input dark:bg-input/30\",\n        underline:\n          \"rounded-full bg-selected group-data-horizontal/tabs:h-0.5 group-data-horizontal/tabs:w-[var(--indicator-w,0px)] group-data-horizontal/tabs:translate-x-[var(--indicator-x,0px)] group-data-horizontal/tabs:translate-y-[calc(var(--indicator-y,0px)+var(--indicator-h,0px)-var(--spacing)*0.5)] group-data-vertical/tabs:h-[var(--indicator-h,0px)] group-data-vertical/tabs:w-0.5 group-data-vertical/tabs:translate-x-[calc(var(--indicator-x,0px)+var(--indicator-w,0px)-var(--spacing)*0.5)] group-data-vertical/tabs:translate-y-[var(--indicator-y,0px)]\",\n        segment:\n          \"h-[var(--indicator-h,0px)] w-[var(--indicator-w,0px)] translate-x-[var(--indicator-x,0px)] translate-y-[var(--indicator-y,0px)] rounded-md bg-card shadow-xs dark:border dark:border-input dark:bg-input/30\",\n      },\n    },\n    defaultVariants: {\n      variant: \"pill\",\n    },\n  }\n)\n\nconst TRAVEL_PROPERTIES = [\n  \"--travel-dx\",\n  \"--travel-dy\",\n  \"--travel-dir-x\",\n  \"--travel-dir-y\",\n  \"--travel-squash-x\",\n  \"--travel-squash-y\",\n] as const\n\n/* The inputs `travel-slide` asks for, for a journey from wherever the indicator\n   visibly is to the rest it is about to be given. The keyframes read the rest\n   back off the element's own translate, so only the offset has to be handed\n   in — but it has to be measured against the same rest the variant classes\n   will compute: the trigger's corner for the filled variants, and for the\n   underline the bar's own thickness backed off the far edge. That thickness\n   is read off the bar rather than restated, so it follows the class.\n\n   The squash takes a fixed 4px along the axis of travel and leaves the cross\n   axis alone, per the keyframes' note: the Switch's 0.9 is 2.2px off a knob\n   but 9px off a 90px pill. Direction is set on the travel axis only; a wrapped\n   row may also move the other way, and that part simply glides. */\nfunction measureTravel(\n  indicator: HTMLElement,\n  list: HTMLElement,\n  variant: TabsListVariant,\n  x: number,\n  y: number,\n  w: number,\n  h: number\n): Record<(typeof TRAVEL_PROPERTIES)[number], string> {\n  /* The orientation the classes key off — Tabs' own data-orientation — not\n     the list's aria-orientation, which Radix derives from a prop Tabs does\n     not forward and so reads \"horizontal\" in a vertical list. */\n  const vertical =\n    (list.closest('[data-slot=\"tabs\"]')?.getAttribute(\"data-orientation\") ??\n      list.getAttribute(\"aria-orientation\")) === \"vertical\"\n  const underline = variant === \"underline\"\n  const [fromX = 0, fromY = 0] = getComputedStyle(indicator)\n    .translate.split(\" \")\n    .map((part) => parseFloat(part) || 0)\n  const restX = underline && vertical ? x + w - indicator.offsetWidth : x\n  const restY = underline && !vertical ? y + h - indicator.offsetHeight : y\n  const dx = fromX - restX\n  const dy = fromY - restY\n  const squash = (size: number) => (size > 8 ? `${1 - 4 / size}` : \"1\")\n  return {\n    \"--travel-dx\": `${dx}px`,\n    \"--travel-dy\": `${dy}px`,\n    \"--travel-dir-x\": vertical ? \"0\" : `${Math.sign(-dx)}`,\n    \"--travel-dir-y\": vertical ? `${Math.sign(-dy)}` : \"0\",\n    \"--travel-squash-x\": vertical ? \"1\" : squash(w),\n    \"--travel-squash-y\": vertical ? squash(h) : \"1\",\n  }\n}\n\n/* Drops the travel flag and its inputs once the keyframes stop. Bound to\n   `animationcancel` as well as `animationend`: an indicator hidden mid-flight\n   without unmounting (a `display:none` ancestor, a force-mounted panel) gets\n   no end event, and a flag left set would replay the journey the next time it\n   is shown. React has no animation-cancel prop, so both are native listeners. */\nfunction settleTravel(event: AnimationEvent) {\n  const indicator = event.currentTarget\n  if (event.target !== indicator || !(indicator instanceof HTMLElement)) return\n  indicator.removeAttribute(\"data-travelling\")\n  for (const name of TRAVEL_PROPERTIES) {\n    indicator.style.removeProperty(name)\n  }\n}\n\ntype TabsListVariant = VariantProps<typeof tabsListVariants>[\"variant\"]\n\nfunction TabsList({\n  className,\n  variant = \"pill\",\n  children,\n  ...props\n}: React.ComponentProps<typeof TabsPrimitive.List> &\n  VariantProps<typeof tabsListVariants>) {\n  const listRef = React.useRef<HTMLDivElement>(null)\n  const indicatorRef = React.useRef<HTMLSpanElement>(null)\n  /* Gates the travel transition until the indicator has been placed once, so it\n     settles onto the active tab on mount instead of gliding in from the edge. */\n  const [measured, setMeasured] = React.useState(false)\n\n  React.useLayoutEffect(() => {\n    const list = listRef.current\n    if (!list) return\n\n    let placed = false\n    /* The trigger the indicator last sat under. Travel is armed only when this\n       changes: a reflow re-places the indicator under the same trigger, and a\n       resized container bouncing every tab bar on the page would be noise. */\n    let settledOn: HTMLElement | null = null\n    const place = () => {\n      /* A hidden list — display:none on it or an ancestor — has no boxes:\n         every rect reads zero, and writing those parks the indicator in the\n         corner, to glide back out when the list is shown again. Leave the\n         last placement standing; the ResizeObserver calls place() again when\n         the list reappears. */\n      if (!list.getClientRects().length) return\n      const active = list.querySelector<HTMLElement>(\n        '[data-slot=\"tabs-trigger\"][data-state=\"active\"]'\n      )\n      /* No tabs, or the active one unmounted — hide rather than strand the\n         indicator on a position that no longer means anything. */\n      if (!active) {\n        list.style.setProperty(\"--indicator-o\", \"0\")\n        settledOn = null\n        return\n      }\n      const l = list.getBoundingClientRect()\n      const a = active.getBoundingClientRect()\n      /* Rects are border boxes; an absolute child is placed against the padding\n         box. Identical while the list is borderless, not if one is added. */\n      const cs = getComputedStyle(list)\n      const bx = parseFloat(cs.borderLeftWidth) || 0\n      const by = parseFloat(cs.borderTopWidth) || 0\n      const x = a.left - l.left - bx\n      const y = a.top - l.top - by\n\n      /* Measured before the new position is written: the origin is wherever\n         the indicator visibly is now, which mid-flight is not its old rest. */\n      const indicator = indicatorRef.current\n      const travel =\n        placed && indicator && settledOn && settledOn !== active\n          ? measureTravel(indicator, list, variant, x, y, a.width, a.height)\n          : null\n      settledOn = active\n\n      list.style.setProperty(\"--indicator-x\", `${x}px`)\n      list.style.setProperty(\"--indicator-y\", `${y}px`)\n      list.style.setProperty(\"--indicator-w\", `${a.width}px`)\n      list.style.setProperty(\"--indicator-h\", `${a.height}px`)\n      list.style.setProperty(\"--indicator-o\", \"1\")\n\n      /* Armed in the same tick as the new position, imperatively rather than\n         through state: a render in between would paint a frame of the\n         indicator parked on its destination before the keyframes pulled it\n         back to where it came from. */\n      if (indicator && travel) {\n        for (const [name, value] of Object.entries(travel)) {\n          indicator.style.setProperty(name, value)\n        }\n        if (indicator.hasAttribute(\"data-travelling\")) {\n          /* Re-targeted mid-flight. The running keyframes have already picked\n             up the new endpoints and would carry on from their current\n             progress, which teleports the indicator; rewinding replays the\n             new journey from where it visibly is, as the Switch does. */\n          for (const animation of indicator.getAnimations()) {\n            if (\"animationName\" in animation) animation.currentTime = 0\n          }\n        } else {\n          indicator.setAttribute(\"data-travelling\", \"\")\n        }\n      }\n\n      if (!placed) {\n        placed = true\n        /* Flush the first placement while the transition is still off — the\n           class arrives next render with nothing left to animate away from. */\n        void list.offsetWidth\n        setMeasured(true)\n      }\n    }\n\n    place()\n    /* Radix flips data-state on the triggers when the value changes; childList\n       catches tabs added or removed after mount. */\n    const mo = new MutationObserver(place)\n    mo.observe(list, {\n      subtree: true,\n      childList: true,\n      attributes: true,\n      attributeFilter: [\"data-state\"],\n    })\n    /* Reflow — wrapping, a font swap, a resized container — moves the target. */\n    const ro = new ResizeObserver(place)\n    ro.observe(list)\n    const indicator = indicatorRef.current\n    indicator?.addEventListener(\"animationend\", settleTravel)\n    indicator?.addEventListener(\"animationcancel\", settleTravel)\n    return () => {\n      mo.disconnect()\n      ro.disconnect()\n      indicator?.removeEventListener(\"animationend\", settleTravel)\n      indicator?.removeEventListener(\"animationcancel\", settleTravel)\n    }\n    /* Swapping variant re-pads the list, so the trigger boxes move under it. */\n  }, [variant])\n\n  return (\n    <TabsPrimitive.List\n      ref={listRef}\n      data-slot=\"tabs-list\"\n      data-variant={variant}\n      className={cn(tabsListVariants({ variant }), className)}\n      {...props}\n    >\n      <span\n        ref={indicatorRef}\n        data-slot=\"tabs-indicator\"\n        aria-hidden=\"true\"\n        className={cn(\n          tabsIndicatorVariants({ variant }),\n          /* The one travelling indicator in the system that should settle with\n             a little life rather than snap: it moves between two known tabs,\n             so the overshoot reads as momentum, not imprecision.\n\n             A change the user makes runs the Switch's travel instead —\n             `travel-slide` on `translate`, its squish on `scale` — armed by\n             place() above and dropped by settleTravel, so nothing bounces on\n             mount and a reflow never does. The transition stays for what the\n             flag cannot see: resizes, a width that changes between tabs, and\n             a controlled value set from elsewhere. `translate` comes off the\n             list while travelling: the position write that arms the keyframes\n             would otherwise be a transition trigger too, and transitions sit\n             above animations in the cascade. Chrome declines to start one on\n             a property a CSS animation holds; the class makes that explicit\n             rather than leaving it to the engine. */\n          measured &&\n            \"transition-[translate,width,height] duration-spring-overshoot ease-spring-overshoot data-travelling:animate-travel-slide data-travelling:transition-[width,height]\"\n        )}\n      />\n      {children}\n    </TabsPrimitive.List>\n  )\n}\n\nfunction TabsTrigger({\n  className,\n  children,\n  ...props\n}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {\n  return (\n    <TabsPrimitive.Trigger\n      data-slot=\"tabs-trigger\"\n      className={cn(\n        \"relative z-10 inline-flex h-full flex-1 items-center justify-center gap-1.5 rounded-full border border-transparent px-5 py-0.5 text-body font-medium whitespace-nowrap text-foreground/70 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\",\n        /* Active label on the filled variants: it sits on a raised surface, so\n           it takes full-strength ink. */\n        \"data-active:text-foreground dark:data-active:text-foreground\",\n        /* Follow the container's corner, so the focus ring traces the same\n           shape the indicator does. */\n        \"group-data-[variant=segment]/tabs-list:rounded-md\",\n        /* Squeeze under the finger, on the press spring. Squeeze only: Tabs\n           activates on pointerdown, so by the time the press registers the\n           indicator is already on its way and a lean would point back the way\n           it came.\n           The trigger's contents squeeze, never the trigger: triggers are\n           flex-1, so a full-width tab is a full-width row, and --press-scale\n           on it would shrink the box and its focus ring inside an indicator\n           that does not shrink. CSS cannot scale a bare text node, so text\n           children are wrapped in a span below — a flex item either way, so\n           nothing moves at rest. The timing sits in :where() so a child that\n           brings its own transition keeps it. */\n        \"[:where(&)>*]:[transition:scale_var(--duration-spring-press)_var(--ease-spring-press)] active:[&>*]:scale-(--press-squeeze)\",\n        /* Underline has no surface under the label — the bar and the label carry\n           the selection together: the bar in --selected, the label in\n           --selected-ink, the same hue darkened until it clears 4.5:1 as text. */\n        \"group-data-[variant=underline]/tabs-list:data-active:text-selected-ink dark:group-data-[variant=underline]/tabs-list:data-active:text-selected-ink\",\n        className\n      )}\n      {...props}\n    >\n      {/* asChild hands its one element to Slot untouched. */}\n      {props.asChild ? children : React.Children.map(children, labelElement)}\n    </TabsPrimitive.Trigger>\n  )\n}\n\n/* Text gets an element to squeeze; everything else passes through. Bare\n   whitespace stays bare — flex layout drops it, and a span around it would\n   take a gap slot. */\nfunction labelElement(child: React.ReactNode) {\n  if (typeof child === \"number\" || (typeof child === \"string\" && child.trim())) {\n    return <span>{child}</span>\n  }\n  return child\n}\n\nfunction TabsContent({\n  className,\n  ...props\n}: React.ComponentProps<typeof TabsPrimitive.Content>) {\n  return (\n    <TabsPrimitive.Content\n      data-slot=\"tabs-content\"\n      className={cn(\n        \"flex-1 text-sm outline-none\",\n        /* Inactive panels stay mounted and hidden, so there is only ever an\n           enter to write — a short rise that lands as the indicator arrives. */\n        \"data-active:animate-in data-active:fade-in-0 data-active:slide-in-from-bottom-[4px] data-active:anim-base data-active:ease-out-expo\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nexport { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}