{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "switch",
  "title": "Switch",
  "description": "Animated toggle switch with a spring-driven thumb, smooth fill transition, and optional label.",
  "dependencies": [
    "motion",
    "@radix-ui/react-switch"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/components/unlumen/switch/index.tsx",
      "content": "\"use client\";\n\nimport * as SwitchPrimitive from \"@radix-ui/react-switch\";\nimport { motion, useMotionValue, useTransform, animate } from \"motion/react\";\nimport { forwardRef, useEffect, useRef } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nconst TRACK_W = 44;\nconst TRACK_H = 26;\nconst THUMB_SIZE = 20;\nconst THUMB_TRAVEL = TRACK_W - THUMB_SIZE - 4; // px from left to right (margin 2px each side)\n\nconst spring = { type: \"spring\" as const, duration: 0.35, bounce: 0.3 };\nconst springFast = { type: \"spring\" as const, duration: 0.15, bounce: 0 };\nconst springSnap = { type: \"spring\" as const, duration: 0.4, bounce: 0.5 };\n\ninterface SwitchProps\n  extends Omit<\n    React.ComponentPropsWithoutRef<typeof SwitchPrimitive.Root>,\n    \"asChild\"\n  > {\n  label?: string;\n  /** @default \"right\" */\n  labelSide?: \"left\" | \"right\";\n}\n\nconst Switch = forwardRef<\n  React.ElementRef<typeof SwitchPrimitive.Root>,\n  SwitchProps\n>(\n  (\n    {\n      checked,\n      onCheckedChange,\n      label,\n      labelSide = \"right\",\n      className,\n      disabled,\n      ...props\n    },\n    ref,\n  ) => {\n    const isControlled = checked !== undefined;\n    const internalChecked = isControlled ? checked : false;\n\n    const thumbX = useMotionValue(internalChecked ? THUMB_TRAVEL : 0);\n    const thumbScaleX = useMotionValue(1);\n    const thumbScaleY = useMotionValue(1);\n\n    const fillOpacity = useTransform(thumbX, [0, THUMB_TRAVEL], [0, 1]);\n\n    const prevChecked = useRef(internalChecked);\n    const directionRef = useRef<1 | -1>(1);\n\n    useEffect(() => {\n      if (prevChecked.current === internalChecked) return;\n      prevChecked.current = internalChecked;\n      animate(thumbX, internalChecked ? THUMB_TRAVEL : 0, spring);\n    }, [internalChecked, thumbX]);\n\n    const handlePointerDown = () => {\n      // Flatten thumb on press (squeeze effect)\n      animate(thumbScaleX, 0.82, springFast);\n      animate(thumbScaleY, 1.1, springFast);\n    };\n\n    const handlePointerUp = () => {\n      // Snap back with bounce\n      animate(thumbScaleX, 1, springSnap);\n      animate(thumbScaleY, 1, springSnap);\n    };\n\n    const handleCheckedChange = (next: boolean) => {\n      directionRef.current = next ? 1 : -1;\n\n      // Squeeze in direction of travel on release\n      animate(thumbScaleX, 1.15, springFast).then(() => {\n        animate(thumbScaleX, 1, springSnap);\n      });\n      animate(thumbScaleY, 0.88, springFast).then(() => {\n        animate(thumbScaleY, 1, springSnap);\n      });\n\n      animate(thumbX, next ? THUMB_TRAVEL : 0, spring);\n      onCheckedChange?.(next);\n    };\n\n    const switchEl = (\n      <SwitchPrimitive.Root\n        ref={ref}\n        checked={checked}\n        onCheckedChange={handleCheckedChange}\n        disabled={disabled}\n        onPointerDown={handlePointerDown}\n        onPointerUp={handlePointerUp}\n        onPointerLeave={handlePointerUp}\n        className={cn(\n          \"relative inline-flex shrink-0 cursor-pointer items-center rounded-full\",\n          \"outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n          \"disabled:cursor-not-allowed disabled:opacity-50\",\n          className,\n        )}\n        style={{ width: TRACK_W, height: TRACK_H }}\n        {...props}\n      >\n        <span\n          className=\"absolute inset-0 rounded-full\"\n          style={{ backgroundColor: \"var(--accent)\" }}\n        />\n\n        <motion.span\n          className=\"absolute inset-0 rounded-full\"\n          style={{\n            backgroundColor: \"var(--foreground)\",\n            opacity: fillOpacity,\n          }}\n        />\n\n        <SwitchPrimitive.Thumb asChild>\n          <motion.span\n            className=\"block rounded-full pointer-events-none z-10\"\n            style={{\n              width: THUMB_SIZE,\n              height: THUMB_SIZE,\n              x: thumbX,\n              scaleX: thumbScaleX,\n              scaleY: thumbScaleY,\n              marginLeft: 2,\n              backgroundColor: \"white\",\n              boxShadow:\n                \"0 1px 4px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.06)\",\n            }}\n          />\n        </SwitchPrimitive.Thumb>\n      </SwitchPrimitive.Root>\n    );\n\n    if (!label) return switchEl;\n\n    return (\n      <label\n        className={cn(\n          \"flex items-center gap-2.5 cursor-pointer select-none\",\n          disabled && \"cursor-not-allowed opacity-50\",\n        )}\n      >\n        {labelSide === \"left\" && (\n          <span className=\"text-sm text-foreground\">{label}</span>\n        )}\n        {switchEl}\n        {labelSide === \"right\" && (\n          <span className=\"text-sm text-foreground\">{label}</span>\n        )}\n      </label>\n    );\n  },\n);\n\nSwitch.displayName = \"Switch\";\n\nexport { Switch, type SwitchProps };\n",
      "type": "registry:ui",
      "target": "components/unlumen-ui/switch.tsx"
    }
  ],
  "type": "registry:ui"
}