# Checkbox

A yes or no choice, or one of several options that can be picked together.

This is the HTML to build it with `dex.css`, for work outside the Dex codebase. Read https://brand.meetdex.ai/design.md first: it says how to set up a page and how to use the stylesheet. The page at https://brand.meetdex.ai/components/checkbox shows the Dex app's own React component, which only works inside the Dex codebase.

## HTML

A native checkbox in a `dex-check-row` label, so pressing the label ticks the box. The label sits 10px from the box.

```html
<label class="dex-check-row"><input type="checkbox" class="dex-checkbox" /> Open to remote roles</label>
```

- **With a description**: the label goes medium and a muted description sits under it. Line the box up with the label's first line:

```html
<label class="dex-check-row" style="align-items: flex-start">
  <input type="checkbox" class="dex-checkbox" style="margin-top: 0.0625rem" />
  <span style="display: grid; gap: 0.125rem">
    <span style="font-weight: 500">Open to contract roles</span>
    <span class="dex-small dex-muted">Show me day-rate and fixed-term roles as well as permanent ones.</span>
  </span>
</label>
```

- **Group**: a question over a stack of options, 12px apart, in a `<fieldset>` with a `<legend>`:

```html
<fieldset style="border: 0; margin: 0; padding: 0; display: grid; gap: 0.75rem">
  <legend class="dex-field-label" style="margin-bottom: 0.75rem">Which kinds of company?</legend>
  <label class="dex-check-row"><input type="checkbox" class="dex-checkbox" checked /> Series A to C</label>
  <label class="dex-check-row"><input type="checkbox" class="dex-checkbox" /> Late stage</label>
  <label class="dex-check-row"><input type="checkbox" class="dex-checkbox" /> Public companies</label>
</fieldset>
```

- **Invalid**: `aria-invalid="true"` turns the edge red. A single box's message lines up with the label, not the box (`style="padding-left: 1.875rem"` on the `dex-field-error`). In a group every box takes it, with one message under the group. See https://brand.meetdex.ai/components/errors.md.
- **Disabled**: the `disabled` attribute. A ticked box keeps its fill at 50%, so it still shows the value.
- **Indeterminate**: a box over a partly selected group fills with a dash. Set it from script (`box.indeterminate = true`); there's no attribute for it.

## States

- Rest, hover and focus step the edge from 25% to 50% to 75%. Ticked, it fills primary with the tick in the primary foreground; on focus a 1px line shows just inside its edge.

## Rules

- Use a checkbox for a yes or no choice, or for picking several options. For exactly one option use radios, and for a setting that applies straight away use a switch.
- Every box has a label, and pressing it ticks the box.
- The label is regular weight unless a description follows it.
- Selected is primary, never orange.
