{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "switch",
  "type": "registry:ui",
  "title": "Switch",
  "description": "Switch is a boolean settings control for immediate on/off changes — not a substitute for Checkbox in forms.",
  "author": "Skrewww",
  "dependencies": [],
  "registryDependencies": [
    "@skrewww/foundation"
  ],
  "docs": "Host requirements (assumed already present, not installed by this command): react, react-dom.",
  "files": [
    {
      "path": "components/ui/Switch.tsx",
      "content": "/** @skrewww-component switch */\n\"use client\";\n\nimport { useId } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { useControllableState } from \"@/lib/use-controllable\";\nimport styles from \"@/components/ui/switch.module.css\";\n\nexport type SwitchProps = {\n  label: string;\n  checked?: boolean;\n  defaultChecked?: boolean;\n  onCheckedChange?: (checked: boolean) => void;\n  disabled?: boolean;\n  id?: string;\n  className?: string;\n  \"aria-describedby\"?: string;\n};\n\nexport function Switch({\n  label,\n  checked,\n  defaultChecked = false,\n  onCheckedChange,\n  disabled = false,\n  id: idProp,\n  className,\n  \"aria-describedby\": ariaDescribedBy,\n}: SwitchProps) {\n  const generatedId = useId();\n  const id = idProp ?? generatedId;\n  const labelId = `${id}-label`;\n\n  const [isOn, setIsOn] = useControllableState({\n    value: checked,\n    defaultValue: defaultChecked,\n    onChange: onCheckedChange,\n  });\n\n  function handleClick() {\n    if (disabled) return;\n    setIsOn(!isOn);\n  }\n\n  return (\n    <div className={cn(styles.control, disabled && styles.controlDisabled, className)}>\n      <button\n        id={id}\n        type=\"button\"\n        role=\"switch\"\n        aria-checked={isOn}\n        aria-labelledby={labelId}\n        aria-describedby={ariaDescribedBy}\n        disabled={disabled}\n        className={cn(\n          styles.switch,\n          isOn && styles.switchOn,\n          disabled && styles.switchDisabled,\n        )}\n        onClick={handleClick}\n      >\n        <span className={cn(styles.thumb, isOn && styles.thumbOn)} aria-hidden=\"true\" />\n      </button>\n      <span id={labelId} className={cn(styles.labelText, disabled && styles.labelDisabled)}>\n        {label}\n      </span>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "~/components/ui/Switch.tsx"
    },
    {
      "path": "components/ui/switch.module.css",
      "content": ".control {\n  display: inline-flex;\n  align-items: center;\n  gap: var(--control-gap);\n  cursor: pointer;\n  color: var(--semantic-text-primary);\n}\n\n.controlDisabled {\n  cursor: not-allowed;\n}\n\n.switch {\n  box-sizing: border-box;\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  flex-shrink: 0;\n  width: var(--control-switch-track-width);\n  height: var(--control-switch-track-height);\n  padding: 0;\n  border: none;\n  background: none;\n  cursor: pointer;\n}\n\n/* Track fill lives on its own layer, not on .switch itself — Figma dims\n   the Track to 40% opacity when Disabled but keeps the Thumb at full\n   opacity, and opacity on .switch would dim both since Thumb is its\n   child. A ::before layer lets Disabled target only the fill. */\n.switch::before {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  border-radius: min(var(--shape-radius-control), 9999px);\n  /* Off/default track fill — Figma has no stroke anywhere on Switch; the\n     track boundary itself is communicated by this fill, not a border. */\n  background: var(--semantic-border-strong);\n  transition: background-color 0.15s ease;\n}\n\n.switch:focus {\n  outline: none;\n}\n\n.switch:focus-visible {\n  outline: 2px solid var(--semantic-focus-ring);\n  outline-offset: 2px;\n}\n\n.switchOn::before {\n  background: var(--semantic-action-primary);\n}\n\n.switchOn:hover:not(:disabled):not([aria-disabled=\"true\"])::before {\n  background: var(--semantic-action-primary-hover);\n}\n\n.switchDisabled {\n  pointer-events: none;\n}\n\n.switchDisabled::before {\n  opacity: var(--opacity-disabled);\n}\n\n.thumb {\n  position: absolute;\n  top: 50%;\n  left: var(--control-switch-thumb-offset);\n  width: var(--control-switch-thumb-size);\n  height: var(--control-switch-thumb-size);\n  border-radius: 50%;\n  background: var(--semantic-surface-default);\n  box-shadow: 0 1px 2px rgb(19 19 22 / 0.12);\n  transform: translateY(-50%);\n  transition: left 0.15s ease;\n}\n\n.thumbOn {\n  left: calc(\n    var(--control-switch-track-width) - var(--control-switch-thumb-size) -\n      var(--control-switch-thumb-offset)\n  );\n}\n\n.labelText {\n  font-size: 0.875rem;\n  line-height: 1.4;\n}\n\n.labelDisabled {\n  opacity: var(--opacity-disabled);\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .switch::before,\n  .thumb {\n    transition: none;\n  }\n}\n",
      "type": "registry:ui",
      "target": "~/components/ui/switch.module.css"
    },
    {
      "path": "lib/cn.ts",
      "content": "export function cn(...classes: Array<string | false | null | undefined>): string {\n  return classes.filter(Boolean).join(\" \");\n}\n",
      "type": "registry:lib",
      "target": "~/lib/cn.ts"
    },
    {
      "path": "lib/use-controllable.ts",
      "content": "import { useCallback, useEffect, useRef, useState } from \"react\";\n\nexport function useControllableState<T>({\n  value,\n  defaultValue,\n  onChange,\n  controlled: controlledProp,\n  valueProvided,\n}: {\n  value?: T;\n  defaultValue?: T;\n  onChange?: (next: T) => void;\n  /** Explicit controlled override — prefer `valueProvided` from the component root. */\n  controlled?: boolean;\n  /** True when the parent passed a `value` prop, including `undefined`. */\n  valueProvided?: boolean;\n}) {\n  const [uncontrolled, setUncontrolled] = useState(defaultValue as T);\n  const isControlled = controlledProp ?? valueProvided ?? value !== undefined;\n  const current = isControlled ? (value as T) : uncontrolled;\n  const wasControlledRef = useRef(isControlled);\n\n  useEffect(() => {\n    if (process.env.NODE_ENV !== \"development\") return;\n    if (wasControlledRef.current !== isControlled) {\n      console.warn(\n        \"[Skrewww] A component changed between controlled and uncontrolled modes. Keep `value` or `defaultValue` usage consistent across renders.\",\n      );\n    }\n    wasControlledRef.current = isControlled;\n  }, [isControlled]);\n\n  const setValue = useCallback(\n    (next: T) => {\n      if (!isControlled) setUncontrolled(next);\n      onChange?.(next);\n    },\n    [isControlled, onChange],\n  );\n\n  return [current, setValue] as const;\n}\n",
      "type": "registry:lib",
      "target": "~/lib/use-controllable.ts"
    }
  ]
}
