{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "switch",
  "type": "registry:ui",
  "title": "Switch",
  "description": "Skeuomorphic toggle switch in two sizes.",
  "dependencies": [
    "react-aria-components@^1.17.0"
  ],
  "registryDependencies": [
    "cx"
  ],
  "files": [
    {
      "path": "components/base/switch/switch.tsx",
      "content": "\"use client\";\n\nimport type { ReactNode, Ref } from \"react\";\nimport { Switch as AriaSwitch } from \"react-aria-components\";\nimport type { SwitchProps as AriaSwitchProps } from \"react-aria-components\";\nimport { cx, sortCx } from \"@/utils/cx\";\n\n/**\n * Figma source: Board UI → \"Toogles\" (node 3856:3807).\n *\n * Two shapes × three sizes, plus off / on:\n *   shape   pill        (Figma \"fully rounded\") — track & thumb rounded-full\n *           rectangle   (Figma \"rectangle\")     — track radius/md-scale, thumb radius/xs-scale\n *   size    sm 28×16 · md 42×24 · lg 56×32   (track w×h; thumb = h − 2·pad)\n *\n * Anatomy (all values 1:1 with Figma):\n *   track   off → bg background/tertiary/default (#ebebeb, no border)\n *           on  → Button/Primary gradient (blue/500 → blue/600) + an inset\n *                 ring + top highlight that scales with size. lg is exactly\n *                 the shared `--shadow-checkbox-selected` token; md/sm scale\n *                 the ring (0.75px / 0.5px) and highlight (1.5px / 1px).\n *   thumb   theme-stable white gradient + contact shadow,\n *           slides by (w − thumb − 2·pad) between states.\n *   chip    small embossed inset in the thumb centre:\n *           off → white→neutral-100 in light mode; in dark mode it matches\n *                 the track so the mark reads like a hole through the thumb;\n *           on  → switch-on-chip-start→end (accent mixes matching Figma's\n *                 raw #2473fe→#0450e2 for blue), accent/600 border.\n *\n * The track visual lives in `SwitchTrack` so `Switch` and `SwitchCard` share it\n * (mirrors how Checkbox / CheckboxCard share `CheckboxGlyph`). Built on\n * react-aria Switch: native toggle semantics, keyboard support, focus-visible\n * ring, optional label via `children`.\n */\n\nexport type SwitchSize = \"sm\" | \"md\" | \"lg\";\nexport type SwitchShape = \"pill\" | \"rectangle\";\n\nexport const switchSizes = sortCx({\n  sm: {\n    track: \"h-4 w-7\",\n    trackRadius: { pill: \"rounded-full\", rectangle: \"rounded-[3px]\" },\n    onShadow: \"shadow-[inset_0_1px_0_0_rgb(255_255_255/0.25),inset_0_0_0_0.5px_var(--color-accent-500)]\",\n    thumb: \"size-3\",\n    thumbRadius: { pill: \"rounded-full\", rectangle: \"rounded-[1px]\" },\n    offset: \"start-0.5 top-0.5\",\n    travel: \"translate-x-3 rtl:-translate-x-3\",\n    chip: \"size-[5px] border-[0.25px] shadow-[0_2px_2px_0_rgb(0_0_0/0.03)]\",\n    chipRadius: { pill: \"rounded-full\", rectangle: \"rounded-[0.5px]\" },\n  },\n  md: {\n    track: \"h-6 w-[42px]\",\n    trackRadius: { pill: \"rounded-full\", rectangle: \"rounded-[4.5px]\" },\n    onShadow: \"shadow-[inset_0_1.5px_0_0_rgb(255_255_255/0.25),inset_0_0_0_0.75px_var(--color-accent-500)]\",\n    thumb: \"size-[18px]\",\n    thumbRadius: { pill: \"rounded-full\", rectangle: \"rounded-[1.5px]\" },\n    offset: \"start-[3px] top-[3px]\",\n    travel: \"translate-x-[18px] rtl:-translate-x-[18px]\",\n    chip: \"size-[7.5px] border-[0.375px] shadow-[0_3px_3px_0_rgb(0_0_0/0.03)]\",\n    chipRadius: { pill: \"rounded-full\", rectangle: \"rounded-[0.75px]\" },\n  },\n  lg: {\n    track: \"h-8 w-14\",\n    trackRadius: { pill: \"rounded-full\", rectangle: \"rounded-md\" },\n    onShadow: \"shadow-checkbox-selected\",\n    thumb: \"size-6\",\n    thumbRadius: { pill: \"rounded-full\", rectangle: \"rounded-xs\" },\n    offset: \"start-1 top-1\",\n    travel: \"translate-x-6 rtl:-translate-x-6\",\n    chip: \"size-[10px] border-[0.5px] shadow-[0_4px_4px_0_rgb(0_0_0/0.03)]\",\n    chipRadius: { pill: \"rounded-full\", rectangle: \"rounded-[1px]\" },\n  },\n});\n\nexport interface SwitchVisualState {\n  isSelected: boolean;\n  isDisabled: boolean;\n  isFocusVisible: boolean;\n}\n\n/**\n * The track + thumb + chip visual. Pure presentation — the react-aria Switch\n * (in `Switch` or `SwitchCard`) owns the input and passes its render state in.\n */\nexport function SwitchTrack({\n  state,\n  size = \"md\",\n  shape = \"pill\",\n}: {\n  state: SwitchVisualState;\n  size?: SwitchSize;\n  shape?: SwitchShape;\n}) {\n  const s = switchSizes[size];\n\n  return (\n    <span\n      aria-hidden\n      className={cx(\n        \"relative shrink-0 transition-colors duration-200 ease\",\n        s.track,\n        s.trackRadius[shape],\n        state.isSelected\n          ? cx(\"bg-linear-to-b from-accent-500 to-accent-600\", s.onShadow)\n          : \"bg-background-tertiary-default\",\n        state.isDisabled && \"opacity-50\",\n        state.isFocusVisible && \"ring-2 ring-border-focus-ring ring-offset-2\",\n      )}\n    >\n      {/* Thumb */}\n      <span\n        className={cx(\n          \"absolute flex items-center justify-center\",\n          \"bg-linear-to-b from-control-indicator-background from-[43.837%] to-control-indicator-background-subtle\",\n          \"shadow-[0_3px_3px_0_rgb(0_0_0/0.03),0_0.75px_0_0_rgb(0_0_0/0.05)]\",\n          \"transition-transform duration-200 ease\",\n          s.thumb,\n          s.thumbRadius[shape],\n          s.offset,\n          state.isSelected && s.travel,\n        )}\n      >\n        {/* Embossed inner chip. Gradient runs bottom→top (`to-t`) — equivalent\n            to the Figma layer's vertical flip — but WITHOUT a transform, so the\n            chip stays pixel-snapped/centred (no blurry 1px shift at sub-pixel\n            sizes) and its drop shadow points down instead of up. */}\n        <span\n          className={cx(\n            \"border-solid bg-linear-to-t from-[43.837%]\",\n            s.chip,\n            s.chipRadius[shape],\n            state.isSelected\n              ? \"border-accent-600 from-switch-on-chip-start to-switch-on-chip-end\"\n              : \"border-border-button-default/50 from-switch-off-chip-start to-switch-off-chip-end\",\n          )}\n        />\n      </span>\n    </span>\n  );\n}\n\nexport interface SwitchProps extends Omit<AriaSwitchProps, \"children\"> {\n  children?: ReactNode;\n  size?: SwitchSize;\n  shape?: SwitchShape;\n  ref?: Ref<HTMLLabelElement>;\n}\n\nexport function Switch({ className, children, size = \"md\", shape = \"pill\", ref, ...props }: SwitchProps) {\n  return (\n    <AriaSwitch\n      ref={ref}\n      {...props}\n      className={(state) =>\n        cx(\n          \"group inline-flex items-center gap-2 select-none\",\n          state.isDisabled ? \"cursor-not-allowed\" : \"cursor-pointer\",\n          typeof className === \"function\" ? className(state) : className,\n        )\n      }\n    >\n      {(state) => (\n        <>\n          <SwitchTrack state={state} size={size} shape={shape} />\n          {children != null && children !== false && (\n            <span className=\"text-body-medium text-text-primary\">{children}</span>\n          )}\n        </>\n      )}\n    </AriaSwitch>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/base/switch/switch.tsx"
    }
  ],
  "meta": {
    "docsUrl": "https://www.boardui.com/components/switch",
    "example": "import { Switch } from \"@/components/base/switch/switch\";\n\nexport function Example() {\n  return (\n    <div className=\"flex items-center gap-6\">\n      <Switch defaultSelected>Enable notifications</Switch>\n      <Switch shape=\"rectangle\" size=\"sm\" aria-label=\"Compact\" />\n    </div>\n  );\n}",
    "snippets": [
      {
        "label": "states",
        "code": "{/* Controlled */}\n<Switch isSelected={enabled} onChange={setEnabled} />\n\n{/* Disabled */}\n<Switch isDisabled defaultSelected />\n\n{/* With label (react-aria associates it automatically) */}\n<Switch>Auto-sync to cloud</Switch>"
      },
      {
        "label": "card",
        "code": "import { RiNotification4Line, RiMoonLine } from \"@remixicon/react\";\nimport { SwitchCard } from \"@/components/base/switch/switch-card\";\n\nexport function Example() {\n  return (\n    <div className=\"flex max-w-md flex-col gap-4\">\n      <SwitchCard\n        icon={RiNotification4Line}\n        title=\"Push notifications\"\n        description=\"Get notified when something needs your attention.\"\n        defaultSelected\n      />\n      {/* icon is optional - pass the component reference, not <RiMoonLine /> */}\n      <SwitchCard icon={RiMoonLine} title=\"Dark mode\" />\n    </div>\n  );\n}"
      }
    ]
  }
}
