# Checkbox

A box the person ticks.

- Registry name: `checkbox` (`@candor/checkbox`)
- Tier: Free (MIT). No licence key needed.
- Docs: https://candor.themethodic.com/docs/checkbox

## Install

```bash
npx candor-ui add checkbox
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/checkbox`.
It brings in: motion, tokens, utils.
npm packages: @base-ui/react@^1.9.0.

## Example

```tsx
"use client"

import * as React from "react"
import { Checkbox } from "@/components/candor/ui/checkbox"
import { Label } from "@/components/candor/ui/label"
import { Locked } from "@/components/candor/locked"

const channels = [
  { id: "email", label: "Email me when a run needs a decision" },
  { id: "digest", label: "Send a weekly summary of finished runs" },
]

export default function Example() {
  // Nothing is ticked until the person ticks it.
  const [ticked, setTicked] = React.useState<string[]>([])
  return (
    <div className="flex w-full max-w-sm flex-col gap-3">
      {channels.map((c) => (
        <div key={c.id} className="flex items-center gap-2.5">
          <Checkbox
            id={c.id}
            checked={ticked.includes(c.id)}
            onCheckedChange={(on) => setTicked((t) => (on === true ? [...t, c.id] : t.filter((x) => x !== c.id)))}
          />
          <Label htmlFor={c.id}>{c.label}</Label>
        </div>
      ))}
      <div className="flex items-center gap-2.5">
        <Locked inline reason="Your workspace sets this for everyone.">
          <Checkbox id="audit" />
        </Locked>
        <Label htmlFor="audit">Keep an audit log of changes</Label>
      </div>
    </div>
  )
}
```

## <Checkbox>

Props:

- `className?: string | undefined`: Classes, merged with Candor's.
- `checked?: CheckedState | undefined`: Whether the box is ticked, when the app controls it; `"indeterminate"` shows a dash (some of its children are ticked).
- `defaultChecked?: CheckedState | undefined`: Whether the box starts ticked, when the box keeps its own state. Leave it out for a choice the person makes.
- `onCheckedChange?: ((checked: boolean, details: CheckboxPrimitive.Root.ChangeEventDetails) => void) | undefined`: Called with the new state when the person ticks or unticks the box, and Base UI's change details.

Also takes the props of `Omit<CheckboxPrimitive.Root.Props, "className" | "checked" | "defaultChecked" | "onCheckedChange" | "indeterminate">`.

## Motion

- **tick** (mark, draw): The tick draws along its path when the person checks the box. A box that is already checked when it appears, or that the app changes, shows its tick at once: nothing is drawn for a change the person didn't make.

Set with `--cd-motion-checkbox-<moment>-*` in your brand file; the families are in the design reference.

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider`: its fixed strings in `strings`, its nouns in `nouns`; entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
