{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"animated-checkbox","type":"registry:ui","title":"Animated Checkbox","description":"A checkbox that pops when checked and draws its tick, with an indeterminate dash for partial selections.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/animated-checkbox.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { useEffect, useId, useRef, useState, type ChangeEvent, type ReactNode } from \"react\";\n\ntype AnimatedCheckboxProps = {\n  checked?: boolean;\n  defaultChecked?: boolean;\n  onCheckedChange?: (checked: boolean) => void;\n  label?: ReactNode;\n  description?: ReactNode;\n  /** Shows a dash instead of the tick, as in a \"select all\" box that is partly checked. */\n  indeterminate?: boolean;\n  color?: string;\n  /** Box size in pixels. */\n  size?: number;\n  disabled?: boolean;\n  required?: boolean;\n  name?: string;\n  value?: string;\n  id?: string;\n  \"aria-label\"?: string;\n  className?: string;\n};\n\nconst INK = \"#070606\";\nconst EASE = [0.65, 0, 0.35, 1] as const;\n\nexport function AnimatedCheckbox({\n  checked,\n  defaultChecked = false,\n  onCheckedChange,\n  label,\n  description,\n  indeterminate = false,\n  color = \"#ff784f\",\n  size = 20,\n  disabled = false,\n  required,\n  name,\n  value = \"on\",\n  id,\n  \"aria-label\": ariaLabel,\n  className = \"\",\n}: AnimatedCheckboxProps) {\n  const autoId = useId();\n  const inputId = id ?? `${autoId}-checkbox`;\n  const descId = `${inputId}-description`;\n  const reduce = useReducedMotion();\n  const inputRef = useRef<HTMLInputElement>(null);\n  const [inner, setInner] = useState(defaultChecked);\n  const on = checked ?? inner;\n  const tick = on && !indeterminate;\n  const filled = on || indeterminate;\n\n  // `indeterminate` only exists as a DOM property, and a click clears it, so re-apply it after every render.\n  useEffect(() => {\n    if (inputRef.current) inputRef.current.indeterminate = indeterminate;\n  });\n\n  function handleChange(e: ChangeEvent<HTMLInputElement>) {\n    const next = e.target.checked;\n    if (checked === undefined) setInner(next);\n    onCheckedChange?.(next);\n  }\n\n  const draw = (visible: boolean) => ({\n    pathLength: { duration: reduce ? 0 : visible ? 0.3 : 0.16, delay: visible && !reduce ? 0.08 : 0, ease: EASE },\n    opacity: { duration: 0, delay: visible || reduce ? 0 : 0.16 },\n  });\n\n  return (\n    <div className={`inline-flex gap-3 ${description ? \"items-start\" : \"items-center\"} ${disabled ? \"opacity-50\" : \"\"} ${className}`}>\n      <span className=\"relative grid shrink-0 place-items-center\" style={{ width: size, height: size, marginTop: description ? 1 : 0 }}>\n        <input\n          ref={inputRef}\n          id={inputId}\n          type=\"checkbox\"\n          name={name}\n          value={value}\n          checked={on}\n          disabled={disabled}\n          required={required}\n          onChange={handleChange}\n          aria-label={label ? undefined : ariaLabel}\n          aria-describedby={description ? descId : undefined}\n          className=\"peer absolute inset-0 z-10 m-0 size-full cursor-pointer appearance-none opacity-0 disabled:cursor-not-allowed\"\n        />\n        <span\n          aria-hidden=\"true\"\n          className=\"absolute inset-0 rounded-[30%] border-[1.5px] border-ink-500 bg-ink-900 transition-colors peer-hover:border-bone-dim peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-ember\"\n        />\n        <motion.span\n          aria-hidden=\"true\"\n          className=\"absolute inset-0 rounded-[30%]\"\n          style={{ backgroundColor: color }}\n          initial={false}\n          animate={filled ? { scale: 1, opacity: 1 } : { scale: 0.35, opacity: 0 }}\n          transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 620, damping: filled ? 15 : 30 }}\n        />\n        <AnimatePresence initial={false}>\n          {tick && !reduce ? (\n            <motion.span\n              key=\"ring\"\n              aria-hidden=\"true\"\n              className=\"pointer-events-none absolute inset-0 rounded-[30%] border-2\"\n              style={{ borderColor: color }}\n              initial={{ scale: 1, opacity: 0.7 }}\n              animate={{ scale: 1.9, opacity: 0 }}\n              exit={{ opacity: 0 }}\n              transition={{ duration: 0.5, ease: \"easeOut\" }}\n            />\n          ) : null}\n        </AnimatePresence>\n        <svg\n          viewBox=\"0 0 20 20\"\n          width={size}\n          height={size}\n          fill=\"none\"\n          stroke={INK}\n          strokeWidth={2.6}\n          strokeLinecap=\"round\"\n          strokeLinejoin=\"round\"\n          className=\"pointer-events-none relative\"\n          aria-hidden=\"true\"\n        >\n          <motion.path\n            d=\"M5.2 10.4 8.5 13.6 14.8 6.8\"\n            initial={false}\n            animate={{ pathLength: tick ? 1 : 0, opacity: tick ? 1 : 0 }}\n            transition={draw(tick)}\n          />\n          <motion.path\n            d=\"M6 10h8\"\n            initial={false}\n            animate={{ pathLength: indeterminate ? 1 : 0, opacity: indeterminate ? 1 : 0 }}\n            transition={draw(indeterminate)}\n          />\n        </svg>\n      </span>\n      {label || description ? (\n        <span className=\"grid min-w-0 gap-0.5\">\n          {label ? (\n            <label\n              htmlFor={inputId}\n              className={`select-none text-sm text-bone ${disabled ? \"cursor-not-allowed\" : \"cursor-pointer\"}`}\n            >\n              {label}\n            </label>\n          ) : null}\n          {description ? (\n            <span id={descId} className=\"text-xs leading-relaxed text-bone-dim\">\n              {description}\n            </span>\n          ) : null}\n        </span>\n      ) : null}\n    </div>\n  );\n}\n"}]}