{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "switch",
  "title": "Switch",
  "description": "Binary setting: a two-cell frame whose block stretches to the on side.",
  "dependencies": [
    "@base-ui/react@1.9.0"
  ],
  "registryDependencies": [
    "@keyline-ui/keyline",
    "utils",
    "@keyline-ui/checkbox",
    "@keyline-ui/keyline-render"
  ],
  "files": [
    {
      "path": "src/registry/keyline/ui/switch.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Switch as SwitchPrimitive } from \"@base-ui/react/switch\";\nimport { Field } from \"@base-ui/react/field\";\n\nimport { cn } from \"@/lib/utils\";\nimport { resolveClassName } from \"../lib/keyline-render\";\nimport { choiceStyles } from \"./checkbox\";\n\n/*\n * Switch, as Base UI's parts (Switch, also exported as SwitchRoot, and SwitchThumb), and SwitchField, a labelled row\n * built from them. A switch reads on/off from three cues, none of them colour alone:\n *   1. position: the thumb sits in the start half (off) or the end half (on);\n *   2. form: off is a hollow thumb, on is a solid one;\n *   3. glyph: on shows the IEC \"on\" bar in the half the thumb left (drawn with a border-free block so it survives\n *      forced colours). Off shows nothing there.\n * The thumb is inset 2px from the frame, so it reads as an object, never as half of a divided box.\n */\n\nconst root = cn(\n  \"group/switch relative m-0 box-content inline-block h-(--kl-sw) w-[calc(var(--kl-sw)*2)] flex-none cursor-pointer p-0\",\n  \"border-(length:--kl-k2) border-kl-line bg-kl-cell text-kl-ink [--kl-sw-gap:2px] [--kl-sw:22px]\",\n  \"[[data-kl-density=compact]_&]:[--kl-sw:16px]\",\n  \"hover:not-data-disabled:bg-kl-tint\",\n  // the foundation's ring keys on a kl- class, and the switch has none: it draws its own\n  \"focus-visible:outline-(length:--kl-ring) focus-visible:outline-offset-(--kl-ring-out) focus-visible:outline-kl-focus focus-visible:outline-solid\",\n  // the \"on\" bar, centred in the start half; it appears once the thumb has left (same delay as the thumb's fill)\n  \"after:absolute after:start-[calc(25%-1px)] after:top-[calc(50%-var(--kl-sw)*0.25)] after:h-[calc(var(--kl-sw)*0.5)]\",\n  \"after:w-0.5 after:bg-current after:opacity-0 after:content-[''] after:[transition:opacity_0s_linear_0s]\",\n  \"data-checked:after:opacity-100 data-checked:after:[transition-delay:calc(var(--kl-stretch-trail)*0.6ms)]\",\n  \"data-disabled:cursor-not-allowed data-disabled:border-kl-dis-line data-disabled:bg-(image:--kl-hatch) data-disabled:text-kl-dis\",\n  \"forced-colors:after:bg-[CanvasText] forced-colors:after:forced-color-adjust-none\",\n  \"forced-colors:data-disabled:after:bg-[GrayText]\",\n);\n\n/**\n * The binary setting. The thumb STRETCHES between the two halves of the frame (the edge on the travel side leads, the\n * other follows: CSS transitions on the stretch springs' timings). Semantics, keyboard, form value and\n * controlled/uncontrolled state are Base UI Switch's; `onCheckedChange` gets Base UI's event details last. Without\n * children it draws its SwitchThumb.\n */\nfunction Switch({ className, children, ...props }: SwitchPrimitive.Root.Props): React.ReactElement {\n  return (\n    <SwitchPrimitive.Root className={resolveClassName(root, className)} {...props} data-slot=\"switch\">\n      {children ?? <SwitchThumb />}\n    </SwitchPrimitive.Root>\n  );\n}\n\n/** Switch, by Base UI's name for the part. */\nconst SwitchRoot = Switch;\n\nconst thumb = cn(\n  \"absolute inset-y-(--kl-sw-gap) start-(--kl-sw-gap) end-[calc(50%+var(--kl-sw-gap)/2)] box-border\",\n  \"border-2 border-kl-inverse bg-transparent\",\n  // turning on: the end edge leads, the start edge trails; turning off is the mirror\n  \"[transition:inset-inline-start_calc(var(--kl-stretch-trail)*1ms)_var(--kl-ease-out),inset-inline-end_calc(var(--kl-stretch-lead)*1ms)_var(--kl-ease-out),background-color_0s_linear_calc(var(--kl-stretch-lead)*0.35ms)]\",\n  \"data-checked:start-[calc(50%+var(--kl-sw-gap)/2)] data-checked:end-(--kl-sw-gap) data-checked:bg-kl-inverse\",\n  \"data-checked:[transition:inset-inline-start_calc(var(--kl-stretch-lead)*1ms)_var(--kl-ease-out),inset-inline-end_calc(var(--kl-stretch-trail)*1ms)_var(--kl-ease-out),background-color_0s_linear_calc(var(--kl-stretch-lead)*0.35ms)]\",\n  // KEY: pressing moves the contents 1px, the frame stays\n  \"group-active/switch:not-data-disabled:translate-y-px\",\n  \"data-disabled:border-kl-dis data-disabled:data-checked:bg-kl-dis\",\n  \"forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:forced-color-adjust-none\",\n  \"forced-colors:data-checked:border-[Highlight] forced-colors:data-checked:bg-[Highlight]\",\n  \"forced-colors:data-disabled:border-[GrayText] forced-colors:data-disabled:data-checked:border-[GrayText]\",\n  \"forced-colors:data-disabled:data-checked:bg-[GrayText]\",\n);\n\n/** The thumb: hollow while off, solid while on. */\nfunction SwitchThumb({ className, ...props }: SwitchPrimitive.Thumb.Props): React.ReactElement {\n  return <SwitchPrimitive.Thumb className={resolveClassName(thumb, className)} {...props} data-slot=\"switch-thumb\" />;\n}\n\n/**\n * Label + description + switch on one row; the row is the hit target. `className` goes to the row's Field.Root; every\n * other prop goes to the Switch.\n */\nfunction SwitchField({\n  label,\n  description,\n  className,\n  disabled,\n  layout = \"control\",\n  ...props\n}: Omit<SwitchPrimitive.Root.Props, \"className\"> & {\n  label: React.ReactNode;\n  description?: React.ReactNode;\n  className?: string;\n  /** control (default): aligns to a form column. cell: a row inside an enclosing frame (inset text and switch). */ layout?:\n    | \"control\"\n    | \"cell\";\n}): React.ReactElement {\n  return (\n    <Field.Root\n      data-slot=\"switch-field\"\n      data-kl-layout={layout}\n      disabled={disabled}\n      className={cn(choiceStyles.root, className)}\n    >\n      <Field.Label data-slot=\"switch-field-row\" className={choiceStyles.row}>\n        <span\n          data-slot=\"switch-field-text\"\n          className={cn(\n            choiceStyles.text,\n            \"ps-(--kl-inset) pe-0 group-data-[kl-layout=control]/choice:ps-0 group-data-[kl-layout=control]/choice:pe-(--kl-inset)\",\n          )}\n        >\n          <span data-slot=\"switch-field-label\" className={choiceStyles.label}>\n            {label}\n          </span>\n          {description ? (\n            <Field.Description data-slot=\"switch-field-description\" className={choiceStyles.description}>\n              {description}\n            </Field.Description>\n          ) : null}\n        </span>\n        <span\n          data-slot=\"switch-field-cell\"\n          className=\"grid flex-none place-items-center px-(--kl-inset) group-data-[kl-layout=control]/choice:px-0\"\n        >\n          <Switch disabled={disabled} {...props} />\n        </span>\n      </Field.Label>\n    </Field.Root>\n  );\n}\n\nexport { Switch, SwitchRoot, SwitchThumb, SwitchField };\n",
      "type": "registry:ui",
      "target": "components/keyline/ui/switch.tsx"
    }
  ],
  "type": "registry:ui"
}