{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "base-checkbox",
  "title": "Base Checkbox",
  "description": "An accessible, stylable checkbox built on Base UI with a Motion-friendly animated indicator.",
  "dependencies": ["@base-ui/react", "motion"],
  "registryDependencies": ["utils", "@soralabs/hooks-use-controlled-state"],
  "files": [
    {
      "path": "registry/ui/base/checkbox/index.tsx",
      "content": "\"use client\";\n\nimport { Checkbox as CheckboxPrimitive } from \"@base-ui/react/checkbox\";\nimport { useControlledState } from \"@/hooks/use-controlled-state\";\nimport { cn } from \"@/lib/utils\";\nimport {\n  motion,\n  useMotionValue,\n  useReducedMotion,\n  useTransform,\n} from \"motion/react\";\nimport type * as React from \"react\";\nimport { useId } from \"react\";\n\ninterface CheckboxCheckIconProps extends Omit<\n  React.ComponentProps<\"svg\">,\n  \"children\"\n> {\n  /** Whether the checkbox checkmark is active. */\n  checked: boolean;\n  /** Whether reduced motion is enabled. */\n  prefersReducedMotion?: boolean | null;\n}\n\n/**\n * Checkmark SVG icon featuring animated path length draw with dynamic round cap transform.\n */\nfunction CheckboxCheckIcon({\n  checked,\n  className,\n  prefersReducedMotion,\n  ...props\n}: CheckboxCheckIconProps) {\n  const pathLength = useMotionValue(checked ? 1 : 0);\n  const strokeLinecap = useTransform(() =>\n    pathLength.get() === 0 ? \"none\" : \"round\"\n  );\n\n  return (\n    <svg\n      aria-hidden=\"true\"\n      className={cn(\"size-3.5 stroke-current\", className)}\n      fill=\"none\"\n      stroke=\"currentColor\"\n      strokeWidth=\"3\"\n      viewBox=\"0 0 24 24\"\n      {...props}\n    >\n      <motion.path\n        animate={{ pathLength: checked ? 1 : 0 }}\n        d=\"M4 12L10 18L20 6\"\n        style={\n          {\n            pathLength,\n            strokeLinecap,\n          } as React.ComponentProps<typeof motion.path>[\"style\"]\n        }\n        transition={\n          prefersReducedMotion\n            ? { duration: 0 }\n            : {\n                type: \"spring\",\n                bounce: 0,\n                duration: checked ? 0.3 : 0.1,\n              }\n        }\n      />\n    </svg>\n  );\n}\n\ntype CheckboxRootProps = React.ComponentProps<typeof CheckboxPrimitive.Root>;\n\n/**\n * Primitive root button for the checkbox component, wrapping Base UI's Checkbox.Root with Motion interaction states.\n * Supports full Tailwind CSS class overriding via `cn(...)`.\n */\nfunction CheckboxRoot({ className, render, ...props }: CheckboxRootProps) {\n  const prefersReducedMotion = useReducedMotion();\n\n  return (\n    <CheckboxPrimitive.Root\n      className={cn(\n        \"peer border-input focus-visible:border-ring focus-visible:ring-ring/50 group-has-[:focus-visible]/field-label:not-data-checked:border-input aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:bg-input/30 dark:data-checked:bg-primary dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 relative flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-[4px] border transition-colors outline-none group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3\",\n        className\n      )}\n      data-slot=\"checkbox\"\n      render={\n        render ?? (\n          <motion.button\n            data-primary-action\n            type=\"button\"\n            whileHover={prefersReducedMotion ? undefined : { scale: 1.05 }}\n            whileTap={prefersReducedMotion ? undefined : { scale: 0.95 }}\n          />\n        )\n      }\n      {...props}\n    />\n  );\n}\n\ntype CheckboxIndicatorProps = React.ComponentProps<\n  typeof CheckboxPrimitive.Indicator\n> & {\n  /** Additional CSS classes for the indicator SVG */\n  className?: string;\n};\n\n/**\n * Animated checkmark indicator for the checkbox using Motion path length animation.\n */\nfunction CheckboxIndicator({ className, ...props }: CheckboxIndicatorProps) {\n  const prefersReducedMotion = useReducedMotion();\n\n  return (\n    <CheckboxPrimitive.Indicator\n      className={cn(\n        \"grid place-content-center text-current transition-none [&>svg]:size-3.5\",\n        className\n      )}\n      data-slot=\"checkbox-indicator\"\n      keepMounted\n      render={(indicatorProps, state) => (\n        <CheckboxCheckIcon\n          checked={Boolean(state.checked)}\n          className={className}\n          prefersReducedMotion={prefersReducedMotion}\n          {...indicatorProps}\n        />\n      )}\n      {...props}\n    />\n  );\n}\n\ninterface CheckboxProps extends Omit<CheckboxRootProps, \"render\"> {\n  /**\n   * Optional class name for the animated checkmark SVG indicator.\n   */\n  indicatorClassName?: string;\n  /**\n   * Optional label rendered beside the checkbox (wraps both in a `<label>`).\n   */\n  label?: React.ReactNode;\n  /**\n   * Optional class name for the outer label wrapper.\n   */\n  labelClassName?: string;\n}\n\n/**\n * An accessible, stylable animated Checkbox component built with Base UI and Motion for React.\n * Supports full Tailwind CSS class overrides just like shadcn/ui.\n */\nfunction Checkbox({\n  checked: controlledChecked,\n  defaultChecked = false,\n  onCheckedChange,\n  label,\n  labelClassName,\n  indicatorClassName,\n  className,\n  id,\n  ref,\n  disabled,\n  ...props\n}: CheckboxProps) {\n  const generatedId = useId();\n  const inputId = id ?? generatedId;\n\n  const [isChecked, setIsChecked] = useControlledState({\n    defaultValue: defaultChecked,\n    onChange: onCheckedChange,\n    value: controlledChecked,\n  });\n\n  const prefersReducedMotion = useReducedMotion();\n\n  const control = (\n    <CheckboxPrimitive.Root\n      checked={isChecked}\n      className={cn(\n        \"peer border-input focus-visible:border-ring focus-visible:ring-ring/50 group-has-[:focus-visible]/field-label:not-data-checked:border-input aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:bg-input/30 dark:data-checked:bg-primary dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 relative flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-[4px] border transition-colors outline-none group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3\",\n        className\n      )}\n      data-slot=\"checkbox\"\n      disabled={disabled}\n      id={inputId}\n      onCheckedChange={setIsChecked}\n      ref={ref}\n      render={\n        <motion.button\n          data-primary-action\n          type=\"button\"\n          whileHover={prefersReducedMotion ? undefined : { scale: 1.05 }}\n          whileTap={prefersReducedMotion ? undefined : { scale: 0.95 }}\n        >\n          <CheckboxCheckIcon\n            checked={isChecked}\n            className={indicatorClassName}\n            prefersReducedMotion={prefersReducedMotion}\n          />\n        </motion.button>\n      }\n      {...props}\n    />\n  );\n\n  if (label === null || label === undefined) {\n    return control;\n  }\n\n  return (\n    <div className=\"inline-flex items-center gap-2.5\">\n      {control}\n      <label\n        className={cn(\n          \"cursor-pointer text-sm leading-none font-medium select-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\",\n          disabled && \"cursor-not-allowed opacity-50\",\n          labelClassName\n        )}\n        htmlFor={inputId}\n      >\n        {label}\n      </label>\n    </div>\n  );\n}\n\nexport type {\n  CheckboxCheckIconProps,\n  CheckboxIndicatorProps,\n  CheckboxProps,\n  CheckboxRootProps,\n};\nexport {\n  Checkbox,\n  Checkbox as BaseCheckbox,\n  Checkbox as default,\n  CheckboxCheckIcon,\n  CheckboxIndicator,\n  CheckboxRoot,\n};\n",
      "type": "registry:ui",
      "target": "components/sora-ui/base/checkbox.tsx"
    }
  ],
  "meta": {
    "agentMetadata": {
      "intent": "Toggle an independent boolean setting.",
      "role": "input",
      "a11yConstraints": [
        "Preserve the checkbox role, label association, and keyboard toggling."
      ],
      "motionEngine": "Motion checkmark and elastic scale feedback.",
      "compositionRules": [
        "Pair with a visible label and optional description."
      ],
      "compositionRecipes": ["Compose with base/button in a settings form."]
    },
    "demoProps": {
      "Checkbox": {
        "label": {
          "value": "Accept terms and conditions"
        },
        "disabled": {
          "value": false
        }
      }
    }
  },
  "type": "registry:ui"
}
