{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "switch",
  "title": "Switch",
  "dependencies": [
    "solid-js@^1.9.15"
  ],
  "registryDependencies": [
    "@audiocn-solid/core"
  ],
  "files": [
    {
      "path": "components/ui/switch.tsx",
      "content": "import { createSignal, untrack } from \"solid-js\";\n\nimport { createCompatEffect } from \"@/lib/solid/effect\";\nimport type { ButtonDOMProps } from \"@/lib/solid/jsx-types\";\nimport { omitProps } from \"@/lib/solid/props\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface SwitchProps extends Omit<\n  ButtonDOMProps,\n  \"onClick\" | \"disabled\" | \"value\"\n> {\n  checked?: boolean;\n  defaultChecked?: boolean;\n  disabled?: boolean;\n  value?: string;\n  onCheckedChange?: (checked: boolean) => void;\n  onClick?: (event: MouseEvent) => void;\n  size?: \"sm\" | \"default\";\n  className?: string;\n}\n\nexport const Switch = (props: SwitchProps) => {\n  const initialChecked = untrack(() => props.defaultChecked ?? false);\n  const [uncontrolled, setUncontrolled] = createSignal(initialChecked);\n\n  const refOptions = { ownedWrite: true, name: \"Switch.input\" };\n\n  const [input, setInput] = createSignal<HTMLInputElement | undefined>(\n    undefined,\n    refOptions\n  );\n\n  createCompatEffect(\n    () => ({ element: input(), controlled: props.checked }),\n    ({ element, controlled }) => {\n      if (element) element.defaultChecked = controlled ?? initialChecked;\n      const form = element?.form;\n\n      const reset = (event: Event) => {\n        // The browser resets inputs after dispatch, including controlled inputs.\n        queueMicrotask(() => {\n          if (event.defaultPrevented || !element) return;\n          const next = props.checked ?? initialChecked;\n\n          if (props.checked === undefined) setUncontrolled(next);\n          element.checked = next;\n        });\n      };\n\n      form?.addEventListener(\"reset\", reset);\n\n      return () => form?.removeEventListener(\"reset\", reset);\n    }\n  );\n\n  const checked = () => props.checked ?? uncontrolled();\n\n  const rest = omitProps(props, [\n    \"class\",\n    \"className\",\n    \"checked\",\n    \"defaultChecked\",\n    \"onCheckedChange\",\n    \"onClick\",\n    \"size\",\n    \"children\",\n    \"name\",\n    \"value\",\n  ]);\n\n  return (\n    <>\n      <button\n        type=\"button\"\n        role=\"switch\"\n        aria-checked={checked() ? \"true\" : \"false\"}\n        data-slot=\"switch\"\n        data-size={props.size ?? \"default\"}\n        data-checked={checked() ? \"\" : undefined}\n        data-unchecked={checked() ? undefined : \"\"}\n        data-disabled={props.disabled ? \"\" : undefined}\n        class={cn(\n          \"peer group/switch focus-visible:border-ring focus-visible:ring-ring/30 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary group-has-[:focus-visible]/field-label:data-checked:border-primary data-unchecked:bg-input/90 relative inline-flex shrink-0 items-center rounded-2xl border-2 transition-all outline-none group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:ring-3 aria-invalid:ring-3 data-disabled:cursor-not-allowed data-disabled:opacity-50 data-unchecked:border-transparent group-has-[:focus-visible]/field-label:data-unchecked:border-transparent data-[size=default]:h-5 data-[size=default]:w-8 data-[size=sm]:h-4 data-[size=sm]:w-6\",\n          props.class,\n          props.className\n        )}\n        {...rest}\n        onClick={(event: MouseEvent) => {\n          props.onClick?.(event);\n\n          if (event.defaultPrevented || props.disabled) return;\n          const next = !checked();\n\n          if (props.checked === undefined) setUncontrolled(next);\n          props.onCheckedChange?.(next);\n        }}\n      >\n        <span\n          data-slot=\"switch-thumb\"\n          data-checked={checked() ? \"\" : undefined}\n          data-unchecked={checked() ? undefined : \"\"}\n          class=\"bg-background dark:data-checked:bg-primary-foreground dark:data-unchecked:bg-foreground pointer-events-none block rounded-2xl shadow-sm ring-0 transition-transform not-dark:bg-clip-padding group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 data-checked:translate-x-[calc(100%-4px)] data-unchecked:translate-x-0\"\n        />\n      </button>\n      <input\n        ref={setInput}\n        type=\"checkbox\"\n        aria-hidden=\"true\"\n        tabindex=\"-1\"\n        class=\"sr-only\"\n        name={props.name}\n        value={props.value ?? \"on\"}\n        form={props.form}\n        checked={checked()}\n        disabled={props.disabled}\n        onChange={(event) => {\n          const next = event.currentTarget.checked;\n\n          if (props.checked === undefined) setUncontrolled(next);\n          props.onCheckedChange?.(next);\n        }}\n      />\n    </>\n  );\n};\n",
      "type": "registry:ui"
    },
    {
      "path": "lib/audiocn-license.txt",
      "content": "Audio component source adapted from https://github.com/audiocn/ui.\nMIT License — Copyright (c) 2026 OrcDev\n\nRegular SVG icon geometry adapted from @phosphor-icons/react 2.1.10.\nMIT License — Copyright (c) 2020 Phosphor Icons\n\nThe following permission and warranty terms apply to both notices.\nRetain this file with copies or substantial portions of the source.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
      "type": "registry:file",
      "target": "@lib/audiocn-license.txt"
    }
  ],
  "type": "registry:ui"
}
