# Badge

A short label for a status or a category. It uses a soft fill, or an outline when it should stay quiet. Its fill is never a solid hue; a solid appears only as the small decorative dot. Solid fills with text-on-<hue> are for Avatar.

**Dependencies:** npm: 1 direct, 2 total; registry: 2 direct, 2 total.

Native: iOS stable, Android stable.

## Usage

### When to use

- Show the state of an item next to it: Failed, Ready, Expiring.
- Tag an item with a category the user reads but doesn't act on: Design, Beta.

### When not to use

- Anything clickable or toggleable. Use Button.
- A picked value the user can take out, such as an active filter. Use Token with a remove button.
- Naming a design token or another machine value. Use Token.
- Sentences or long labels. Keep a badge label short: Beta, Failed, New.

### Native

**Status**

```text
WerewolfBadge(variant: .success, dot: true) { Text("Ready") }
```

```text
WerewolfBadge(variant = WerewolfBadgeVariant.Success, dot = true) { Text("Ready") }
```

**Small**

```text
WerewolfBadge(size: .sm) { Text("New") }
```

```text
WerewolfBadge(size = WerewolfBadgeSize.Sm) { Text("New") }
```

**Dot only**

```text
WerewolfBadge(accessibilityLabel: "New messages", ring: true, variant: .destructive)
```

```text
WerewolfBadge(accessibilityLabel = "New messages", ring = true, variant = WerewolfBadgeVariant.Destructive)
```

## Variants

### variant

default is a neutral gray label. accent uses the muted accent. outline has no fill, only a thin border. destructive, success, warning and info show a status. red, orange, yellow, green, teal, blue, purple and pink mark a category. Every filled variant pairs the soft background with its matching text color; the fill is never the solid (the dot is the only solid).

Values: `default`, `accent`, `outline`, `destructive`, `success`, `warning`, `info`, `red`, `orange`, `yellow`, `green`, `teal`, `blue`, `purple`, `pink`. Default: `default`.

### size

md is 24px tall. sm is 20px with tighter padding, like Token, for dense tables and counts inside a tab.

Values: `sm`, `md`. Default: `md`.

## Examples

### Default

```tsx
<Badge>Beta</Badge>
```

### With icon

```tsx
<Badge variant="success">
  <IconCheck size={12} />
  Ready
</Badge>
```

### Info

```tsx
<Badge variant="info">Scheduled</Badge>
```

### Status dot

```tsx
<div className="flex items-center gap-sm">
  <Badge variant="success" dot>Online</Badge>
  <Badge variant="destructive" dot>Failed</Badge>
</div>
```

### Small

```tsx
<Badge size="sm">New</Badge>
```

### Dot only

```tsx
<div className="flex items-center gap-md">
  <Badge variant="destructive" dot aria-label="New messages" />
  <span className="relative inline-flex">
    <IconMail size={20} aria-hidden="true" />
    <Badge variant="destructive" dot ring aria-label="New mail" className="absolute end-0 top-0" />
  </span>
</div>
```

## Do and don't

### Do

- Use the status variants (destructive, success, warning, info) for state, and hues for categories.
- Keep labels short: Beta, Failed, New.
- Show at most one status badge per row or card.
- Put the icon (12px) before the label.
- Use outline for a quiet neutral label next to filled badges.
- Use a dot-only badge for a notification dot on an icon, named with aria-label, and add ring when it sits on an icon or a photo.

### Don't

- Don't make a badge clickable.
- Don't use Badge for filter chips or removable tags. Anything that toggles or has a remove action is a Button.
- Don't put text or icons on a hue solid (bg-red). Solids are for dots and charts.
- Don't use the danger solid with text-on-danger for a badge; destructive is the soft pair.
- Don't restyle colors through className. Pick a variant. If none fits, open an issue instead of overriding it.

## Props

| Name | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `variant` | `enum` | `default`, `accent`, `outline`, `destructive`, `success`, `warning`, `info`, `red`, `orange`, `yellow`, `green`, `teal`, `blue`, `purple`, `pink` | `default` | default is a neutral gray label. accent uses the muted accent. outline has no fill, only a thin border. destructive, success, warning and info show a status. red, orange, yellow, green, teal, blue, purple and pink mark a category. Every filled variant pairs the soft background with its matching text color; the fill is never the solid (the dot is the only solid). |
| `size` | `enum` | `sm`, `md` | `md` | md is 24px tall. sm is 20px with tighter padding, like Token, for dense tables and counts inside a tab. |
| `dot` | `boolean` |  | `false` | A 6px status dot before the label, on the solid of the badge's hue (bg-danger for destructive, bg-<hue> for a hue). The only solid in a badge. Decorative: the label still carries the meaning. With no label the badge is the dot alone, with no pill: name it with aria-label (accessibilityLabel on native), for example a notification dot on an icon. |
| `ring` | `boolean` |  | `false` | Dot-only badge: adds a spacing-2xs ring in the page color around the dot, so it reads on an icon or any surface. Ignored when the badge has a label. |
| `accessibilityLabel` | `string` |  |  | The name VoiceOver and TalkBack read for a dot-only badge, such as New messages. Required by the dot-only form, as aria-label is what names it on the web. Only on iOS, Android. |

### Slots

| Name | Required | Description |
| --- | --- | --- |
| `label` | yes | Short label, sentence case or a single status word. Leave it out only with dot, for a dot-only badge. |
| `icon` | no | Optional leading icon. |

## Anatomy

| Part | Description |
| --- | --- |
| `root` | The badge surface: size-inline-md (24px) tall, size-inline-sm (20px) for size sm, soft fill, radius-element, compact type. |
| `icon` | Optional Tabler icon before the label, 12px. |
| `dot` | Optional status dot, data-slot badge-dot, aria-hidden. A circle of spacing-2xs * 3 (6px) on the solid of the badge hue; the only solid in a badge. There is no size token for it, so the size is an expression. With dot and no label the dot is the whole badge: no pill, padding or height. |
| `ring` | Dot-only badge with ring: a spacing-2xs ring in color-background-page around the dot (on the web the --ring-offset-color AvatarStack uses, the page by default), so the dot reads on an icon, a photo or any surface. |

## Accessibility

Role: `generic`

- Badge is not interactive. Don't make it a link or button; put the action on the row or card instead.
- Color is not the only cue: keep a short text label (Failed, not only a red dot).
- A dot-only badge (dot with no label) is named by aria-label and then has role="img"; on iOS and Android the dot-only form requires accessibilityLabel. Without aria-label on the web it is aria-hidden, for a parent that names it (BottomNavItem names its dot through dotLabel).
- Root is a plain span with no role, so a badge is never a live region by default. If a badge's text changes and must be announced (a build going from Running to Failed), add role="status" at the call site.

## Install

```bash
npx werewolf-ui add badge
```

Run `npx werewolf-ui init` once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See [Installation](https://www.werewolf-ui.dev/docs/installation.md) for requirements and the alternative registry setup.

```bash
npx werewolf-ui add badge --platform ios
npx werewolf-ui add badge --platform android
```

For iOS and Android, run `npx werewolf-ui init --platform ios` or `npx werewolf-ui init --platform android` once, then add with `--platform`. See [Installation](https://www.werewolf-ui.dev/docs/installation.md).
