{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ui-toggle",
  "title": "Toggle",
  "description": "Switch with a label and hint whose thumb stretches as it travels and pops a few pixel sparks when it turns on.",
  "registryDependencies": [
    "https://elements.lumesec.ai/r/lumesec-theme.json",
    "https://elements.lumesec.ai/r/lumesec-motion.json",
    "https://elements.lumesec.ai/r/lumesec-sparks.json",
    "https://elements.lumesec.ai/r/lumesec-use-controllable-state.json",
    "utils"
  ],
  "files": [
    {
      "path": "registry/components/lumesec/ui-toggle.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { prefersReducedMotion } from \"@/lib/lumesec/motion\";\nimport { BurstLayer, useBurst } from \"@/lib/lumesec/sparks\";\nimport { useControllableState } from \"@/lib/lumesec/use-controllable-state\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface UiToggleProps extends Omit<React.ComponentProps<\"div\">, \"onChange\"> {\n  /** Controlled state. Use with `onCheckedChange`. */\n  checked?: boolean;\n  /** Initial state when uncontrolled. */\n  defaultChecked?: boolean;\n  /** Called when the user toggles the switch. Changing `checked` from outside does not call it. */\n  onCheckedChange?: (checked: boolean) => void;\n  /** Label text. Defaults to \"Extended thinking\". */\n  children?: React.ReactNode;\n  /** Secondary text under the label, linked to the switch as its description. */\n  hint?: React.ReactNode;\n}\n\n/**\n * Switch with a label and hint whose thumb stretches as it travels and pops a few pixel sparks when it\n * turns on. The whole row is clickable; the switch itself is a native button with `role=\"switch\"`.\n *\n * @example\n * <UiToggle defaultChecked hint=\"Think longer before answering\">\n *   Extended thinking\n * </UiToggle>\n */\nexport function UiToggle({\n  checked: checkedProp,\n  defaultChecked = false,\n  onCheckedChange,\n  children,\n  hint,\n  className,\n  onClick,\n  ...props\n}: UiToggleProps) {\n  const [checked, setChecked] = useControllableState({\n    value: checkedProp,\n    defaultValue: defaultChecked,\n    onChange: onCheckedChange,\n  });\n  const thumbRef = React.useRef<HTMLSpanElement>(null);\n  const { ref: sparksRef, fire: fireSparks } = useBurst();\n  const sparkTimer = React.useRef(0);\n  const labelId = React.useId();\n  const hintId = React.useId();\n  const state = checked ? \"checked\" : \"unchecked\";\n\n  React.useEffect(() => () => window.clearTimeout(sparkTimer.current), []);\n\n  const toggle = () => {\n    const on = !checked;\n    setChecked(on);\n    if (prefersReducedMotion()) return;\n    // the thumb stretches to 25px mid-travel, then snaps back to a circle\n    thumbRef.current?.animate(\n      on\n        ? [\n            { transform: \"translateX(0)\", width: \"18px\" },\n            { transform: \"translateX(2px)\", width: \"25px\", offset: 0.45 },\n            { transform: \"translateX(18px)\", width: \"18px\" },\n          ]\n        : [\n            { transform: \"translateX(18px)\", width: \"18px\" },\n            { transform: \"translateX(11px)\", width: \"25px\", offset: 0.45 },\n            { transform: \"translateX(0)\", width: \"18px\" },\n          ],\n      { duration: 420, easing: \"cubic-bezier(.3,.8,.3,1.1)\" },\n    );\n    if (on) {\n      window.clearTimeout(sparkTimer.current);\n      // the burst layer extends 40px past the switch: (70, 52) is where the thumb lands\n      sparkTimer.current = window.setTimeout(\n        () => fireSparks({ x: 40 + 30, y: 40 + 12 }, { count: 18, speed: [50, 170], life: [0.3, 0.7] }),\n        170,\n      );\n    }\n  };\n\n  return (\n    <div\n      data-slot=\"ui-toggle\"\n      data-state={state}\n      className={cn(\"flex cursor-pointer items-center justify-between gap-[18px] select-none\", className)}\n      onClick={(event) => {\n        onClick?.(event);\n        if (!event.defaultPrevented) toggle();\n      }}\n      {...props}\n    >\n      <span className=\"grid min-w-0 gap-0.5\">\n        <span id={labelId} className=\"text-[14px] leading-normal font-medium text-foreground\">\n          {children ?? \"Extended thinking\"}\n        </span>\n        <span id={hintId} className=\"text-[12.5px] leading-[1.4] text-muted-foreground\">\n          {hint}\n        </span>\n      </span>\n      <button\n        type=\"button\"\n        role=\"switch\"\n        aria-checked={checked}\n        aria-labelledby={labelId}\n        aria-describedby={hint ? hintId : undefined}\n        data-state={state}\n        className=\"relative h-6 w-[42px] flex-none cursor-pointer rounded-xl border-0 bg-muted p-0 font-[inherit] shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--foreground)_9%,transparent)] outline-none select-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-lumesec focus-visible:outline-solid\"\n      >\n        <span\n          data-state={state}\n          className=\"absolute inset-0 rounded-xl bg-lumesec transition-[clip-path] duration-450 ease-[cubic-bezier(.3,.7,.2,1)] [clip-path:circle(0px_at_12px_12px)] data-[state=checked]:[clip-path:circle(48px_at_30px_12px)]\"\n        />\n        <span\n          ref={thumbRef}\n          data-state={state}\n          className=\"absolute top-[3px] left-[3px] size-[18px] rounded-[9px] bg-white shadow-[0_1px_3px_rgba(0,0,0,.3)] data-[state=checked]:[transform:translateX(18px)]\"\n        />\n        <BurstLayer ref={sparksRef} />\n      </button>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "@components/lumesec/ui-toggle.tsx"
    }
  ],
  "meta": {
    "tag": "ui-toggle",
    "collection": "interaction",
    "react": "UiToggle",
    "kind": "react"
  },
  "docs": "Toggle docs: https://elements.lumesec.ai/components/interaction/toggle",
  "categories": [
    "interaction",
    "controls"
  ],
  "type": "registry:component"
}