# Switch

Turns a setting on or off, and applies it straight away.

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/switch shows the Dex app's own React component, which only works inside the Dex codebase.

## HTML

A native checkbox with `role="switch"`, in a `dex-check-row` label:

```html
<label class="dex-check-row"><input type="checkbox" role="switch" class="dex-switch" checked /> Visible to companies</label>
```

- **Settings rows**: the text on the left and the switch on the right, with a hairline between rows. Join each switch to its label with `for` and `id`.

```html
<div style="display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; padding: 0.75rem 0">
  <div style="display: grid; gap: 0.125rem">
    <label class="dex-field-label" for="matches">New role matches</label>
    <span class="dex-small dex-muted">An email when a role matches your profile.</span>
  </div>
  <input type="checkbox" role="switch" class="dex-switch" id="matches" checked />
</div>
<div style="display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; padding: 0.75rem 0;
  border-top: var(--dex-hairline) solid var(--dex-border)">
  <div style="display: grid; gap: 0.125rem">
    <label class="dex-field-label" for="digest">Weekly digest</label>
    <span class="dex-small dex-muted">A Monday email with the week's new roles.</span>
  </div>
  <input type="checkbox" role="switch" class="dex-switch" id="digest" />
</div>
```

- **Disabled**: the `disabled` attribute takes it to 50%. On, it keeps its fill. For a locked settings row, put `opacity: 0.5` on the whole row and `style="opacity: 1"` on the disabled switch, so it doesn't fade twice.

## States

- Rest, hover and focus step the edge from 25% to 50% to 75%. On, the track fills primary and the knob slides right in the primary foreground.

## Rules

- Use a switch for a setting that applies straight away, such as profile visibility. For an answer that's sent with a form, use a checkbox.
- A switch never errors, so it has no invalid state.
- Beside a single setting, the label sits to the right of the switch; in a list of settings, the text is on the left and the switch on the right.
- Name the setting, not the action: "Weekly digest", not "Turn on weekly digest".
