# Checkbox

A box the person ticks. Nothing is checked until the person checks it or the app says so with `checked` or `defaultChecked`; a choice that decides something is left empty, never pre-ticked. `checked="indeterminate"` shows a dash for a parent whose children are only partly ticked. Pair it with a `Label` (`htmlFor` and `id`), or wrap both in a <label>. To lock it, wrap it in `Locked` with a reason: it stays focusable, says why, and doesn't change.

- 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, render-prop, tokens, utils.
npm packages: radix-ui@^1.8.1.

## Example

```tsx
"use client"

import * as React from "react"
import { Checkbox } from "@/components/ui/checkbox"
import { Label } from "@/components/ui/label"
import { Locked } from "@/components/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>

No props.

Also takes the props of `React.ComponentProps<typeof CheckboxPrimitive.Root>`, `RenderProp`.

## 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` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
