# Toggle

A pressed or unpressed button over a checkbox or radio.

Source: https://www.zazz.sh/api/primitives/toggle/

## Installation

```bash
pnpm dlx zazz-ui add toggle
```

Also adds `fields`, `kbd`, `button`, which it depends on.

Run `zazz-ui init` first if the project has no `zazz/` folder yet.

## Examples

### Default

```html
<div
  style="
    --display: flex-col;
    --items: start;
    --gap: 6;
  "
>
  <div
    style="
      --display: flex;
      --items: center;
      --gap: 4;
    "
  >
    <label data-ui="toggle" data-toggle-size="icon">
      <input type="checkbox" name="bold" aria-label="Bold" />
      <svg
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
        aria-hidden="true"
      >
        <path d="M6 4h8a4 4 0 0 1 0 8H6z" />
        <path d="M6 12h9a4 4 0 0 1 0 8H6z" />
      </svg>
    </label>
    <label data-ui="toggle" data-toggle-size="icon">
      <input type="checkbox" name="italic" aria-label="Italic" checked />
      <svg
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
        aria-hidden="true"
      >
        <line x1="19" y1="4" x2="10" y2="4" />
        <line x1="14" y1="20" x2="5" y2="20" />
        <line x1="15" y1="4" x2="9" y2="20" />
      </svg>
    </label>
    <label data-ui="toggle" data-toggle-size="icon" data-toggle-variant="ghost">
      <input type="checkbox" name="underline" aria-label="Underline" />
      <svg
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
        aria-hidden="true"
      >
        <path d="M6 4v6a6 6 0 0 0 12 0V4" />
        <line x1="4" y1="20" x2="20" y2="20" />
      </svg>
    </label>
  </div>

  <div
    style="
      --display: flex;
      --items: center;
      --gap: 4;
    "
  >
    <label data-ui="toggle">
      <input type="checkbox" name="bold" />
      <span>Bold</span>
    </label>
    <label data-ui="toggle">
      <input type="checkbox" name="italic" checked />
      <span>Italic</span>
    </label>
    <label data-ui="toggle" data-toggle-variant="ghost">
      <input type="checkbox" name="disabled" disabled />
      <span>Disabled</span>
    </label>
  </div>
</div>
```

## Attributes

| Attribute | Kind | Values |
| --- | --- | --- |
| `data-ui="toggle"` | identity | free value |
| `data-toggle-size` | preset | `icon` `icon-sm` `sm` |
| `data-toggle-variant` | preset | `destructive` `ghost` `muted` `primary` `secondary` `tertiary` |

Requires: button.

## Hooks

| Hook | Default | State |
| --- | --- | --- |
| `--ui-toggle-background-clip` | `border-box` | — |
| `--ui-toggle-bg` | `var(--ui-button-bg)` | — |
| `--ui-toggle-bg--active` | `var(--ui-button-bg--active)` | active |
| `--ui-toggle-bg--checked` | `var(--color-primary)` | checked |
| `--ui-toggle-bg--checked-active` | `oklch(from var(--color-primary) l c h / 0.8)` | checked-active |
| `--ui-toggle-bg--checked-hover` | `oklch(from var(--color-primary) l c h / 0.9)` | checked-hover |
| `--ui-toggle-bg--hover` | `var(--ui-button-bg--hover)` | hover |
| `--ui-toggle-border-color` | `var(--ui-button-border-color)` | — |
| `--ui-toggle-border-color--active` | `var(--ui-button-border-color--active)` | active |
| `--ui-toggle-border-color--checked` | `var(--color-border)` | checked |
| `--ui-toggle-border-color--checked-active` | `var(--color-border)` | checked-active |
| `--ui-toggle-border-color--checked-hover` | `var(--color-border)` | checked-hover |
| `--ui-toggle-border-color--hover` | `var(--ui-button-border-color--hover)` | hover |
| `--ui-toggle-border-style` | `var(--ui-button-border-style)` | — |
| `--ui-toggle-border-width` | `var(--ui-button-border-width)` | — |
| `--ui-toggle-corner-shape` | `var(--ui-button-corner-shape)` | — |
| `--ui-toggle-font-family` | `var(--ui-button-font-family)` | — |
| `--ui-toggle-font-size` | `var(--ui-button-font-size)` | — |
| `--ui-toggle-font-weight` | `var(--ui-button-font-weight)` | — |
| `--ui-toggle-gap` | `var(--ui-button-gap)` | — |
| `--ui-toggle-icon-size` | `var(--ui-button-icon-size)` | — |
| `--ui-toggle-leading` | `var(--ui-button-leading)` | — |
| `--ui-toggle-min-h` | `var(--ui-button-min-h)` | — |
| `--ui-toggle-px` | `var(--ui-button-px)` | — |
| `--ui-toggle-py` | `var(--ui-button-py)` | — |
| `--ui-toggle-radius` | `var(--ui-button-radius)` | — |
| `--ui-toggle-ring-color` | `var(--ui-button-ring-color)` | — |
| `--ui-toggle-shadow` | `var(--ui-button-shadow)` | — |
| `--ui-toggle-text` | `var(--ui-button-text)` | — |
| `--ui-toggle-text--active` | `var(--ui-button-text--active)` | active |
| `--ui-toggle-text--checked` | `var(--color-primary-foreground)` | checked |
| `--ui-toggle-text--checked-active` | `var(--color-primary-foreground)` | checked-active |
| `--ui-toggle-text--checked-hover` | `var(--color-primary-foreground)` | checked-hover |
| `--ui-toggle-text--hover` | `var(--ui-button-text--hover)` | hover |
