# Badge

## Usage

Import the component from its dedicated entry. The component loads its structural styles.

Import the theme in your application entry:

```ts
import '@astryx-vue/themes/neutral.css'
```

Component usage:

```vue
<script setup lang="ts">
import { Badge } from '@astryx-vue/core/Badge'
</script>

<template>
  <Badge variant="success">
    Completed
  </Badge>
</template>
```

### Anatomy

- **Icon**: An optional leading icon that helps identify the badge type at a glance.
- **Label**: The text or number shown inside the badge.

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Every status badge steals attention. Only badge states where the user needs to notice or act: errors, warnings, items requiring follow-up. If no action is needed, plain text is fine. |
| Do | Use success, warning, and error variants only for system status that demands attention: "Failed", "Degraded", "Action Required". These have bold solid backgrounds designed to stand out. |
| Do | Use color variants (blue, purple, teal, etc.) for category tags that group or classify items: team names, content types, priority levels. |
| Do | Keep labels to one or two words. If you need more detail, put it in surrounding text instead of the badge. |
| Do | Add an icon when it helps identify the badge type quickly, but always include a text label alongside it. |
| Do | A string or number label keeps its character order under right-to-left, so `+3` and `@alice` read as written. When slot content mixes directions, mark the direction on your own content, for example with `dir` or `<bdi>`. |
| Don't | Apply a "success" badge to every healthy/active/normal item. If all rows show green "Active" badges, none stand out; the badge adds noise, not information. Show only the states that need user attention (errors, warnings, pending actions). |
| Don't | Use badges for metadata. Durations ("6h window"), counts ("12 trigger types"), dates, and descriptions are not statuses or categories; use description text (Text with type="supporting") instead. |
| Don't | Use semantic status variants (success, warning, error, info) for categories or informational content. These are visually loud and should only indicate system state. |
| Don't | Repeat the same badge in every row of a table or list. If the same value appears in most rows, it's not adding information; use plain text for common states and reserve badges for the exceptional ones. |
| Don't | Make badges clickable; they are read-only indicators. Use a button or link if the user needs to take action. |

## Examples

### Colors

Blue, cyan, green, and the other category colors group teams or topics. They do not report system status.

```vue
<script setup lang="ts">
import { Badge } from '@astryx-vue/core/Badge'
</script>

<template>
  <div class="badge-preview__group">
    <span class="badge-preview__label">Teams</span>
    <div class="badge-preview__badges">
      <Badge variant="blue">
        Design
      </Badge>
      <Badge variant="cyan">
        DevOps
      </Badge>
      <Badge variant="green">
        Backend
      </Badge>
      <Badge variant="pink">
        Marketing
      </Badge>
      <Badge variant="purple">
        Engineering
      </Badge>
      <Badge variant="teal">
        Research
      </Badge>
    </div>
  </div>
  <div class="badge-preview__group">
    <span class="badge-preview__label">Priority</span>
    <div class="badge-preview__badges">
      <Badge variant="orange">
        Urgent
      </Badge>
      <Badge variant="red">
        Critical
      </Badge>
      <Badge variant="yellow">
        Review
      </Badge>
    </div>
  </div>
</template>
```

### Counts

A short number for unread messages or open tasks. Values past 99 can read 99+.

```vue
<script setup lang="ts">
import { Badge } from '@astryx-vue/core/Badge'
</script>

<template>
  <div class="badge-preview__count">
    <Badge variant="info">
      3
    </Badge>
    <span>Messages</span>
  </div>
  <div class="badge-preview__count">
    <Badge variant="error">
      99+
    </Badge>
    <span>Alerts</span>
  </div>
  <div class="badge-preview__count">
    <Badge variant="success">
      12
    </Badge>
    <span>Completed</span>
  </div>
  <div class="badge-preview__count">
    <Badge variant="warning">
      5
    </Badge>
    <span>Pending</span>
  </div>
</template>
```

### Status

Success, warning, and error mark a state that needs attention. Neutral and info mark where something sits in a workflow.

```vue
<script setup lang="ts">
import { Badge } from '@astryx-vue/core/Badge'
import { HStack, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <VStack :gap="6">
    <VStack :gap="2">
      <Text type="supporting" color="secondary">
        System status
      </Text>
      <HStack :gap="2" align="center">
        <Badge variant="success">
          Active
        </Badge>
        <Badge variant="warning">
          Pending
        </Badge>
        <Badge variant="error">
          Failed
        </Badge>
      </HStack>
    </VStack>
    <VStack :gap="2">
      <Text type="supporting" color="secondary">
        Workflow
      </Text>
      <HStack :gap="2" align="center">
        <Badge variant="neutral">
          Draft
        </Badge>
        <Badge variant="info">
          In Review
        </Badge>
      </HStack>
    </VStack>
  </VStack>
</template>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `BadgeVariant` | `'neutral'` | Sets the visual variant of the badge. Optional: neutral, info, success, warning, error, blue, cyan, green, orange, pink, purple, red, teal, yellow. |
| `label` | `string \| number` | - | Badge text. Give the text here or through the default slot; the slot wins when both are set. A badge is one line and at least as tall as that line, so it grows with a larger text size. It is as wide as its label, so it does not stretch to fill a grid cell or a stack; a label wider than the space available ends in an ellipsis, and a string or number label is also set as the title. |

## Slots

| Name | Description |
| --- | --- |
| `default` | Text content displayed by the badge. |
| `icon` | Optional leading icon. An icon should not replace the text label. |

## Native attributes

The root element is `<span>`.

The root element receives:

- HTML attributes.
- `aria-*` attributes.
- `data-*` attributes.
- `class`.
- `style`.
- Native event listeners.

`Badge` is a read-only indicator. Do not add interactive behavior.
