# Toggle group

Toggles joined into one control, single or multiple selection.

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

## Installation

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

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

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

## Examples

### Default

```html
<ui-toggle-group role="group" aria-label="Text alignment">
  <label data-ui="toggle" data-toggle-size="icon">
    <input type="radio" name="align" aria-label="Align left" 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="4" y1="6" x2="20" y2="6" />
      <line x1="4" y1="12" x2="14" y2="12" />
      <line x1="4" y1="18" x2="18" y2="18" />
    </svg>
  </label>
  <label data-ui="toggle" data-toggle-size="icon">
    <input type="radio" name="align" aria-label="Align center" />
    <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="4" y1="6" x2="20" y2="6" />
      <line x1="7" y1="12" x2="17" y2="12" />
      <line x1="5" y1="18" x2="19" y2="18" />
    </svg>
  </label>
  <label data-ui="toggle" data-toggle-size="icon">
    <input type="radio" name="align" aria-label="Align right" />
    <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="4" y1="6" x2="20" y2="6" />
      <line x1="10" y1="12" x2="20" y2="12" />
      <line x1="6" y1="18" x2="20" y2="18" />
    </svg>
  </label>
</ui-toggle-group>
```

### Multiple

```html
<ui-toggle-group role="group" aria-label="Text formatting">
  <label data-ui="toggle">
    <input type="checkbox" name="format" value="bold" checked />
    <span>Bold</span>
  </label>
  <label data-ui="toggle">
    <input type="checkbox" name="format" value="italic" />
    <span>Italic</span>
  </label>
  <label data-ui="toggle">
    <input type="checkbox" name="format" value="underline" checked />
    <span>Underline</span>
  </label>
</ui-toggle-group>
```

### Vertical

```html
<ui-toggle-group data-toggle-group-orientation="vertical" role="group" aria-label="Map layer">
  <label data-ui="toggle">
    <input type="radio" name="layer" value="map" checked />
    <span>Map</span>
  </label>
  <label data-ui="toggle">
    <input type="radio" name="layer" value="satellite" />
    <span>Satellite</span>
  </label>
  <label data-ui="toggle">
    <input type="radio" name="layer" value="terrain" />
    <span>Terrain</span>
  </label>
</ui-toggle-group>
```

## Attributes

| Attribute | Kind | Values |
| --- | --- | --- |
| `data-ui="toggle-group"` | identity | free value |
| `<ui-toggle-group>` | tag | free value |
| `data-toggle-group-orientation` | preset | `vertical` |

Requires: toggle.

## Hooks

| Hook | Default | State |
| --- | --- | --- |
| `--ui-toggle-group-bg` | `var(--color-card)` | — |
| `--ui-toggle-group-corner-shape` | `var(--ui-toggle-corner-shape)` | — |
| `--ui-toggle-group-radius` | `var(--ui-toggle-radius)` | — |
