# Button group

Buttons joined into one control with shared borders.

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

## Installation

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

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;
  "
>
  <ui-button-group role="group" aria-label="Text alignment">
    <button data-ui="button" type="button">Left</button>
    <button data-ui="button" type="button">Center</button>
    <button data-ui="button" type="button">Right</button>
  </ui-button-group>

  <ui-button-group role="group" aria-label="Pagination">
    <button data-ui="button" data-button-variant="muted" type="button">Previous</button>
    <button data-ui="button" data-button-variant="muted" type="button">1</button>
    <button data-ui="button" data-button-variant="muted" type="button">2</button>
    <button data-ui="button" data-button-variant="muted" type="button">3</button>
    <button data-ui="button" data-button-variant="muted" type="button">Next</button>
  </ui-button-group>

  <ui-button-group role="group" aria-label="Formatting">
    <button data-ui="button" data-button-size="icon" type="button" 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>
    </button>
    <button data-ui="button" data-button-size="icon" type="button" aria-label="Italic">
      <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>
    </button>
    <button data-ui="button" data-button-size="icon" type="button" 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>
    </button>
  </ui-button-group>
</div>
```

### Vertical

```html
<ui-button-group data-button-group-orientation="vertical" role="group" aria-label="View options">
  <button data-ui="button" type="button">List</button>
  <button data-ui="button" type="button">Board</button>
  <button data-ui="button" type="button">Calendar</button>
  <button data-ui="button" type="button">Timeline</button>
</ui-button-group>
```

## Attributes

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

Requires: button.

## Hooks

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