{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "checkbox",
  "title": "Checkbox",
  "description": "Checkbox whose primary fill grows from the press point as the box rounds toward a circle and back, then the tick draws itself; tri-state with a pill.",
  "dependencies": [
    "@radix-ui/react-checkbox",
    "motion"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "utils",
    "https://reactmotionkit.com/r/motion-kit.json",
    "https://reactmotionkit.com/r/motion-presets.json",
    "https://reactmotionkit.com/r/beats.json"
  ],
  "files": [
    {
      "path": "ui/checkbox.tsx",
      "content": "\"use client\"\n\nimport * as CheckboxPrimitive from \"@radix-ui/react-checkbox\"\nimport {\n  AnimatePresence,\n  animate,\n  motion,\n  type Transition,\n  useMotionValue,\n  useTransform,\n} from \"motion/react\"\nimport {\n  type ComponentProps,\n  type PointerEvent,\n  type ReactNode,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from \"react\"\n\nimport { cascade, usePress, SMALL_SQUASH } from \"@/lib/beats\"\nimport { durations, type Temperament } from \"@/lib/motion\"\nimport { useMotionKit } from \"@/lib/motion-kit\"\nimport { cn } from \"@/lib/utils\"\n\n/** A spread on purpose: the shadcn CLI rewrites a literal `asChild` for Base UI projects. */\nconst slotted = { asChild: true } as const\n\nexport type CheckboxCheckedState = boolean | \"indeterminate\"\n\n/** Box geometry per size, in pixels: side, resting corner radius, tick stroke. */\nconst SIZES = {\n  sm: { side: 16, radius: 3, stroke: 1.75, hit: \"after:-inset-1\" },\n  md: { side: 18, radius: 4, stroke: 2, hit: \"after:-inset-[3px]\" },\n} as const\n\n/** The tick is drawn on an 18-unit grid and scaled to the box. */\nconst TICK_GRID = 18\nconst TICK_PATH = \"M4.75 9.25 7.75 12.25 13.25 6\"\n\n/*\n * A circle of this diameter, centred on the box, just covers its corners (the box's\n * diagonal). Grown from an off-centre press point it scales past 1 to still reach the\n * farthest corner.\n */\nconst SQRT2 = Math.SQRT2\n\n/*\n * How far the corners round toward a circle (share of the trip from the resting radius\n * to half the side) at the peak of the fill, which is halfway. A linear map of the\n * squash leaves lively at a 6 px corner on an 18 px box, too close to the 4 px rest to\n * read; lively needs about 70% of the trip to read as the box turning round. Calm keeps\n * the hint (15%), reduced motion squares (no shape change at all).\n */\nconst ROUNDING: Record<Temperament, number> = { calm: 0.15, lively: 0.7, playful: 1 }\n\n/*\n * The disc's radius follows the fill's progress raised to this power: it stays a\n * readable disc in the pressed corner for the first third of the spring, then sweeps\n * the box. Linear, it covered the box before the eye found where it started.\n */\nconst GROWTH_CURVE = 1.5\n\n/*\n * The settle overshoot of the box lasts two fill-lengths and peaks halfway, as the\n * fill completes: the box swells once the circle has reached the corners, not before.\n */\nconst SETTLE_LENGTH = 2\nconst SETTLE_PEAK = 0.5\n\n/*\n * A path drawn below 2% of its length is only its round caps, a dot: the tick stays\n * hidden until it is clearly drawing.\n */\nconst DOT_THRESHOLD = 0.02\n\n/*\n * Trace and pill start once the fill is under way, at 40% of it, and leave in the first\n * 40% of the way back (the same share as the cascade's exit in lib/beats).\n */\nconst TRACE_SHARE = 0.4\n\n/* The indeterminate pill is 60% of the box wide: short enough to read as \"some\". */\nconst PILL_WIDTH = 0.6\n\n/*\n * With a `ratio`, the pill runs from 28% of the box (one row of many) to 72% (all but\n * one): the ends stay clear of a dot and of the full stretch that means \"all\".\n */\nconst PILL_MIN = 0.28\nconst PILL_MAX = 0.72\n\n/*\n * Refuse kick: how far the box swings sideways, in pixels. The temperament's squash is\n * a fraction of an 18 px box (0.3 px calm), too small to read as \"no\"; a kick needs a\n * couple of pixels at every temperament, so the amount is set per temperament here.\n * Each swing back is this share of the previous one (a damped shake: no, no, no).\n */\nconst KICK_PX: Record<Temperament, number> = { calm: 1.5, lively: 2.5, playful: 3.5 }\nconst KICK_DAMPING = 0.55\n\n/*\n * Children checked by a \"select all\" parent follow one stagger step apart; past twelve\n * rows (a table page) the rest arrive with the twelfth so the eye is never kept waiting.\n */\nconst CASCADE_CAP = 12\n\n/** Perceived duration of a Motion spring transition, or `fallback` (reduced motion's fade). */\nfunction perceived(transition: Transition, fallback: number) {\n  return \"visualDuration\" in transition && typeof transition.visualDuration === \"number\"\n    ? transition.visualDuration\n    : fallback\n}\n\nconst clamp01 = (value: number) => Math.min(Math.max(value, 0), 1)\n\nexport interface CheckboxProps extends Omit<\n  ComponentProps<typeof CheckboxPrimitive.Root>,\n  \"asChild\" | \"children\" | \"checked\" | \"defaultChecked\" | \"onCheckedChange\"\n> {\n  /** Controlled state: `true`, `false` or `\"indeterminate\"`. */\n  checked?: CheckboxCheckedState\n  /** Uncontrolled initial state. */\n  defaultChecked?: CheckboxCheckedState\n  /** Fires on toggle, after the internal state update. */\n  onCheckedChange?: (checked: CheckboxCheckedState) => void\n  /** Box size: `sm` for tables and dense lists, `md` for forms and settings. */\n  size?: keyof typeof SIZES\n  /**\n   * Position in a \"select all\" group. A check caused by the parent waits one stagger\n   * step per index (capped at 12); the checkbox's own press never waits.\n   */\n  cascadeIndex?: number\n  /**\n   * Draw the tick once on mount when the box starts checked (an entrance trace, one\n   * `cascadeIndex` step apart). The state is correct from the first frame; only the\n   * stroke replays.\n   */\n  appear?: boolean\n  /**\n   * Error look: the rim and halo turn `destructive` and `aria-invalid` is set. Turning it\n   * on kicks the box sideways once (the refuse beat). Defaults to the `aria-invalid` prop.\n   */\n  invalid?: boolean\n  /**\n   * Change it (a submit attempt count, say) to replay the refuse kick while `invalid`.\n   */\n  refuseKey?: number | string\n  /**\n   * Share of the group that is selected, 0 to 1. While indeterminate, the pill's length\n   * follows it: a \"select all\" header shows how much of the list is ticked.\n   */\n  ratio?: number\n  /** Motion intensity (how much it moves): calm, lively or playful. Wins over `MotionKitProvider`. */\n  temperament?: Temperament\n}\n\n/** Pill length (share of the box) for a ratio, or the default \"some\" length. */\nfunction pillLength(ratio: number | undefined) {\n  return ratio === undefined ? PILL_WIDTH : PILL_MIN + (PILL_MAX - PILL_MIN) * clamp01(ratio)\n}\n\n/**\n * Checkbox whose fill is a shape change. Pressing sinks the box under the finger;\n * checking grows a `primary` circle from the press point while the corners round toward\n * a circle and square back, the tick draws itself and the box settles with a small\n * overshoot. Indeterminate is a short pill that stretches into the fill when checked.\n * Built on Radix Checkbox: a real `role=\"checkbox\"` button with labels and forms.\n */\nexport function Checkbox({\n  size = \"md\",\n  temperament,\n  cascadeIndex,\n  appear = false,\n  invalid: invalidProp,\n  refuseKey,\n  ratio,\n  \"aria-invalid\": ariaInvalid,\n  checked: checkedProp,\n  defaultChecked = false,\n  onCheckedChange,\n  disabled,\n  className,\n  style,\n  onPointerDown,\n  onPointerUp,\n  onPointerLeave,\n  onPointerCancel,\n  onKeyDown,\n  onKeyUp,\n  onBlur,\n  ...props\n}: CheckboxProps) {\n  const m = useMotionKit(temperament)\n  const [internal, setInternal] = useState<CheckboxCheckedState>(defaultChecked)\n  const checked = checkedProp ?? internal\n  const geometry = SIZES[size]\n  const { side } = geometry\n  const filled = checked !== false\n  const ticked = checked === true\n  const indeterminate = checked === \"indeterminate\"\n  const invalid = invalidProp ?? (ariaInvalid === true || ariaInvalid === \"true\")\n  // The pill element is PILL_MAX of the box wide; its scale sets the visible length.\n  const pillTarget = pillLength(ratio) / PILL_MAX\n\n  // True when the last change came from this box (press, Space, label): it never waits.\n  const selfCaused = useRef(false)\n\n  // Press point as a fraction of the box (0.5 = centre, the keyboard's origin).\n  const originX = useMotionValue(0.5)\n  const originY = useMotionValue(0.5)\n\n  // One timeline: the fill's progress drives the circle, the corners and the glow.\n  const fill = useMotionValue(filled ? 1 : 0)\n  const cover = useMotionValue(1)\n  const fillX = useMotionValue(0)\n  const fillY = useMotionValue(0)\n  const fillOpacity = useMotionValue(1)\n  const fillScale = useTransform(\n    [fill, cover],\n    ([p = 0, c = 1]: number[]) => Math.sign(p) * Math.abs(p) ** GROWTH_CURVE * c,\n  )\n  const roundAmount = m.reduced ? 0 : ROUNDING[m.temperament] * (side / 2 - geometry.radius)\n  const radius = useTransform(\n    fill,\n    (p) => geometry.radius + roundAmount * Math.sin(Math.PI * clamp01(p)),\n  )\n  const glowOpacity = useTransform(\n    [fill, fillOpacity],\n    ([p = 0, o = 1]: number[]) => clamp01(p) * o,\n  )\n\n  const scale = useMotionValue(1)\n  const [drawOnMount] = useState(() => appear && ticked)\n  const tick = useMotionValue(ticked && !drawOnMount ? 1 : 0)\n  const tickFade = useMotionValue(1)\n  // Both values are explicit inputs, so a fade alone (reduced motion) updates the tick.\n  const tickOpacity = useTransform([tick, tickFade], ([drawn = 0, faded = 1]: number[]) =>\n    drawn > DOT_THRESHOLD ? faded : 0,\n  )\n  const pillScale = useMotionValue(indeterminate ? pillTarget : 0)\n  const pillOpacity = useMotionValue(indeterminate ? 1 : 0)\n\n  const press = usePress<HTMLButtonElement>({\n    disabled,\n    keys: [\" \"],\n    onPointerDown: (event) => {\n      if (event.button === 0 && !disabled) setOrigin(event)\n      onPointerDown?.(event)\n    },\n    onPointerUp,\n    onPointerLeave: (event) => {\n      centreOrigin()\n      onPointerLeave?.(event)\n    },\n    onPointerCancel: (event) => {\n      centreOrigin()\n      onPointerCancel?.(event)\n    },\n    onKeyDown: (event) => {\n      if (event.key === \" \") centreOrigin()\n      onKeyDown?.(event)\n    },\n    onKeyUp,\n    onBlur,\n  })\n  const { pressed } = press\n\n  function setOrigin(event: PointerEvent<HTMLButtonElement>) {\n    const rect = event.currentTarget.getBoundingClientRect()\n    if (rect.width === 0 || rect.height === 0) return\n    originX.set(clamp01((event.clientX - rect.left) / rect.width))\n    originY.set(clamp01((event.clientY - rect.top) / rect.height))\n  }\n\n  function centreOrigin() {\n    originX.set(0.5)\n    originY.set(0.5)\n  }\n\n  // Charge: the box sinks toward the press point; release springs it back.\n  const sinkTo = 1 - m.values.squash * SMALL_SQUASH\n  useEffect(() => {\n    const controls = animate(scale, pressed ? sinkTo : 1, m.springSmall)\n    return () => {\n      controls.stop()\n    }\n  }, [pressed, sinkTo, scale, m.springSmall])\n\n  // Refuse: when the box turns invalid (or `refuseKey` changes while it is), it swings\n  // sideways and back, squashed on the first swing. Reduced motion keeps only the rim.\n  const kickX = useMotionValue(0)\n  const kickSquash = useMotionValue(1)\n  const refused = useRef({ invalid, key: refuseKey })\n  useEffect(() => {\n    const before = refused.current\n    refused.current = { invalid, key: refuseKey }\n    if (!invalid || m.reduced || (before.invalid && before.key === refuseKey)) return\n    const a = KICK_PX[m.temperament]\n    const d = KICK_DAMPING\n    const timing = { duration: m.seconds(m.values.duration), ease: \"easeOut\" as const }\n    const squashed = 1 - m.values.squash * SMALL_SQUASH\n    const runs = [\n      animate(kickX, [0, -a, a * d, -a * d * d, 0], timing),\n      animate(kickSquash, [1, squashed, 1, 1, 1], timing),\n    ]\n    return () => {\n      for (const run of runs) run.stop()\n    }\n  }, [invalid, refuseKey, m, kickX, kickSquash])\n\n  // Entrance trace: the tick of a box that starts checked draws itself once.\n  const reducedOnMount = m.reduced\n  const tweenOnMount = m.tween\n  const appearDelay = m.staggerDelay(Math.min(cascadeIndex ?? 0, CASCADE_CAP))\n  useEffect(() => {\n    if (!drawOnMount) return\n    if (reducedOnMount) {\n      tick.set(1)\n      return\n    }\n    const run = animate(tick, 1, { ...tweenOnMount, delay: appearDelay })\n    return () => {\n      run.stop()\n    }\n    // Runs once on mount by design: later changes go through the effect below.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [])\n\n  // Action and settle, all parts on one schedule from the same delay. A new change\n  // retargets every motion value from where it is; the runs stop only on unmount.\n  const previous = useRef(checked)\n  const previousPill = useRef(pillTarget)\n  const runs = useRef<{ stop: () => void }[]>([])\n  useEffect(\n    () => () => {\n      for (const run of runs.current) run.stop()\n    },\n    [],\n  )\n  useEffect(() => {\n    const from = previous.current\n    previous.current = checked\n    const pillFrom = previousPill.current\n    previousPill.current = pillTarget\n    if (from === checked) {\n      // Same state, new ratio: the pill grows or shrinks to the new share.\n      if (indeterminate && pillFrom !== pillTarget) {\n        if (m.reduced) pillScale.set(pillTarget)\n        else runs.current.push(animate(pillScale, pillTarget, m.springSmall))\n      }\n      return\n    }\n    const own = selfCaused.current\n    selfCaused.current = false\n\n    const wasFilled = from !== false\n    const delay =\n      !own && filled && !wasFilled && cascadeIndex !== undefined\n        ? m.staggerDelay(Math.min(cascadeIndex, CASCADE_CAP))\n        : 0\n    const fillTime = perceived(m.spring, m.seconds(durations.fade))\n    const exitTime = perceived(m.springSmall, m.seconds(durations.fade))\n    const traceDelay = delay + fillTime * TRACE_SHARE\n    const exit = { duration: exitTime * TRACE_SHARE, ease: \"easeIn\" as const }\n    const next: { stop: () => void }[] = []\n    runs.current = next\n\n    if (m.reduced) {\n      // Crossfade at full size, square corners, the tick whole.\n      if (!wasFilled) fillOpacity.set(0)\n      if (from !== true) tickFade.set(0)\n      fill.set(1)\n      cover.set(1)\n      fillX.set(0)\n      fillY.set(0)\n      tick.set(1)\n      pillScale.set(pillTarget)\n      next.push(\n        animate(fillOpacity, filled ? 1 : 0, m.fade),\n        animate(tickFade, ticked ? 1 : 0, m.fade),\n        animate(pillOpacity, indeterminate ? 1 : 0, m.fade),\n      )\n    } else {\n      fillOpacity.set(1)\n      tickFade.set(1)\n      if (filled && !wasFilled) {\n        // Grow from the press point: the circle's scale reaches the farthest corner.\n        const px = originX.get() * side\n        const py = originY.get() * side\n        const far = Math.hypot(Math.max(px, side - px), Math.max(py, side - py))\n        fill.set(0)\n        fillX.set(px - side / 2)\n        fillY.set(py - side / 2)\n        cover.set(far / (side / SQRT2))\n        // The disc crosses the whole diagonal from the press point: on the small spring it\n        // covers the box in under 0.1 s and the growth never reads, so it rides the main\n        // spring (a box-length move, like a thumb's travel), still interruptible.\n        next.push(animate(fill, 1, { ...m.spring, delay }))\n        // Settle: a small overshoot of the whole box (none where the spring has no bounce),\n        // peaking as the fill completes and resting one fill-length later.\n        const over = m.values.bounce > 0 ? m.values.squash : 0\n        next.push(\n          animate(scale, [scale.get(), 1 + over, 1], {\n            duration: fillTime * SETTLE_LENGTH,\n            times: [0, SETTLE_PEAK, 1],\n            ease: \"easeOut\",\n            delay,\n          }),\n        )\n      } else if (!filled && wasFilled) {\n        // Shrink to the centre.\n        next.push(\n          animate(fill, 0, m.springSmall),\n          animate(fillX, 0, m.springSmall),\n          animate(fillY, 0, m.springSmall),\n          animate(cover, 1, m.springSmall),\n        )\n      }\n\n      if (ticked) {\n        // From indeterminate the pill clears in the first 40%; the tick starts after it.\n        next.push(animate(tick, 1, { ...m.tween, delay: traceDelay }))\n      } else {\n        next.push(animate(tick, 0, exit))\n      }\n\n      if (indeterminate) {\n        pillOpacity.set(1)\n        next.push(\n          animate(pillScale, pillTarget, { ...m.tween, delay: wasFilled ? delay : traceDelay }),\n        )\n      } else if (from === \"indeterminate\" && ticked) {\n        // The pill stretches into the full fill and is gone before the tick starts.\n        next.push(\n          animate(pillScale, 1 / PILL_MAX, { ...exit, ease: \"easeOut\" }),\n          animate(pillOpacity, 0, exit),\n        )\n      } else {\n        next.push(animate(pillScale, 0, exit))\n      }\n    }\n  }, [\n    checked,\n    filled,\n    ticked,\n    indeterminate,\n    pillTarget,\n    cascadeIndex,\n    side,\n    m,\n    fill,\n    cover,\n    fillX,\n    fillY,\n    fillOpacity,\n    scale,\n    tick,\n    tickFade,\n    pillScale,\n    pillOpacity,\n    originX,\n    originY,\n  ])\n\n  return (\n    <CheckboxPrimitive.Root\n      data-slot=\"checkbox\"\n      data-size={size}\n      data-pressed={pressed || undefined}\n      data-temperament={m.temperament}\n      aria-invalid={invalid || undefined}\n      checked={checked}\n      disabled={disabled}\n      onCheckedChange={(next) => {\n        selfCaused.current = true\n        if (checkedProp === undefined) setInternal(next)\n        onCheckedChange?.(next)\n      }}\n      {...press.handlers}\n      className={cn(\n        \"group/checkbox relative inline-flex shrink-0 cursor-pointer outline-none\",\n        size === \"sm\" ? \"rounded-[3px]\" : \"rounded-[4px]\",\n        // A 24px hit area (WCAG 2.5.8) without growing the box.\n        \"after:absolute after:content-['']\",\n        geometry.hit,\n        \"transition-[box-shadow] ease-out focus-visible:ring-[3px] focus-visible:ring-ring/50\",\n        \"disabled:cursor-not-allowed\",\n        // Rim colour: input pulled toward foreground for 3:1 at rest, further on hover.\n        \"[--checkbox-rim-width:1px] [--checkbox-rim:color-mix(in_oklch,var(--input),var(--foreground)_40%)]\",\n        \"hover:[--checkbox-rim:color-mix(in_oklch,var(--input),var(--foreground)_62%)]\",\n        \"aria-invalid:[--checkbox-rim:var(--destructive)]\",\n        \"disabled:[--checkbox-rim:var(--border)]\",\n        className,\n      )}\n      style={{\n        width: side,\n        height: side,\n        transitionDuration: `${String(m.seconds(durations.micro))}s`,\n        ...style,\n      }}\n      {...props}\n    >\n      {/* Hover, focus and touch halo: grows from behind the box to 1.6x its size. */}\n      <span\n        aria-hidden\n        data-slot=\"checkbox-halo\"\n        className={cn(\n          \"pointer-events-none absolute -inset-[30%] scale-50 rounded-full bg-foreground/8 opacity-0 transition-[transform,opacity,background-color] ease-out\",\n          \"group-data-[state=checked]/checkbox:bg-primary/15 group-data-[state=indeterminate]/checkbox:bg-primary/15\",\n          \"group-aria-invalid/checkbox:bg-destructive/15\",\n          \"group-hover/checkbox:scale-100 group-hover/checkbox:opacity-100\",\n          \"group-focus-visible/checkbox:scale-100 group-focus-visible/checkbox:opacity-100\",\n          \"group-data-pressed/checkbox:scale-100 group-data-pressed/checkbox:opacity-100\",\n          // Table rows marked `data-checkbox-row` show the halo while the row is hovered.\n          \"[[data-checkbox-row]:hover_&]:scale-100 [[data-checkbox-row]:hover_&]:opacity-100\",\n          \"group-disabled/checkbox:hidden\",\n        )}\n        style={{ transitionDuration: `${String(m.seconds(durations.micro))}s` }}\n      />\n      {/* Charge and settle: the whole box scales from the press point. */}\n      <motion.span\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0\"\n        style={{ scale, originX, originY, x: kickX, scaleX: kickSquash }}\n      >\n        {/* Tinted shadow under the checked box, following the fill. */}\n        <motion.span\n          className=\"absolute inset-0 shadow-[0_2px_6px_-1px_color-mix(in_oklch,var(--primary)_35%,transparent)] group-disabled/checkbox:hidden\"\n          style={{ borderRadius: radius, opacity: glowOpacity }}\n        />\n        <CheckboxPrimitive.Indicator forceMount {...slotted}>\n          <motion.span\n            data-slot=\"checkbox-box\"\n            className={cn(\n              \"absolute inset-0 isolate overflow-hidden bg-background\",\n              \"shadow-[inset_0_0_0_var(--checkbox-rim-width)_var(--checkbox-rim),inset_0_1px_1px_rgb(0_0_0/0.08)] dark:shadow-[inset_0_0_0_var(--checkbox-rim-width)_var(--checkbox-rim),inset_0_1px_1px_rgb(0_0_0/0.3)]\",\n              \"transition-[box-shadow,background-color] ease-out\",\n              \"group-disabled/checkbox:bg-muted\",\n            )}\n            style={{\n              borderRadius: radius,\n              transitionDuration: `${String(m.seconds(durations.micro))}s`,\n            }}\n          >\n            {/* The fill: a circle grown from the press point until it covers the box. */}\n            <motion.span\n              data-slot=\"checkbox-fill\"\n              className=\"absolute top-1/2 left-1/2 rounded-full bg-primary group-disabled/checkbox:bg-muted-foreground\"\n              style={{\n                width: side * SQRT2,\n                height: side * SQRT2,\n                marginLeft: (-side * SQRT2) / 2,\n                marginTop: (-side * SQRT2) / 2,\n                x: fillX,\n                y: fillY,\n                scale: fillScale,\n                opacity: fillOpacity,\n              }}\n            />\n            {/* Top highlight and bottom shade on the fill: the checked box has a lit face. */}\n            <motion.span\n              aria-hidden\n              className=\"absolute inset-0 rounded-[inherit] shadow-[inset_0_1px_0_rgb(255_255_255/0.22),inset_0_-1px_0_rgb(0_0_0/0.1)] group-disabled/checkbox:hidden dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.4),inset_0_-1px_0_rgb(0_0_0/0.08)]\"\n              style={{ opacity: glowOpacity }}\n            />\n            {/* Indeterminate: a short capsule, 2px tall with real 1px radii. */}\n            <motion.span\n              data-slot=\"checkbox-pill\"\n              className=\"absolute top-1/2 left-1/2 h-0.5 rounded-[1px] bg-primary-foreground group-disabled/checkbox:bg-background\"\n              style={{\n                width: side * PILL_MAX,\n                marginLeft: (-side * PILL_MAX) / 2,\n                marginTop: -1,\n                scaleX: pillScale,\n                opacity: pillOpacity,\n              }}\n            />\n            <svg\n              viewBox={`0 0 ${String(TICK_GRID)} ${String(TICK_GRID)}`}\n              fill=\"none\"\n              className=\"absolute inset-0 size-full text-primary-foreground group-disabled/checkbox:text-background\"\n            >\n              <motion.path\n                d={TICK_PATH}\n                stroke=\"currentColor\"\n                strokeWidth={(geometry.stroke * TICK_GRID) / side}\n                strokeLinecap=\"round\"\n                strokeLinejoin=\"round\"\n                style={{ pathLength: tick, opacity: tickOpacity }}\n              />\n            </svg>\n          </motion.span>\n        </CheckboxPrimitive.Indicator>\n      </motion.span>\n    </CheckboxPrimitive.Root>\n  )\n}\n\nexport interface CheckboxFieldProps extends Omit<CheckboxProps, \"className\"> {\n  /** The visible label: names the checkbox. */\n  label: ReactNode\n  /** Help text under the label, linked with `aria-describedby`. */\n  description?: ReactNode\n  /**\n   * Error message under the label. When set the box is `invalid` (destructive rim, refuse\n   * kick) and the message is linked with `aria-describedby`.\n   */\n  error?: ReactNode\n  /** Classes for the row. */\n  className?: string\n  /** Classes for the checkbox itself. */\n  checkboxClassName?: string\n}\n\n/**\n * A checkbox with its label, description and error in one row. The whole row is the hit\n * target (at least 44 px tall for touch) and shows the box's halo on hover; the error\n * rises under the label without a bounce.\n */\nexport function CheckboxField({\n  label,\n  description,\n  error,\n  id: idProp,\n  className,\n  checkboxClassName,\n  invalid,\n  temperament,\n  disabled,\n  \"aria-describedby\": describedByProp,\n  ...props\n}: CheckboxFieldProps) {\n  const m = useMotionKit(temperament)\n  const autoId = useId()\n  const id = idProp ?? autoId\n  const hasError = error !== undefined && error !== null && error !== false\n  const describedBy =\n    [\n      describedByProp,\n      description ? `${id}-description` : undefined,\n      hasError ? `${id}-error` : undefined,\n    ]\n      .filter(Boolean)\n      .join(\" \") || undefined\n  const rise = cascade(m, 0, { after: 0 })\n\n  return (\n    <div\n      data-slot=\"checkbox-field\"\n      data-checkbox-row\n      data-disabled={disabled ? true : undefined}\n      data-invalid={hasError || invalid === true ? true : undefined}\n      className={cn(\n        \"relative flex min-h-11 items-start gap-3 rounded-xl px-3 py-2.5 transition-colors ease-out\",\n        \"hover:bg-muted/60 data-disabled:hover:bg-transparent\",\n        className,\n      )}\n      style={{ transitionDuration: `${String(m.seconds(durations.micro))}s` }}\n    >\n      {/* The box sits on the first line of the label (20 px) and above the row's hit area. */}\n      <span className=\"relative z-10 flex h-5 shrink-0 items-center\">\n        <Checkbox\n          id={id}\n          temperament={temperament}\n          disabled={disabled}\n          invalid={invalid ?? (hasError || undefined)}\n          aria-describedby={describedBy}\n          className={checkboxClassName}\n          {...props}\n        />\n      </span>\n      <div className=\"min-w-0 flex-1\">\n        <label\n          htmlFor={id}\n          className={cn(\n            \"block cursor-pointer text-sm leading-5 font-medium text-foreground\",\n            // Stretched over the row: a press anywhere on it toggles the box.\n            \"after:absolute after:inset-0 after:rounded-[inherit] after:content-['']\",\n            disabled && \"cursor-not-allowed text-muted-foreground\",\n          )}\n        >\n          {label}\n        </label>\n        {description ? (\n          <p id={`${id}-description`} className=\"mt-0.5 text-xs leading-5 text-muted-foreground\">\n            {description}\n          </p>\n        ) : null}\n        <div aria-live=\"polite\">\n          <AnimatePresence initial={false}>\n            {hasError ? (\n              <motion.p\n                key=\"error\"\n                id={`${id}-error`}\n                initial={rise.initial}\n                animate={rise.animate}\n                exit={rise.exit}\n                // Errors never bounce: the cascade's timing on the calm spring.\n                transition={m.reduced ? rise.transition : m.springCalm}\n                className=\"pointer-events-none mt-1 flex items-start gap-1.5 text-xs leading-5 text-destructive\"\n              >\n                <svg\n                  viewBox=\"0 0 16 16\"\n                  fill=\"none\"\n                  stroke=\"currentColor\"\n                  strokeWidth=\"1.5\"\n                  strokeLinecap=\"round\"\n                  aria-hidden\n                  className=\"mt-0.5 size-4 shrink-0\"\n                >\n                  <circle cx=\"8\" cy=\"8\" r=\"6.25\" />\n                  <path d=\"M8 5v3.5M8 11h.01\" />\n                </svg>\n                <span className=\"min-w-0\">{error}</span>\n              </motion.p>\n            ) : null}\n          </AnimatePresence>\n        </div>\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "tier": "free",
    "collection": "interface",
    "needsImage": false,
    "addedAt": "2026-10-16",
    "tags": [
      "checkbox",
      "form",
      "field",
      "table",
      "selection",
      "tri-state",
      "bulk-actions"
    ],
    "triggers": [
      "toggle",
      "press"
    ],
    "wave": "1",
    "tech": [],
    "presets": [],
    "keyboard": [
      {
        "keys": "Space",
        "action": "Toggles the checkbox (the box sinks while the key is down); indeterminate becomes checked"
      },
      {
        "keys": "Tab",
        "action": "Moves focus to and from the checkbox"
      },
      {
        "keys": "Enter",
        "action": "Does nothing on the checkbox (WAI-ARIA); submits the form natively"
      }
    ],
    "reducedMotion": "The primary fill and the tick crossfade in at full size with square corners: no sink, no growth from the press point, no overshoot, no refuse kick (the destructive rim stays), and select-all checks the children together.",
    "heavy": false,
    "ai": {
      "summary": "Checkbox with tri-state support for forms and table selection",
      "useCases": [
        "Accept required terms in a form, with an error state",
        "Select rows in a table, with a select-all header",
        "Pick columns with a select-all parent",
        "Single labelled options in a form"
      ],
      "whenToUse": "Use for a choice applied when a form is submitted, for selecting table rows, and for a tri-state select-all parent. CheckboxField adds label, description and error.",
      "whenNotToUse": "For an instant on/off setting use `switch`. For exactly one choice among several use `radio-group`.",
      "pairsWith": [
        "radio-group",
        "switch",
        "data-table",
        "form"
      ],
      "contexts": [
        "forms",
        "dashboard",
        "saas-app",
        "data"
      ],
      "keywords": [
        "checkbox",
        "check",
        "tick",
        "tri-state",
        "indeterminate",
        "select all",
        "terms",
        "form"
      ],
      "triggers": [
        "click",
        "focus",
        "value"
      ]
    }
  },
  "categories": [
    "controls"
  ],
  "type": "registry:ui"
}