{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "checkbox",
  "title": "Checkbox",
  "description": "A labeled checkbox on the Field contract, with the label to its right: pass `label`, and `checked` with `onCheckedChange` (or `defaultChecked`).",
  "dependencies": [
    "@base-ui/react@^1.8.0"
  ],
  "registryDependencies": [
    "@ouro/field",
    "@ouro/lib-control-ref",
    "@ouro/lib-dev",
    "@ouro/lib-env",
    "@ouro/lib-touch-target",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-field"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/checkbox/checkbox-styles.ts",
      "content": "export { boxClass, dashClass, indicatorClass, tickClass };\n\n// Class strings for Checkbox, apart from the components so each component\n// file exports only components (React Fast Refresh). Class strings are literal so the app's\n// Tailwind finds them when it compiles.\n\n/**\n * The box: 20px on touch screens, beside a 24px label line, stepping down to 16px beside a\n * 20px line from the `sm` breakpoint with a fine pointer, so a landscape phone keeps the\n * phone size. Either way it sits 2px down, centered on the label's first line. It fills\n * with the primary color when checked or mixed, presses in, and its hit area is 44px on\n * touch screens.\n *\n * @internal\n * @claim \"The box: 20px on touch screens\" registry/ouro/components/ouro/checkbox/checkbox.touch.test.tsx verify:testExists(registry/ouro/components/ouro/checkbox/checkbox.touch.test.tsx::keeps the 20px box and 16px label on a landscape phone, past the sm breakpoint)\n * @claim \"It fills with the primary color\" registry/ouro/components/ouro/checkbox/checkbox.touch.test.tsx verify:testExists(registry/ouro/components/ouro/checkbox/checkbox.touch.test.tsx::gives the box a 44px hit area, though it is 20px)\n * @claim \"The box: 20px on touch screens\" registry/ouro/components/ouro/checkbox/checkbox.test.tsx verify:testExists(registry/ouro/components/ouro/checkbox/checkbox.test.tsx::Checkbox look > is 16px beside 14px text with a fine pointer from sm, centered on the label's first line)\n * @claim \"Either way it sits 2px down\" registry/ouro/components/ouro/checkbox/checkbox.test.tsx verify:testExists(registry/ouro/components/ouro/checkbox/checkbox.test.tsx::Checkbox look > is 16px beside 14px text with a fine pointer from sm, centered on the label's first line)\n */\n// Its own transition, not `press`'s: the box's fill eases before the tick draws, one choreographed motion.\nconst boxClass =\n  \"group [transition:scale_var(--ouro-duration-press)_var(--ouro-ease-out),background-color_var(--ouro-duration-fast)_ease,border-color_var(--ouro-duration-fast)_ease,color_var(--ouro-duration-fast)_ease,opacity_var(--ouro-duration-fast)_ease] relative m-0 mt-0.5 box-border inline-flex size-5 shrink-0 items-center justify-center p-0 sm:pointer-fine:size-4 \" +\n  \"rounded-ouro-sm border border-solid border-muted-foreground bg-transparent text-primary-foreground dark:not-data-checked:not-data-indeterminate:bg-input/30 \" +\n  \"data-checked:border-primary data-checked:bg-primary data-indeterminate:border-primary data-indeterminate:bg-primary \" +\n  \"aria-invalid:border-destructive \" +\n  \"cursor-default select-none touch-manipulation [-webkit-tap-highlight-color:transparent] \" +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"not-aria-invalid:not-data-disabled:not-data-checked:not-data-indeterminate:pointer-fine:hover:border-foreground \" +\n  \"motion-safe:not-data-disabled:active:scale-(--ouro-press-scale) \" +\n  \"data-disabled:cursor-not-allowed data-disabled:opacity-50\";\n\n/**\n * The indicator, kept mounted so the tick can fade out as well as in.\n *\n * @internal\n */\nconst indicatorClass = \"pointer-events-none flex size-full items-center justify-center\";\n\n/**\n * The tick draws along its path (`pathLength` 1, so a dash of 1 is the whole tick, and its gap\n * of 2 leaves no empty dash at either end for a round cap to draw as a dot) once the box has filled: `stroke-dashoffset` from 1 to 0 over `--ouro-duration-draw`, starting after\n * `--ouro-duration-fast`. Unchecking takes it back along the same path at once, over\n * `--ouro-duration-fast`. With reduced motion nothing draws: the whole tick fades in and out.\n *\n * @internal\n * @claim \"The tick draws along its path\" registry/ouro/components/ouro/checkbox/checkbox.test.tsx verify:testExists(registry/ouro/components/ouro/checkbox/checkbox.test.tsx::Checkbox look > fills the box, then draws the tick along its path, and only fades and recolours with reduced motion)\n */\nconst tickClass =\n  \"[stroke-dasharray:1_2] [stroke-dashoffset:1] group-data-checked:[stroke-dashoffset:0] group-data-indeterminate:hidden \" +\n  \"motion-safe:[transition:stroke-dashoffset_var(--ouro-duration-fast)_var(--ouro-ease-out)] \" +\n  \"motion-safe:group-data-checked:[transition:stroke-dashoffset_var(--ouro-duration-draw)_var(--ouro-ease-out)_var(--ouro-duration-fast)] \" +\n  \"motion-reduce:[stroke-dashoffset:0] motion-reduce:opacity-0 motion-reduce:group-data-checked:opacity-100 \" +\n  \"motion-reduce:[transition:opacity_var(--ouro-duration-fast)_var(--ouro-ease-out)]\";\n\n/**\n * The dash a mixed box shows in place of the tick.\n *\n * @internal\n */\nconst dashClass = \"hidden group-data-indeterminate:block\";\n\n",
      "type": "registry:ui",
      "target": "@components/ouro/checkbox/checkbox-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/checkbox/checkbox.tsx",
      "content": "\"use client\";\n\nimport { Checkbox as BaseCheckbox } from \"@base-ui/react/checkbox\";\nimport type { JSX, ReactNode, Ref } from \"react\";\nimport { Field } from \"@/registry/ouro/components/ouro/field/field\";\nimport { contractWarnings } from \"@/registry/ouro/components/ouro/field/field-styles\";\nimport { devThrow } from \"@/registry/ouro/lib/ouro/dev\";\nimport { controlRef } from \"@/registry/ouro/lib/ouro/control-ref\";\nimport { TouchTarget } from \"@/registry/ouro/lib/ouro/touch-target\";\nimport { FieldOwnerContext, useField, type ReadonlyErrorMessages } from \"@/registry/ouro/lib/ouro/use-field\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { boxClass, dashClass, indicatorClass, tickClass } from \"@/registry/ouro/components/ouro/checkbox/checkbox-styles\";\n\n/** Props for {@link Checkbox}. */\nexport interface CheckboxProps {\n  /**\n   * What checking it means, shown to the right of the box and read as its name. Required:\n   * every control needs a name. To hide it visually, keep it and add `hideLabel`.\n   * @claim \"Required: every control needs a name\" registry/ouro/components/ouro/checkbox/checkbox.test-d.ts verify:fileLine(registry/ouro/components/ouro/checkbox/checkbox.test-d.ts, /\\{\\schecked:\\strue\\s\\}>\\(\\)\\.not\\.toExtend<CheckboxProps>/)\n   */\n  label: string;\n  /** Hides the label visually; screen readers still read it as the checkbox's name. */\n  hideLabel?: boolean | undefined;\n  /** Supporting text under the label, read after it through `aria-describedby`. */\n  description?: ReactNode | undefined;\n  /**\n   * What is wrong, from your server action or client check, shown under the label; the box\n   * gets `aria-invalid`. A message is text or a React node (one with a link); an empty string or array means valid. In a `CheckboxGroup`, pass it\n   * to the group.\n   */\n  error?: ReadonlyErrorMessages | undefined;\n  /**\n   * The box must be checked to submit the form (accepting terms): it gets `required` and\n   * `aria-required`, and the label a marker. In a `CheckboxGroup`, pass it to the group.\n   */\n  required?: boolean | undefined;\n  /** Disables the checkbox and fades it. */\n  disabled?: boolean | undefined;\n  /** The form field name it submits under when checked. In a `CheckboxGroup`, the group's `name` applies. */\n  name?: string | undefined;\n  /**\n   * What a checked box submits (`on` without one). In a `CheckboxGroup`, it identifies the\n   * box in the group's `value`, so it is required there.\n   */\n  value?: string | undefined;\n  /** Whether it is checked, for a controlled checkbox; pair it with `onCheckedChange`. */\n  checked?: boolean | undefined;\n  /** Whether it starts checked, for an uncontrolled checkbox. */\n  defaultChecked?: boolean | undefined;\n  /** Called with the new state when it is checked or unchecked. */\n  onCheckedChange?: ((checked: boolean) => void) | undefined;\n  /**\n   * Shows a dash and announces \"mixed\": neither checked nor unchecked, as a \"select all\" box\n   * does when some of its items are checked. It is controlled: a click does not clear it, so\n   * clear it in `onCheckedChange`, as in\n   * `<Checkbox indeterminate={some} checked={all} onCheckedChange={toggleAll}>`. The box\n   * submits only while `checked`.\n   * @claim \"box does when some of its items are\" registry/ouro/components/ouro/checkbox/checkbox.test.tsx verify:testExists(registry/ouro/components/ouro/checkbox/checkbox.test.tsx::Checkbox > announces the indeterminate state as mixed and shows a dash)\n   */\n  indeterminate?: boolean | undefined;\n  /** Shows the state but ignores clicks and keys, unlike `disabled`, which also fades it. */\n  readOnly?: boolean | undefined;\n  /**\n   * Layout only: margins, width, grid placement (`mt-4`, `col-span-2`). Appearance classes\n   * warn in development; style checkboxes in your theme.\n   */\n  className?: string | undefined;\n  /** The box element, a `<button role=\"checkbox\">`, which the label names with `for`. */\n  ref?: Ref<HTMLElement> | undefined;\n\n  /** Not a prop. Ouro UI uses `onCheckedChange`, which gets the new state: `onCheckedChange={setChecked}`. */\n  onChange?: { 'Use onCheckedChange={setChecked}': never };\n  /** Not a prop. Ouro UI uses `checked`: `<Checkbox checked={agreed}>`. */\n  isChecked?: { 'Use <Checkbox checked={agreed}>': never };\n  /** Not a prop. Ouro UI uses `indeterminate`: `<Checkbox indeterminate>`. */\n  isIndeterminate?: { 'Use <Checkbox indeterminate>': never };\n  /** Not a prop. A checkbox's starting state is `defaultChecked`: `<Checkbox defaultChecked>`. */\n  defaultValue?: { 'Use <Checkbox defaultChecked>': never };\n  /** Not a prop. Ouro UI uses `error`: `<Checkbox error=\"Required.\">`. */\n  errorMessage?: { 'Use <Checkbox error=\"Required.\">': never };\n  /** Not a prop. Ouro UI uses `description`: `<Checkbox description=\"...\">`. */\n  helperText?: { 'Use <Checkbox description=\"...\">': never };\n  /** Not a prop. `error` marks the checkbox invalid: `<Checkbox error=\"What is wrong\">`. */\n  isInvalid?: { 'Use <Checkbox error=\"What is wrong\">': never };\n  /** Not a prop. `error` marks the checkbox invalid: `<Checkbox error=\"What is wrong\">`. */\n  invalid?: { 'Use <Checkbox error=\"What is wrong\">': never };\n  /** Not a prop. Ouro UI uses `required`: `<Checkbox required>`. */\n  isRequired?: { 'Use <Checkbox required>': never };\n  /** Not a prop. Ouro UI uses `disabled`: `<Checkbox disabled>`. */\n  isDisabled?: { 'Use <Checkbox disabled>': never };\n}\n\n/** Field's messages and root name Checkbox, and put the box before its label. */\nconst owner = { name: \"Checkbox\", data: \"checkbox\", layout: \"inline\" } as const;\n/** Marks the hidden input Base UI submits the box with. */\nconst markInput = controlRef(\"checkbox\", \"hidden-input\");\n\n/** The box, inside the Field: it takes its name, description and error ids from the field. */\nfunction CheckboxBox(props: {\n  value: string | undefined;\n  checked: boolean | undefined;\n  defaultChecked: boolean | undefined;\n  onCheckedChange: ((checked: boolean) => void) | undefined;\n  indeterminate: boolean | undefined;\n  readOnly: boolean | undefined;\n  ref: Ref<HTMLElement> | undefined;\n}): JSX.Element {\n  const { onCheckedChange, ...rest } = props;\n  const field = useField()!;\n  return (\n    <BaseCheckbox.Root\n      {...rest}\n      // A real button, so the label's `for` names it and not the hidden input: its label finds one control.\n      nativeButton\n      render={<button />}\n      inputRef={markInput}\n      data-ouro-control=\"checkbox\"\n      data-ouro-part=\"box\"\n      onCheckedChange={onCheckedChange && ((checked) => onCheckedChange(checked))}\n      required={field.required}\n      // Set here, not left to Base UI's effects, so the server HTML names and describes the box.\n      aria-labelledby={field.labelId}\n      aria-describedby={field.describedBy}\n      aria-invalid={field.invalid || undefined}\n      className={boxClass}\n    >\n      <TouchTarget />\n      <BaseCheckbox.Indicator keepMounted className={indicatorClass}>\n        <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth={2} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className=\"size-full\">\n          <path d=\"M3.5 8.5 6.5 11.5 12.5 4.5\" pathLength={1} data-ouro-part=\"tick\" className={tickClass} />\n          <path d=\"M4 8h8\" className={dashClass} />\n        </svg>\n      </BaseCheckbox.Indicator>\n    </BaseCheckbox.Root>\n  );\n}\n\n/**\n * A labeled checkbox on the Field contract, with the label to its right: pass `label`, and\n * `checked` with `onCheckedChange` (or `defaultChecked`). Clicking the label toggles it,\n * Space toggles it from the keyboard, the box fills and the tick draws, and `indeterminate` shows a\n * dash announced as \"mixed\". With `name`, a checked box submits `name=value` with its form.\n *\n * Use `CheckboxGroup` instead for several choices under one legend that submit together,\n * `Switch` for a setting that applies at once, and `RadioGroup` when only one choice may be picked.\n *\n * @group Forms\n * @see https://ui.ouroboros.bot/docs/checkbox\n *\n * @example\n * <Checkbox label=\"Email me new recipes\" name=\"newsletter\" defaultChecked />\n * <Checkbox label=\"I accept the terms\" name=\"terms\" required error={errors?.terms} />\n */\nexport function Checkbox(props: CheckboxProps): JSX.Element {\n  const {\n    label,\n    hideLabel,\n    description,\n    error,\n    required,\n    disabled,\n    name,\n    value,\n    checked,\n    defaultChecked,\n    onCheckedChange,\n    indeterminate,\n    readOnly,\n    className,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    onChange,\n    isChecked,\n    isIndeterminate,\n    defaultValue,\n    errorMessage,\n    helperText,\n    isInvalid,\n    invalid,\n    isRequired,\n    isDisabled,\n  } = props;\n  const group = useField()?.group;\n  if (group === \"RadioGroup\") {\n    devThrow(\n      \"Checkbox\",\n      \"a RadioGroup takes Radio choices\",\n      process.env.NODE_ENV !== \"production\"\n        ? `<RadioGroup legend=\"Size\"><Radio value=\"small\" label=\"${label}\" /></RadioGroup>, or a CheckboxGroup for several choices`\n        : /* istanbul ignore next @preserve -- production only */ \"\",\n    );\n  }\n\n  useDevWarnings(\n    \"Checkbox\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          ...contractWarnings(\"Checkbox\", { errorMessage, helperText, isInvalid, invalid, isRequired, isDisabled }),\n          onChange !== undefined && [\"onChange is not a prop; onCheckedChange gets the new state\", \"<Checkbox onCheckedChange={(checked) => setChecked(checked)}>\"],\n          isChecked !== undefined && [\"isChecked is not a prop\", `<Checkbox checked={${String(isChecked)}}>`],\n          isIndeterminate !== undefined && [\"isIndeterminate is not a prop\", \"<Checkbox indeterminate>\"],\n          defaultValue !== undefined && [\"defaultValue is not a prop; a checkbox starts checked with defaultChecked\", \"<Checkbox defaultChecked>\"],\n          group !== undefined && value === undefined && [`a checkbox in a ${group} needs a value`, `<Checkbox value=\"basil\" label=\"${label}\" />`],\n          checked !== undefined && !onCheckedChange && !readOnly && [\"checked without onCheckedChange never changes\", \"<Checkbox checked={checked} onCheckedChange={setChecked}>, or defaultChecked\"],\n          indeterminate &&\n            !onCheckedChange &&\n            !readOnly &&\n            !disabled && [\n            \"indeterminate without onCheckedChange stays mixed after a click while the box submits as checked\",\n            \"<Checkbox indeterminate={some} checked={all} onCheckedChange={toggleAll}>\",\n          ],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  return (\n    <FieldOwnerContext.Provider value={owner}>\n      <Field\n        label={label}\n        hideLabel={hideLabel}\n        description={description}\n        error={error}\n        required={required}\n        disabled={disabled}\n        name={name}\n        className={className}\n      >\n        <CheckboxBox\n          value={value}\n          checked={checked}\n          defaultChecked={defaultChecked}\n          onCheckedChange={onCheckedChange}\n          indeterminate={indeterminate}\n          readOnly={readOnly}\n          ref={ref}\n        />\n      </Field>\n    </FieldOwnerContext.Provider>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/checkbox/checkbox.tsx"
    }
  ],
  "docs": "A labeled checkbox on the Field contract, with the label to its right: pass `label`, and `checked` with `onCheckedChange` (or `defaultChecked`). Import: import { Checkbox } from \"@/components/ouro/checkbox/checkbox\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: field, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/checkbox.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}