# State rules

Every control moves through the same states, drawn with the same tokens.

This is the rule in `dex.css` terms, 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/state-rules shows the rule on the Dex app's own React components, which only work inside the Dex codebase.

## HTML

`dex.css` draws every state below on its controls. Set the state with the attribute and the stylesheet does the rest:

```html
<input class="dex-field" placeholder="Senior backend engineer" />          <!-- rest, hover, focus -->
<input class="dex-field" aria-invalid="true" value="pete@" />            <!-- invalid -->
<input class="dex-field" disabled placeholder="1 month" />               <!-- disabled -->
<input class="dex-field" readonly value="£88,000" />                     <!-- read-only -->
<label class="dex-check-row"><input type="checkbox" class="dex-checkbox" checked /> Open to remote roles</label>
```

- **Rest**: a 1px edge in `--dex-control-border-subtle` (25% of the text colour) on a `--dex-card` fill. Every control starts here.
- **Hover**: the edge steps up to `--dex-control-border` (50%). Nothing fills and nothing moves. A selected item doesn't change on hover.
- **Focus**: the edge steps up again to `--dex-control-border-strong` (75%), for the keyboard only (`:focus-visible`). Nothing is drawn outside the control.
- **Selected**: `--dex-primary`. Small things fill with it; choice cards take it as their edge. See https://brand.meetdex.ai/components/selected.md.
- **Invalid**: `aria-invalid="true"` turns the edge `--dex-destructive`, with a `dex-field-error` under it. See https://brand.meetdex.ai/components/errors.md.
- **Disabled**: the `disabled` attribute takes the whole control to 50% with a `--dex-muted` fill and no hover. A ticked, selected or on control keeps its primary fill, so it still shows its value.
- **Read-only**: fields only. The `readonly` attribute gives a muted fill and full-contrast text. Add a lock and helper text saying where the value came from (see https://brand.meetdex.ai/components/input.md).

## Focus

Focus is always a darker 1px edge, never a glow or an outer ring. How it's drawn depends on what the control already has, and `dex.css` picks the right one for each class:

- **Bordered controls** (`dex-field`, `dex-checkbox`, `dex-radio`, `dex-switch`, `dex-chip`, `dex-joined`): the edge itself steps up to 75%.
- **Borderless things** (ghost, outline and link buttons, `dex-tab`, accordion rows, calendar days): the same edge as a 1px inset, which shifts nothing.
- **Text with no padding round it** (`dex-link`): a 1px outline 2px out, so it doesn't cut into the letters.
- **Filled things** (a ticked box, a selected radio, chip or day, a switch that's on, a solid button): the primary edge stays, with a 1px line in the foreground colour just inside it.
- **An invalid control** keeps its red edge, and focus doubles it. Focus never hides an error.
- **A choice card** marks the card, not the radio inside it. **A slider** marks the thumb, not the track.

## Rules

- The edge carries the state. Never show state with a shadow, a glow or an outer ring.
- Hide the browser's own focus ring only where `dex.css` draws its own; never leave a control with no visible focus.
- Choices (checkboxes, radios, chips) have no read-only state. Show the answer as text, or use `disabled` if it must stay in the form.
- A switch never errors.
- If you build a control `dex.css` doesn't have, give it these states with these tokens and it will fit the set.
