# Button

Actions and links as buttons: variants, sizes, and icons.

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

## Installation

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

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

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

## Examples

### Default

```html
<div
  style="
    --display: flex;
    --flex-wrap: wrap;
    --items: center;
    --gap: 4;
  "
>
  <button data-ui="button" type="button">Default</button>
  <button data-ui="button" data-button-variant="primary" type="button">Primary</button>
  <button data-ui="button" data-button-variant="muted" type="button">Muted</button>
  <button data-ui="button" data-button-variant="ghost" type="button">Ghost</button>
  <button data-ui="button" data-button-variant="outline" type="button">Outline</button>
  <button data-ui="button" data-button-variant="info" type="button">Info</button>
  <button data-ui="button" data-button-variant="success" type="button">Success</button>
  <button data-ui="button" data-button-variant="warning" type="button">Warning</button>
  <button data-ui="button" data-button-variant="destructive" type="button">Destructive</button>
  <button data-ui="button" data-button-variant="link" type="button">Link</button>
</div>
```

### Icon

```html
<div
  style="
    --display: flex;
    --items: center;
    --gap: 4;
  "
>
  <button data-ui="button" data-button-variant="primary" type="button">
    Start free trial
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
      <rect width="256" height="256" fill="none" />
      <line
        x1="40"
        y1="128"
        x2="216"
        y2="128"
        fill="none"
        stroke="currentColor"
        stroke-linecap="round"
        stroke-linejoin="round"
        stroke-width="16"
      />
      <polyline
        points="144 56 216 128 144 200"
        fill="none"
        stroke="currentColor"
        stroke-linecap="round"
        stroke-linejoin="round"
        stroke-width="16"
      />
    </svg>
  </button>
  <button data-ui="button" type="button">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
      <rect width="256" height="256" fill="none" />
      <path
        d="M128,88a32,32,0,0,1,32-32h72V200H160a32,32,0,0,0-32,32"
        fill="none"
        stroke="currentColor"
        stroke-linecap="round"
        stroke-linejoin="round"
        stroke-width="16"
      />
      <path
        d="M24,200H96a32,32,0,0,1,32,32V88A32,32,0,0,0,96,56H24Z"
        fill="none"
        stroke="currentColor"
        stroke-linecap="round"
        stroke-linejoin="round"
        stroke-width="16"
      />
      <line
        x1="160"
        y1="96"
        x2="200"
        y2="96"
        fill="none"
        stroke="currentColor"
        stroke-linecap="round"
        stroke-linejoin="round"
        stroke-width="16"
      />
      <line
        x1="160"
        y1="128"
        x2="200"
        y2="128"
        fill="none"
        stroke="currentColor"
        stroke-linecap="round"
        stroke-linejoin="round"
        stroke-width="16"
      />
      <line
        x1="160"
        y1="160"
        x2="200"
        y2="160"
        fill="none"
        stroke="currentColor"
        stroke-linecap="round"
        stroke-linejoin="round"
        stroke-width="16"
      />
    </svg>
    Read article
  </button>
</div>
```

### Icon only

```html
<div
  style="
    --display: flex;
    --items: center;
    --gap: 4;
  "
>
  <button type="button" data-ui="button" data-button-size="icon" aria-label="Open menu">
    <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="20" y2="12" />
      <line x1="4" y1="18" x2="20" y2="18" />
    </svg>
  </button>
  <button
    type="button"
    data-ui="button"
    data-button-variant="primary"
    data-button-size="icon"
    aria-label="Open menu"
  >
    <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="20" y2="12" />
      <line x1="4" y1="18" x2="20" y2="18" />
    </svg>
  </button>
  <button
    type="button"
    data-ui="button"
    data-button-variant="muted"
    data-button-size="icon"
    aria-label="Open menu"
  >
    <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="20" y2="12" />
      <line x1="4" y1="18" x2="20" y2="18" />
    </svg>
  </button>
  <button
    type="button"
    data-ui="button"
    data-button-variant="ghost"
    data-button-size="icon"
    aria-label="Open menu"
  >
    <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="20" y2="12" />
      <line x1="4" y1="18" x2="20" y2="18" />
    </svg>
  </button>
</div>
```

## Attributes

| Attribute | Kind | Values |
| --- | --- | --- |
| `data-ui="button"` | identity | free value |
| `data-button-size` | preset | `icon` `icon-sm` `sm` |
| `data-button-variant` | preset | `destructive` `ghost` `info` `link` `muted` `outline` `primary` `secondary` `success` `tertiary` `warning` |

Requires: kbd, fields.

## Hooks

| Hook | Default | State |
| --- | --- | --- |
| `--ui-button-background-clip` | `border-box` | — |
| `--ui-button-bg` | `var(--color-background)` | — |
| `--ui-button-bg--active` | `oklch(from var(--ui-button-bg--hover) l c h / calc(alpha * 1.5))` | active |
| `--ui-button-bg--hover` | `var(--color-muted)` | hover |
| `--ui-button-border-color` | `var(--ui-field-border-color)` | — |
| `--ui-button-border-color--active` | `var(--ui-field-border-color)` | active |
| `--ui-button-border-color--hover` | `var(--ui-field-border-color)` | hover |
| `--ui-button-border-style` | `var(--ui-field-border-style)` | — |
| `--ui-button-border-width` | `var(--ui-field-border-width)` | — |
| `--ui-button-corner-shape` | `var(--ui-field-corner-shape)` | — |
| `--ui-button-font-family` | `var(--font-family-body)` | — |
| `--ui-button-font-size` | `var(--font-size-sm)` | — |
| `--ui-button-font-weight` | `var(--font-weight-strong)` | — |
| `--ui-button-gap` | `var(--spacing)` | — |
| `--ui-button-icon-size` | `var(--ui-field-icon-size)` | — |
| `--ui-button-leading` | `1` | — |
| `--ui-button-min-h` | `var(--ui-field-h)` | — |
| `--ui-button-px` | `var(--ui-field-px)` | — |
| `--ui-button-py` | `var(--ui-field-py)` | — |
| `--ui-button-radius` | `var(--ui-field-radius)` | — |
| `--ui-button-ring-color` | `var(--ui-field-ring-color)` | — |
| `--ui-button-shadow` | `0 0 transparent` | — |
| `--ui-button-text` | `var(--color-foreground)` | — |
| `--ui-button-text--active` | `var(--color-foreground)` | active |
| `--ui-button-text--hover` | `var(--color-foreground)` | hover |
