{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "checkbox",
  "title": "Checkbox",
  "description": "A checkbox whose tick wipes in along its stroke, in reading order. In a group, a parent that selects all ticks its boxes one after another, top to bottom.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/choice.json",
    "https://kinoui.com/r/theme.json",
    "https://kinoui.com/r/refs.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/checkbox.tsx",
      "content": "'use client'\n\nimport {\n  choiceBoxClassName,\n  choiceCheckboxClassName,\n  choiceClassName,\n  choicePressHandlers,\n  choiceWipeClassName,\n} from '@/registry/lib/choice'\nimport { reducesMotion } from '@/registry/lib/reduce-motion'\nimport { mergeRefs } from '@/registry/lib/refs'\nimport {\n  Checkbox as CheckboxPrimitive,\n  CheckboxGroup as CheckboxGroupPrimitive,\n  CheckboxIndicator as CheckboxIndicatorPrimitive,\n} from '@ui-sdk/react/checkbox'\nimport { type ComponentProps, useMemo, useRef } from 'react'\n\nimport { cn } from '@/lib/utils'\n\nconst mark = cn(choiceWipeClassName, '[transition-delay:var(--checkbox-delay)]')\n\nfunction Checkbox({\n  className,\n  value,\n  onKeyDown,\n  onKeyUp,\n  onBlur,\n  ...props\n}: Omit<ComponentProps<typeof CheckboxPrimitive>, 'className' | 'children'> & {\n  className?: string\n}) {\n  return (\n    <CheckboxPrimitive\n      data-value={value}\n      value={value}\n      className={cn(\n        choiceClassName,\n        choiceBoxClassName,\n        choiceCheckboxClassName,\n        'group/checkbox',\n        // The cascade waits on the colours only, in choiceBoxClassName's order\n        // (background, border, ring, scale): a focus ring or a press answers at once.\n        '[--checkbox-cascade:var(--checkbox-order,0)] [--checkbox-delay:calc(var(--motion-press-duration)*0.35*var(--checkbox-cascade))] [transition-delay:var(--checkbox-delay),var(--checkbox-delay),0s,0s] motion-reduce:[--checkbox-cascade:0]',\n        className,\n      )}\n      {...choicePressHandlers({ onKeyDown, onKeyUp, onBlur })}\n      {...props}\n    >\n      <CheckboxIndicator />\n    </CheckboxPrimitive>\n  )\n}\n\n/** The tick and the dash inside a Checkbox's box, or a box of your own. */\nfunction CheckboxIndicator({\n  className,\n  ...props\n}: Omit<\n  ComponentProps<typeof CheckboxIndicatorPrimitive>,\n  'className' | 'keepMounted'\n> & {\n  className?: string\n}) {\n  return (\n    <CheckboxIndicatorPrimitive\n      keepMounted\n      className={cn('pointer-events-none flex items-center justify-center', className)}\n      {...props}\n    >\n      <CheckboxMark />\n    </CheckboxIndicatorPrimitive>\n  )\n}\n\n/**\n * The tick and the dash, wiping in along their stroke, inside an element\n * marked `group/checkbox` that carries the state: a Checkbox's box, or a\n * mark that shows a state but takes no press, such as a password's rule.\n */\nfunction CheckboxMark({ className }: { className?: string }) {\n  return (\n    <svg\n      viewBox='0 0 14 14'\n      fill='none'\n      stroke='currentColor'\n      strokeWidth={2}\n      strokeLinecap='round'\n      strokeLinejoin='round'\n      aria-hidden\n      className={cn(\n        'text-primary-foreground pointer-events-none size-3.5 overflow-visible forced-colors:text-[HighlightText]',\n        className,\n      )}\n    >\n      <path\n        d='M3 7.4 5.8 10.2 11 4.2'\n        className={cn(mark, 'group-data-checked/checkbox:[clip-path:inset(0_0_0_0)]!')}\n      />\n      <path\n        d='M3.5 7h7'\n        className={cn(\n          mark,\n          'group-data-indeterminate/checkbox:[clip-path:inset(0_0_0_0)]!',\n        )}\n      />\n    </svg>\n  )\n}\n\n/**\n * Where each box stands in a cascade: when one change ticks or clears more\n * than one box (a parent that selects all), the changed boxes are numbered in\n * reading order, so each one's mark wipes in a beat after the one before.\n * However many change, the last starts at most `CASCADE_STEPS` beats after the\n * first, so a long list still settles at once. A change to a single box\n * numbers none.\n */\nconst CASCADE_STEPS = 2\n\nfunction cascadeOrder(\n  boxes: readonly { value: string; checked: boolean }[],\n  next: readonly string[],\n): (number | null)[] {\n  const changed = boxes.map((box) => box.checked !== next.includes(box.value))\n  const count = changed.filter(Boolean).length\n  if (count < 2) return boxes.map(() => null)\n  const beat = Math.min(1, CASCADE_STEPS / (count - 1))\n  let order = 0\n  return changed.map((change) => (change ? order++ * beat : null))\n}\n\nconst inGroup = (element: Element | null, group: Element) =>\n  element?.closest('[data-slot=checkbox-group]') === group\n\n/** Numbers the boxes a change to `next` ticks or clears, so their marks wipe in one after another. */\nfunction cascade(group: HTMLElement, next: readonly string[]) {\n  if (reducesMotion(group)) return\n  const boxes = [\n    ...group.querySelectorAll<HTMLElement>('[data-slot=checkbox][data-value]'),\n  ].filter((box) => inGroup(box, group))\n  const order = cascadeOrder(\n    boxes.map((box) => ({\n      value: box.dataset.value ?? '',\n      checked: box.hasAttribute('data-checked'),\n    })),\n    next,\n  )\n  boxes.forEach((box, index) => {\n    const place = order[index]\n    if (place === null) box.style.removeProperty('--checkbox-order')\n    else box.style.setProperty('--checkbox-order', String(place))\n  })\n}\n\nfunction CheckboxGroup<T extends string = string>({\n  className,\n  onValueChange,\n  onTransitionEnd,\n  ref,\n  ...props\n}: Omit<ComponentProps<typeof CheckboxGroupPrimitive<T>>, 'className'> & {\n  className?: string\n}) {\n  const group = useRef<HTMLDivElement>(null)\n  const refs = useMemo(() => mergeRefs(group, ref), [ref])\n  return (\n    <CheckboxGroupPrimitive<T>\n      ref={refs}\n      className={cn('flex flex-col gap-3', className)}\n      onValueChange={(next, details) => {\n        if (group.current) cascade(group.current, next)\n        onValueChange?.(next, details)\n      }}\n      onTransitionEnd={(event) => {\n        if (event.propertyName === 'clip-path' && event.target instanceof Element) {\n          event.target\n            .closest<HTMLElement>('[data-slot=checkbox]')\n            ?.style.removeProperty('--checkbox-order')\n        }\n        onTransitionEnd?.(event)\n      }}\n      {...props}\n    />\n  )\n}\n\nexport { Checkbox, CheckboxGroup, CheckboxIndicator, CheckboxMark, cascadeOrder }\n",
      "type": "registry:component",
      "target": "@components/kino/checkbox.tsx"
    }
  ],
  "type": "registry:component"
}