> A guide to [@fabiocv/ui](https://ui.fabio.cv/). Every guide is listed at https://ui.fabio.cv/llms.txt.

# Switch

A setting that is on or off, built on Base UI's
[Switch](https://base-ui.com/react/components/switch), exported from
`@fabiocv/ui/switch`. Its label sits beside it and presses it too.

```tsx
import { Switch } from '@fabiocv/ui/switch';

<Switch label="Play sounds" checked={sound} onCheckedChange={setSound} />;
```

- `checked` and `defaultChecked` say whether it is on, and `onCheckedChange` is
  called with the new state.
- The track is two `16px` thumbs wide with `2px` padding, `36px` by `20px`,
  with `8px` corners, as a control takes. The thumb takes `6px`, so they stay
  concentric.
- Off, the track is Surface subtle. On, it is Foreground and the thumb slides
  across. The thumb is Surface. The slide and the fill change on `SNAP`.
  With reduced motion the thumb moves at once, and the fill still fades.
- The label is `Text.Body` in Foreground secondary, and Foreground while
  hovered. It changes on `TRACK`.
- Disabled, the label is Foreground disabled, an on track turns Foreground
  disabled, and presses do nothing.
- Focus shows `focusRing` on the track, in Foreground while off and Surface
  while on, and Space presses it.
- `className` goes to the label. Other props go to Base UI's `Switch.Root`,
  such as `disabled`, `name` and `ref`.

## Types of `@fabiocv/ui/switch`

```ts
export type SwitchProps = Omit<BaseSwitch.Root.Props, 'children' | 'className' | 'render'> & {
    /** Shown beside the switch. Pressing it presses the switch. */
    label: string;
    /** Given to the label that holds the switch. */
    className?: string;
};

/** A setting that is on or off, built on Base UI's Switch, with its label. */
export declare function Switch({ label, className, ...props }: SwitchProps): import("react").JSX.Element;
```

## Examples

### Default

```tsx
<Switch label="Play sounds" checked={false} />
```

### Disabled

```tsx
<Switch label="Off" disabled />
<Switch label="On" disabled defaultChecked />
```

See it at https://ui.fabio.cv/switch/.
