{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "retro-toggle-group",
  "title": "RetroToggleGroup",
  "description": "A Mac OS 9 styled toggle group with shared borders, raised/pressed bevel states, and single or multiple selection modes, built on UI SDK Toggle Group.",
  "dependencies": [
    "@ui-sdk/core@0.1.0-beta.1",
    "@ui-sdk/react@0.1.0-beta.1",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "https://nostalgia-ui.com/r/nostalgia-theme.json"
  ],
  "files": [
    {
      "path": "registry/new-york/ui/retro-toggle-group.tsx",
      "content": "\"use client\"\n\n/*\n * RetroToggleGroup: a row of joined OS 9 bevel buttons.\n *\n * Crafted moment: the sliding pressed slab. With type=\"single\" one\n * pushed-in slab slides to the button you chose (180ms, strong ease-out),\n * so the row reads as one control with one state, not separate buttons.\n * The label ink flips in one step as the slab arrives. Classic flair and\n * reduced motion: the slab snaps. With type=\"multiple\" each button pushes\n * in on its own, instantly.\n *\n * Layering: each button paints its raised face on a ::before (z-0), the\n * slab sits above those faces (z-1), labels sit above it (z-2) and the\n * focus ring above everything (z-3), so the slab never hides behind a\n * neighbour while it travels. Until the slab has measured (and on the\n * server) the pressed button paints its own pushed-in face.\n *\n * Built on UI SDK's ToggleGroup: one tab stop, arrow keys between buttons.\n * The Radix-shaped API stays: type=\"single\" takes a string value,\n * type=\"multiple\" a string[].\n */\n\nimport * as React from \"react\"\nimport { Toggle as TogglePrimitive, ToggleGroup as ToggleGroupPrimitive } from \"@ui-sdk/react/toggle\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst retroToggleGroupVariants = cva(\n  [\n    \"group/tgi relative -ml-px first:ml-0 inline-flex items-center justify-center whitespace-nowrap\",\n    \"font-[family-name:var(--os9-font-heading)] text-[12px] tracking-[0.42px] leading-[0.98]\",\n    \"cursor-pointer select-none outline-none text-os9-black\",\n    /* the raised face */\n    \"before:absolute before:inset-0 before:z-0 before:border before:border-os9-black before:bg-os9-gray-300\",\n    \"before:shadow-[inset_1px_1px_0_var(--os9-white),inset_-1px_-1px_0_#808080]\",\n    /* the pushed-in face, painted by the button itself unless the slab is on */\n    \"data-pressed:before:bg-os9-gray-700\",\n    \"data-pressed:before:shadow-[inset_1px_1px_0_#808080,inset_-1px_-1px_0_var(--os9-white)]\",\n    \"group-data-[slab=on]/tg:data-pressed:before:bg-os9-gray-300\",\n    \"group-data-[slab=on]/tg:data-pressed:before:shadow-[inset_1px_1px_0_var(--os9-white),inset_-1px_-1px_0_#808080]\",\n    /* focus ring above everything */\n    \"after:pointer-events-none after:absolute after:inset-0 after:z-[3] focus-visible:after:shadow-[0_0_0_2px_var(--os9-focus)]\",\n    \"data-disabled:opacity-50 data-disabled:pointer-events-none\",\n  ],\n  {\n    variants: {\n      size: {\n        default: \"h-[24px] px-[8px] py-[4px]\",\n        sm: \"h-[20px] px-[6px] py-[2px] text-[10px]\",\n        lg: \"h-[30px] px-[12px] py-[4px] text-[12px]\",\n      },\n    },\n    defaultVariants: {\n      size: \"default\",\n    },\n  }\n)\n\ntype ToggleGroupContextValue = VariantProps<typeof retroToggleGroupVariants>\n\nconst ToggleGroupContext = React.createContext<ToggleGroupContextValue>({\n  size: \"default\",\n})\n\nconst SLAB_TRANSITION = \"transform 180ms cubic-bezier(0.23, 1, 0.32, 1), width 180ms cubic-bezier(0.23, 1, 0.32, 1)\"\n\n/** Keeps the slab under the pressed button; marks the group data-slab=\"on\" once placed. */\nfunction useSlab(enabled: boolean) {\n  return React.useCallback(\n    (root: HTMLDivElement | null) => {\n      if (!root || !enabled) return\n      const slab = root.querySelector<HTMLElement>(\":scope > [data-tg-slab]\")\n      if (!slab) return\n      let shown = false\n\n      const place = () => {\n        const item = Array.from(\n          root.querySelectorAll<HTMLElement>('[data-slot=\"toggle\"][data-pressed]')\n        ).find((el) => el.closest('[data-slot=\"toggle-group\"]') === root)\n        if (!item) {\n          shown = false\n          slab.style.opacity = \"0\"\n          root.setAttribute(\"data-slab\", \"on\")\n          return\n        }\n        /* rects, not offsets: buttons have fractional widths */\n        const box = root.getBoundingClientRect()\n        const r = item.getBoundingClientRect()\n        const left = r.left - box.left - root.clientLeft\n        const top = r.top - box.top - root.clientTop\n        const style = slab.style\n        if (!shown) style.transition = \"none\"\n        style.transform = `translate(${left}px, ${top}px)`\n        style.width = `${r.width}px`\n        style.height = `${r.height}px`\n        style.opacity = \"1\"\n        if (!shown) {\n          void slab.offsetWidth // commit the snap before re-enabling the slide\n          style.transition = SLAB_TRANSITION\n        }\n        shown = true\n        root.setAttribute(\"data-slab\", \"on\")\n      }\n\n      place()\n      const mutations = new MutationObserver(place)\n      mutations.observe(root, { subtree: true, attributes: true, attributeFilter: [\"data-pressed\"] })\n      const resize = new ResizeObserver(place)\n      resize.observe(root)\n      return () => {\n        mutations.disconnect()\n        resize.disconnect()\n        root.removeAttribute(\"data-slab\")\n      }\n    },\n    [enabled]\n  )\n}\n\ntype ToggleGroupPrimitiveProps = React.ComponentProps<typeof ToggleGroupPrimitive<string>>\n\ntype RetroToggleGroupBaseProps = Omit<\n  ToggleGroupPrimitiveProps,\n  \"className\" | \"children\" | \"value\" | \"defaultValue\" | \"onValueChange\" | \"multiple\"\n> &\n  VariantProps<typeof retroToggleGroupVariants> & {\n    className?: string\n    children?: React.ReactNode\n  }\n\ntype RetroToggleGroupProps = RetroToggleGroupBaseProps &\n  (\n    | {\n        type?: \"single\"\n        value?: string\n        defaultValue?: string\n        /** \"\" when the pressed button is released */\n        onValueChange?: (value: string) => void\n      }\n    | {\n        type: \"multiple\"\n        value?: string[]\n        defaultValue?: string[]\n        onValueChange?: (value: string[]) => void\n      }\n  )\n\nconst toList = (v: string | string[] | undefined) =>\n  v === undefined ? undefined : Array.isArray(v) ? v : v ? [v] : []\n\nfunction RetroToggleGroup({\n  className,\n  size,\n  children,\n  type = \"single\",\n  value,\n  defaultValue,\n  onValueChange,\n  ref,\n  ...props\n}: RetroToggleGroupProps) {\n  const single = type !== \"multiple\"\n  const slabRef = useSlab(single)\n  const mergedRef = React.useCallback(\n    (node: HTMLDivElement | null) => {\n      if (typeof ref === \"function\") ref(node)\n      else if (ref) (ref as React.RefObject<HTMLDivElement | null>).current = node\n      return slabRef(node)\n    },\n    [ref, slabRef]\n  )\n\n  return (\n    <ToggleGroupPrimitive\n      ref={mergedRef}\n      multiple={!single}\n      value={toList(value)}\n      defaultValue={toList(defaultValue)}\n      onValueChange={(next) => {\n        if (!onValueChange) return\n        if (single) (onValueChange as (v: string) => void)(next[0] ?? \"\")\n        else (onValueChange as (v: string[]) => void)(next)\n      }}\n      className={cn(\"group/tg relative isolate inline-flex flex-row items-center\", className)}\n      {...props}\n    >\n      {single && (\n        <span\n          aria-hidden\n          data-tg-slab=\"\"\n          className={cn(\n            \"pointer-events-none absolute left-0 top-0 z-[1] opacity-0\",\n            \"border border-os9-black bg-os9-gray-700\",\n            \"shadow-[inset_1px_1px_0_#808080,inset_-1px_-1px_0_var(--os9-white)]\",\n            \"in-data-[flair=classic]:transition-none! motion-reduce:transition-none!\",\n            \"group-data-disabled/tg:opacity-50!\"\n          )}\n        />\n      )}\n      <ToggleGroupContext.Provider value={{ size }}>{children}</ToggleGroupContext.Provider>\n    </ToggleGroupPrimitive>\n  )\n}\n\ntype RetroToggleGroupItemProps = Omit<\n  React.ComponentProps<typeof TogglePrimitive>,\n  \"className\" | \"children\"\n> &\n  VariantProps<typeof retroToggleGroupVariants> & {\n    className?: string\n    children?: React.ReactNode\n  }\n\nfunction RetroToggleGroupItem({ className, size, children, ...props }: RetroToggleGroupItemProps) {\n  const context = React.useContext(ToggleGroupContext)\n  const resolvedSize = size ?? context.size\n\n  return (\n    <TogglePrimitive\n      className={cn(retroToggleGroupVariants({ size: resolvedSize }), className)}\n      {...props}\n    >\n      <span\n        className={cn(\n          \"relative z-[2] flex h-full items-center gap-[6px]\",\n          \"group-data-pressed/tgi:text-os9-white\",\n          /* with the slab, the ink flips as it arrives */\n          \"transition-[color] duration-0 group-data-[slab=on]/tg:delay-90\",\n          \"in-data-[flair=classic]:delay-0! motion-reduce:delay-0!\"\n        )}\n      >\n        {children}\n      </span>\n    </TogglePrimitive>\n  )\n}\n\nexport { RetroToggleGroup, RetroToggleGroupItem, retroToggleGroupVariants }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}