# Switch

Binary toggle control built on Radix Switch. Track height matches `--control-icon-*`, width is `2×` height, and the thumb translates with `--duration-100` (disabled under `prefers-reduced-motion`).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| size | "xs" \| "sm" \| "md" \| "lg" | "md" | Track dimensions (height = icon size, width = 2× height) and minimum row height (--control-height-*). |
| label | ReactNode | — | Inline label rendered to the right of the switch; makes the entire row clickable. |
| description | ReactNode | — | Optional helper text wired into aria-describedby. |
| checked / defaultChecked | boolean | false | Controlled or uncontrolled toggle state. |
| disabled | boolean | false | Disables toggling using step 3 background and step 8 thumb without opacity. |

## Sizes and tokens

| Tier / Role | Token | Value |
| --- | --- | --- |
| xs | --control-icon-xs / --control-height-xs | 16×32px track · 12px thumb · 24px row min-height |
| sm | --control-icon-sm / --control-height-sm | 16×32px track · 12px thumb · 32px row min-height |
| md | --control-icon-md / --control-height-md | 20×40px track · 16px thumb · 40px row min-height |
| lg | --control-icon-lg / --control-height-lg | 24×48px track · 20px thumb · 48px row min-height |
| Track & thumb | --input / --primary / --primary-foreground | Off = step 8 track · On = brand step 9 track · 100ms transform |

## Code

```tsx
import { Switch } from "@freshgemui/monoplinth";

export function Example() {
  return (
    <Switch
      name="strict-contrast"
      value="enabled"
      label="Strict contrast"
      description="Enforce 4.5:1 text pairs in CI."
      defaultChecked
    />
  );
}
```

## Do and don't

- **Do: Use Switch for immediate on/off settings** — Use Switch when toggling a setting takes effect immediately, and pair it with a clear inline label.
- **Don't: Use Switch inside a multi-select list that requires a Save button** — Use Checkbox for selections that are only applied when a form is submitted.

## Accessibility

- Renders `role="switch"` with `aria-checked`; `Space` toggles state.
- Clicking anywhere on the row toggles the switch while keeping `<label>` scoped to the label text.
- `motion-reduce:transition-none` removes thumb slide motion when `prefers-reduced-motion: reduce` is active.
- Every size enforces `--control-height-*` minimum target height (≥ 24px).

## Rationale

Using `--input` (step 8) for the off track and `--primary` (step 9) for the on track guarantees at least `3:1` non-text contrast against `background` in every theme and mode.
