{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "switch",
  "type": "registry:ui",
  "title": "Switch",
  "description": "An on/off switch for a setting that applies at once, built on Radix Switch.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/switch.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/switch.tsx",
      "content": "import { useState, type ButtonHTMLAttributes } from 'react';\nimport { cn } from '../lib/utils';\n\n// Own implementation (not Radix): Radix Switch renders a hidden checkbox with an inline style attribute in server-rendered HTML.\ntype SwitchProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onChange' | 'role' | 'value'> & {\n  checked?: boolean; defaultChecked?: boolean; onCheckedChange?: (checked: boolean) => void; name?: string; value?: string; required?: boolean;\n};\n\n/** Toggle. Give it a label via aria-label or an associated <label htmlFor>. With `name` it posts `value` (default \"on\") when checked. */\nexport function Switch({ className, checked, defaultChecked = false, onCheckedChange, name, value = 'on', required, form, disabled, onClick, ...rest }: SwitchProps) {\n  const [inner, setInner] = useState(defaultChecked);\n  const on = checked ?? inner;\n  const state = on ? 'checked' : 'unchecked';\n  return (\n    <>\n      <button\n        type=\"button\"\n        role=\"switch\"\n        aria-checked={on}\n        data-state={state}\n        data-disabled={disabled ? '' : undefined}\n        disabled={disabled}\n        aria-required={required || undefined}\n        form={form}\n        onClick={(e) => {\n          onClick?.(e);\n          if (e.defaultPrevented) return;\n          if (checked === undefined) setInner(!on);\n          onCheckedChange?.(!on);\n        }}\n        className={cn(\n          'relative inline-flex h-6 w-11 shrink-0 items-center rounded-kh-pill bg-kh-surface-3 transition-colors duration-(--kh-dur) data-[state=checked]:bg-kh-accent',\n          // Off, the track also takes the band's control edge: transparent on light bands, 3:1 on the inverse and accent bands, where a quiet\n          // fill alone cannot reach it (WCAG 1.4.11, KB-354).\n          'data-[state=unchecked]:ring-1 data-[state=unchecked]:ring-(--kh-ghost-edge) data-[state=unchecked]:ring-inset',\n          'after:absolute after:-inset-2.5 after:content-[\"\"] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--kh-focus) disabled:opacity-50',\n          className,\n        )}\n        {...rest}\n      >\n        <span data-state={state} className=\"block size-5 translate-x-0.5 rounded-kh-pill bg-kh-surface shadow-kh-1 transition-transform duration-(--kh-dur) data-[state=checked]:translate-x-[22px]\" />\n      </button>\n      {name && on && !disabled && <input type=\"hidden\" name={name} value={value} form={form} />}\n    </>\n  );\n}\n"
    }
  ]
}
