{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"animated-checkbox","type":"registry:component","title":"Animated Checkbox","description":"A real checkbox with a check that draws itself in: the fill opens from the centre, the box pops, a ring and six sparks leave it, and a checked label can strike through. Indeterminate state, three sizes, controlled or not. No dependencies.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/animated-checkbox.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useState, type CSSProperties, type ReactNode } from \"react\";\n\nconst SAFE_COLOR = /^(#[0-9a-f]{3,8}|(rgb|hsl)a?\\([\\d\\s.,%/-]+\\))$/i;\n\nconst SPARKS = [0, 60, 120, 180, 240, 300];\n\nconst CSS = [\n  \".acb{position:relative;-webkit-tap-highlight-color:transparent;--acb-s:var(--acb-size,24px);--acb-spring:cubic-bezier(.34,1.56,.64,1);--acb-out:cubic-bezier(.2,.8,.2,1)}\",\n  \".acb[data-size=sm]{--acb-s:var(--acb-size,18px)}\",\n  \".acb[data-size=lg]{--acb-s:var(--acb-size,32px)}\",\n  \".acb[data-disabled]{cursor:not-allowed;opacity:.45}\",\n  \"@media (pointer:coarse){.acb{min-height:40px}}\",\n  \".acb-in{position:absolute;left:0;top:50%;width:var(--acb-s);height:var(--acb-s);margin:0;transform:translateY(-50%);opacity:0;cursor:inherit}\",\n  \".acb-box{position:relative;flex:none;width:var(--acb-s);height:var(--acb-s);box-sizing:border-box;border:2px solid color-mix(in srgb,currentColor 36%,transparent);border-radius:calc(var(--acb-s)*.3);transition:border-color .2s ease,background-color .2s ease,transform .45s var(--acb-spring),box-shadow .3s ease}\",\n  \".acb:not([data-disabled]):hover .acb-in:not(:checked):not(:indeterminate)~.acb-box{border-color:color-mix(in srgb,currentColor 66%,transparent);background-color:color-mix(in srgb,currentColor 6%,transparent)}\",\n  \".acb:not([data-disabled]):active .acb-box{transform:scale(.86);transition-duration:.12s,.12s,.12s,.3s}\",\n  \".acb-in:checked~.acb-box,.acb-in:indeterminate~.acb-box{border-color:var(--acb-c);box-shadow:0 5px 16px -6px var(--acb-c)}\",\n  \".acb-in:focus-visible~.acb-box{outline:2px solid var(--acb-c);outline-offset:3px}\",\n  \".acb-bg{position:absolute;inset:-2px;border-radius:inherit;background:var(--acb-c);clip-path:circle(0% at 50% 50%);transition:clip-path .16s ease-in}\",\n  \".acb-in:checked~.acb-box .acb-bg,.acb-in:indeterminate~.acb-box .acb-bg{clip-path:circle(75% at 50% 50%);transition:clip-path .38s var(--acb-out)}\",\n  \".acb-svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible}\",\n  \".acb-svg path{fill:none;stroke:var(--acb-k);stroke-width:2.8;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1;stroke-dashoffset:1;transition:stroke-dashoffset .14s ease-in}\",\n  \".acb-in:checked:not(:indeterminate)~.acb-box .acb-tick,.acb-in:indeterminate~.acb-box .acb-dash{stroke-dashoffset:0;transition:stroke-dashoffset .3s cubic-bezier(.65,0,.35,1) .1s}\",\n  \".acb-ring{position:absolute;inset:-2px;border-radius:inherit;border:2px solid var(--acb-c);opacity:0;pointer-events:none}\",\n  \".acb-spark{position:absolute;left:50%;top:50%;width:3px;height:3px;margin:-1.5px 0 0 -1.5px;border-radius:50%;background:var(--acb-c);opacity:0;pointer-events:none}\",\n  \"@keyframes acb-pop{0%{transform:scale(.86)}45%{transform:scale(1.14)}100%{transform:scale(1)}}\",\n  \"@keyframes acb-ring{0%{opacity:.6;transform:scale(1)}100%{opacity:0;transform:scale(1.9)}}\",\n  \"@keyframes acb-spark{0%{opacity:1;transform:rotate(var(--a)) translateY(calc(var(--acb-s)*-.5)) scale(1)}100%{opacity:0;transform:rotate(var(--a)) translateY(calc(var(--acb-s)*-1)) scale(.2)}}\",\n  \"[data-ready] .acb-in:checked:not(:indeterminate)~.acb-box{animation:acb-pop .5s var(--acb-out)}\",\n  \"[data-ready] .acb-in:checked:not(:indeterminate)~.acb-box .acb-ring{animation:acb-ring .6s var(--acb-out) .05s}\",\n  \"[data-ready] .acb-in:checked:not(:indeterminate)~.acb-box .acb-spark{animation:acb-spark .55s var(--acb-out) .08s}\",\n  \".acb-label{font-size:var(--acb-fs,.875rem);font-weight:500;line-height:1.35;transition:opacity .3s ease .08s}\",\n  \".acb-text{background-image:linear-gradient(currentColor,currentColor);background-repeat:no-repeat;background-position:0 58%;background-size:0% 2px;-webkit-box-decoration-break:clone;box-decoration-break:clone;transition:background-size .12s ease-in}\",\n  \".acb[data-strike] .acb-in:checked~.acb-label{opacity:.48}\",\n  \".acb[data-strike] .acb-in:checked~.acb-label .acb-text{background-size:100% 2px;transition:background-size .36s cubic-bezier(.65,0,.35,1) .1s}\",\n  \"@media (prefers-reduced-motion:reduce){\",\n  \".acb-box,.acb-bg,.acb-svg path,.acb-label,.acb-text{transition-duration:.01s!important;transition-delay:0s!important}\",\n  \"[data-ready] .acb-in:checked~.acb-box,[data-ready] .acb-ring,[data-ready] .acb-spark{animation:none!important}\",\n  \".acb:not([data-disabled]):active .acb-box{transform:none}\",\n  \"}\",\n].join(\"\\n\");\n\nexport function AnimatedCheckbox({\n  label = \"Send me the changelog\",\n  defaultChecked = false,\n  checked,\n  onCheckedChange,\n  indeterminate = false,\n  disabled = false,\n  size = \"md\",\n  color = \"#ef4444\",\n  strike = false,\n  name,\n  value,\n  className = \"\",\n}: {\n  label?: ReactNode;\n  defaultChecked?: boolean;\n  /** Controlled value. Leave undefined to let the checkbox own its state. */\n  checked?: boolean;\n  onCheckedChange?: (checked: boolean) => void;\n  /** Shows the dash (mixed) state, e.g. for a select-all parent. */\n  indeterminate?: boolean;\n  disabled?: boolean;\n  size?: \"sm\" | \"md\" | \"lg\";\n  /** Fill colour of the checked box (hex, rgb() or hsl()). */\n  color?: string;\n  /** Draw a line through the label and dim it while checked. */\n  strike?: boolean;\n  name?: string;\n  value?: string;\n  className?: string;\n}) {\n  const [inner, setInner] = useState(defaultChecked);\n  const controlled = checked !== undefined;\n  const isChecked = controlled ? checked : inner;\n  const rootRef = useRef<HTMLLabelElement>(null);\n  const inputRef = useRef<HTMLInputElement>(null);\n  const accent = SAFE_COLOR.test(color.trim()) ? color.trim() : \"#ef4444\";\n\n  // Native indeterminate is a DOM property, not an attribute.\n  useEffect(() => {\n    if (inputRef.current) inputRef.current.indeterminate = indeterminate;\n  }, [indeterminate, isChecked]);\n\n  // Burst animations only play after mount, so a pre-checked box does not fire on load.\n  useEffect(() => {\n    const id = requestAnimationFrame(() => rootRef.current?.toggleAttribute(\"data-ready\", true));\n    return () => cancelAnimationFrame(id);\n  }, []);\n\n  return (\n    <>\n      <style>\n        {CSS}\n      </style>\n      <label\n        ref={rootRef}\n        className={\"acb flex cursor-pointer select-none items-center gap-3 \" + className}\n        data-size={size}\n        data-strike={strike ? \"\" : undefined}\n        data-disabled={disabled ? \"\" : undefined}\n        style={{ \"--acb-c\": accent, \"--acb-k\": \"#fff\" } as CSSProperties}\n      >\n        <input\n          ref={inputRef}\n          type=\"checkbox\"\n          className=\"acb-in\"\n          checked={isChecked}\n          disabled={disabled}\n          name={name}\n          value={value}\n          onChange={(e) => {\n            if (!controlled) setInner(e.target.checked);\n            onCheckedChange?.(e.target.checked);\n          }}\n        />\n        <span className=\"acb-box\" aria-hidden=\"true\">\n          <span className=\"acb-bg\" />\n          <svg className=\"acb-svg\" viewBox=\"0 0 24 24\">\n            <path className=\"acb-tick\" d=\"M6.2 12.8l3.8 3.8 7.8-9\" pathLength={1} />\n            <path className=\"acb-dash\" d=\"M7 12h10\" pathLength={1} />\n          </svg>\n          <span className=\"acb-ring\" />\n          {SPARKS.map((a) => (\n            <span key={a} className=\"acb-spark\" style={{ \"--a\": a + 20 + \"deg\" } as CSSProperties} />\n          ))}\n        </span>\n        <span className=\"acb-label\">\n          <span className=\"acb-text\">{label}</span>\n        </span>\n      </label>\n    </>\n  );\n}\n","type":"registry:component","target":"components/viberdy/animated-checkbox.tsx"}],"meta":{"tier":"free","tags":["checkbox","form","svg","toggle","checklist","indeterminate","micro-interaction"],"href":"https://viberdy.dev/library/animated-checkbox","aiPrompt":"Create a dependency-free React + Tailwind component named AnimatedCheckbox (\"use client\", one file, no framer-motion).\n\nProps (all optional): label = \"Send me the changelog\" (ReactNode), defaultChecked = false, checked (controlled; undefined = uncontrolled), onCheckedChange(checked), indeterminate = false, disabled = false, size \"sm\" | \"md\" | \"lg\" = \"md\" (box 18 / 24 / 32px), color = \"#ef4444\" (hex/rgb/hsl, validate with a regex and fall back to the default), strike = false, name, value, className.\n\nStructure: a root <label> (flex, items-center, gap-3, cursor-pointer, select-none) containing, in order, a real <input type=\"checkbox\"> (absolutely positioned over the box, opacity 0, so the browser owns toggling, forms, Space key and the mixed state; set input.indeterminate in an effect), a decorative box <span aria-hidden> and the label text. Render the CSS in a plain <style> element beside the label inside a fragment (React 18 and 19 safe, never inside the label). Drive every visual from CSS selectors on the input (:checked, :indeterminate, :focus-visible, :disabled) with ~ sibling combinators. Pass the accent through a --acb-c custom property.\n\nBox: size var, border 2px solid currentColor at 36% (color-mix), radius 30% of size. Hover (not checked): border to 66% and a 6% tint. Active: scale 0.86 over 0.12s, release on cubic-bezier(.34,1.56,.64,1) 0.45s. Checked: border and a soft 5px 16px -6px accent shadow. Fill layer inset -2px, accent, clip-path circle(0%) to circle(75%) in 0.38s cubic-bezier(.2,.8,.2,1) (0.16s ease-in back). Tick: SVG viewBox 24, path \"M6.2 12.8l3.8 3.8 7.8-9\", pathLength=1, stroke white 2.8 round caps, stroke-dasharray 1, dashoffset 1 to 0 in 0.3s cubic-bezier(.65,0,.35,1) with 0.1s delay (0.14s ease-in back). Indeterminate: same fill, a dash \"M7 12h10\" drawn the same way.\n\nCheck burst (only after mount; set a data-ready attribute in a requestAnimationFrame effect so a pre-checked box does not fire): box keyframe pop scale .86 / 1.14 / 1 over 0.5s; a ring (2px accent border, inset -2px) scaling 1 to 1.9 while fading from 0.6 over 0.6s; six 3px accent sparks at 20/80/140/200/260/320 degrees travelling from 0.5x to 1x the box size while shrinking and fading over 0.55s.\n\nstrike: label text gets a 2px line from a linear-gradient background-size 0% to 100% (0.36s, 0.1s delay) and the label dims to 0.48 opacity.\n\nFocus: outline 2px solid accent, offset 3px on the drawn box (:focus-visible on the input). On (pointer: coarse) the row is min-height 40px. disabled: opacity 0.45, cursor not-allowed. prefers-reduced-motion: no pop, ring, sparks or scale; transitions near-instant. Text and border follow currentColor so it works on light and dark pages.","license":"https://viberdy.dev/license"}}