# Badge

A small label for status, counts, and categories.

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

## Installation

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

Also adds `fields`, 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 type="button" data-ui="badge">Category</button>
  <button type="button" data-ui="badge" data-badge-variant="primary">New</button>
  <button type="button" data-ui="badge" data-badge-variant="muted">Draft</button>
  <button type="button" data-ui="badge" data-badge-variant="ghost">Inline</button>
  <button type="button" data-ui="badge" data-badge-variant="info">Update</button>
  <button type="button" data-ui="badge" data-badge-variant="success">Paid</button>
  <button type="button" data-ui="badge" data-badge-variant="warning">Pending</button>
  <button type="button" data-ui="badge" data-badge-variant="destructive">Overdue</button>
  <button type="button" data-ui="badge" data-badge-variant="link">Posts</button>
</div>
```

### Icon

```html
<button type="button" data-ui="badge" data-badge-size="icon" aria-label="Icon badge default">
  <svg fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
    <rect width="256" height="256" fill="none" />
    <circle cx="128" cy="128" r="12" />
    <circle cx="196" cy="128" r="12" />
    <circle cx="60" cy="128" r="12" />
  </svg>
</button>
<button
  type="button"
  data-ui="badge"
  data-badge-size="icon"
  data-badge-variant="primary"
  aria-label="Icon badge primary"
>
  <svg fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
    <rect width="256" height="256" fill="none" />
    <circle cx="128" cy="128" r="12" />
    <circle cx="196" cy="128" r="12" />
    <circle cx="60" cy="128" r="12" />
  </svg>
</button>
<button
  type="button"
  data-ui="badge"
  data-badge-size="icon"
  data-badge-variant="muted"
  aria-label="Icon badge muted"
>
  <svg fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
    <rect width="256" height="256" fill="none" />
    <circle cx="128" cy="128" r="12" />
    <circle cx="196" cy="128" r="12" />
    <circle cx="60" cy="128" r="12" />
  </svg>
</button>
<button
  type="button"
  data-ui="badge"
  data-badge-size="icon"
  data-badge-variant="ghost"
  aria-label="Icon badge ghost"
>
  <svg fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
    <rect width="256" height="256" fill="none" />
    <circle cx="128" cy="128" r="12" />
    <circle cx="196" cy="128" r="12" />
    <circle cx="60" cy="128" r="12" />
  </svg>
</button>
```

## Attributes

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

Requires: fields.

## Hooks

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