{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toggle",
  "title": "Toggle",
  "description": "A native checkbox switch with a dithered track that eases between off and on.",
  "dependencies": [],
  "registryDependencies": [
    "https://dotgrain.space/r/engine.json"
  ],
  "files": [
    {
      "path": "registry/ui/toggle.tsx",
      "content": "\"use client\";\n\nimport { useState, type ComponentProps } from \"react\";\nimport { paletteColors } from \"@/lib/dotgrain/palettes\";\nimport { useColorScheme, useDitherTokens, useReducedMotion } from \"@/lib/dotgrain/provider\";\nimport { Quantize } from \"@/lib/dotgrain/quantize\";\nimport type { DitherTokens } from \"@/lib/dotgrain/types\";\n\nexport type ToggleProps = Omit<ComponentProps<\"input\">, \"type\" | \"size\" | keyof DitherTokens> &\n  Partial<Omit<DitherTokens, \"mode\" | \"glyphs\">> & {\n    /** Track height in CSS pixels; the width is twice that. */\n    size?: number;\n  };\n\nexport function Toggle({\n  size = 24,\n  pattern, cell, palette, speed, contrast, threshold,\n  checked, defaultChecked, onChange, onFocus, onBlur,\n  disabled, className, style, ...props\n}: ToggleProps) {\n  const tokens = { pattern, cell, palette, speed, contrast, threshold };\n  const [own, setOwn] = useState(!!defaultChecked);\n  const [focus, setFocus] = useState(false);\n  const on = checked ?? own;\n  const reduced = useReducedMotion();\n  const { scheme } = useColorScheme();\n  const colors = paletteColors(useDitherTokens({ ...tokens, mode: \"dither\" }).palette, scheme);\n  const [bg, fg] = [colors[0], colors[colors.length - 1]];\n  const thumb = size - 6;\n  return (\n    <span\n      className={className}\n      style={{\n        position: \"relative\",\n        display: \"inline-block\",\n        width: size * 2,\n        height: size,\n        border: `1px solid ${fg}`,\n        background: bg,\n        opacity: disabled ? 0.5 : undefined,\n        outline: focus ? `2px solid ${fg}` : undefined,\n        outlineOffset: 2,\n        ...style,\n      }}\n    >\n      <Quantize\n        source={{ kind: \"field\", field: \"progress\", params: { value: on ? 1.3 : -0.3, softness: 0.3 } }}\n        ease\n        {...tokens}\n        mode=\"dither\"\n        style={{ position: \"absolute\", inset: 0 }}\n      />\n      <span\n        aria-hidden=\"true\"\n        style={{\n          position: \"absolute\",\n          top: 2,\n          left: on ? size * 2 - thumb - 4 : 2,\n          width: thumb,\n          height: thumb,\n          background: on ? bg : fg,\n          transition: reduced ? undefined : \"left 150ms ease-out\",\n        }}\n      />\n      {/* The real control: invisible but covering the track, so clicks, keyboard and forms are native. */}\n      <input\n        type=\"checkbox\"\n        role=\"switch\"\n        {...props}\n        checked={checked}\n        defaultChecked={defaultChecked}\n        disabled={disabled}\n        onChange={(e) => (setOwn(e.target.checked), onChange?.(e))}\n        onFocus={(e) => (setFocus(e.target.matches(\":focus-visible\")), onFocus?.(e))}\n        onBlur={(e) => (setFocus(false), onBlur?.(e))}\n        style={{ position: \"absolute\", inset: 0, width: \"100%\", height: \"100%\", margin: 0, opacity: 0, cursor: disabled ? \"not-allowed\" : \"pointer\" }}\n      />\n    </span>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "modes": [
      "dither"
    ]
  },
  "categories": [
    "control"
  ],
  "type": "registry:ui"
}