# Toggle

A button that stays pressed, like Billable on a time entry or Bold in an editor. Built on ui-sdk's Toggle: it says aria-pressed, and Space or Enter flips it. Off is the Outline button; on takes the tinted navy pick.

- Beta: ready to use; its API can still change in a minor release.
- Category: Actions

```tsx
import { Toggle } from "@leap-crm/design-system";
```

## Best practices

- Do: Use it for a button that stays pressed, like Billable on a time entry or Bold in an editor.
- Do: Give an icon-only toggle an `aria-label`, like Bold, and keep that name the same pressed or not. `aria-pressed` says the state.
- Do: Use `sm`, the default, in toolbars, and `xs` or `md` to match the buttons beside it.
- Don't: Use a row of toggles for one choice from several, like Day, Week or Month. Use `SegmentedControl`, which allows only one.
- Don't: Use it for a setting on a settings page. Use `SwitchRow`, which pairs the switch with its label and a description.

## Keyboard

| Keys | What they do |
| --- | --- |
| Enter, Space | Press the focused toggle. |

## Related

- [Switch](./switch.md)
- [Checkbox](./checkbox.md)
- [Button](./button.md)
- [Segmented Control](./segmented-control.md)

## Examples

What the examples import:

```tsx
import { Bold, Italic, Pin, Underline } from "lucide-react";
import { Fragment } from "react";
import { Toggle } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const sizes = ["xs", "sm", "md"] as const;
```

### Text and icon

Press each: off is Outline, on is navy/100 with a navy/200 edge, and hover deepens it. Tab for focus. An icon toggle needs aria-label.

```tsx
<div className="grid grid-cols-[auto_repeat(3,auto)] items-center justify-start justify-items-start gap-x-6 gap-y-4">
  <span />
  {["Off", "On", "Disabled"].map(column => (
    <span key={column} className="text-small text-neutral-text-muted">
      {column}
    </span>
  ))}
  <span className="text-small text-neutral-text-muted">Text</span>
  <Toggle>Billable</Toggle>
  <Toggle defaultPressed>Billable</Toggle>
  <Toggle disabled>Billable</Toggle>
  <span className="text-small text-neutral-text-muted">Icon</span>
  <Toggle icon={<Bold />} aria-label="Bold" />
  <Toggle icon={<Bold />} aria-label="Bold" defaultPressed />
  <Toggle icon={<Bold />} aria-label="Bold" disabled />
  <span className="text-small text-neutral-text-muted">Both</span>
  <Toggle icon={<Pin />}>Pinned</Toggle>
  <Toggle icon={<Pin />} defaultPressed>
    Pinned
  </Toggle>
  <Toggle icon={<Pin />} disabled>
    Pinned
  </Toggle>
</div>
```

### Sizes

sm (32 px) by default, as in toolbars. xs (28) and md (36) follow the button ladder.

```tsx
<div className="grid grid-cols-[auto_auto_auto] items-center justify-start justify-items-start gap-x-6 gap-y-4">
  {sizes.map(size => (
    <Fragment key={size}>
      <span className="text-small text-neutral-text-muted">{size}</span>
      <Toggle size={size} defaultPressed>
        Billable
      </Toggle>
      <Toggle size={size} icon={<Italic />} aria-label="Italic" />
    </Fragment>
  ))}
</div>
```

### In a toolbar

Formatting toggles side by side. Each flips on its own; for one choice from several, use SegmentedControl.

```tsx
<div className="flex gap-1">
  <Toggle icon={<Bold />} aria-label="Bold" />
  <Toggle icon={<Italic />} aria-label="Italic" defaultPressed />
  <Toggle icon={<Underline />} aria-label="Underline" />
</div>
```

## Props

Also takes ui-sdk's Toggle props: pressed, defaultPressed, onPressedChange, value, disabled and focusableWhenDisabled.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `size` | `"xs" \| "sm" \| "md"` | `"sm"` | sm (32 px) by default, as in toolbars; xs and md follow the button ladder. |
| `icon` | `ReactNode` |  | A leading icon, or the only content of an icon toggle (which then needs `aria-label`). |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
