## class: `WyBadge`, `wy-badge`

Small badge component showing a count, a text label or a generic dot indicator.

The badge kind is decided from the text content of the element:

*   Empty, whitespace or `0` renders nothing, so `<wy-badge>${unread}</wy-badge>` hides itself when there is nothing unread.
*   A whole number renders a count badge, truncated to `limit` (`100` → `99+`).
*   Any other text renders a text badge, truncated with an ellipsis at `--wy-badge-max-width`.
*   The `dot` attribute renders a generic dot indicator. The content remains available to assistive technology.

Hover text is only shown when an explicit `title` is provided.

The `color` attribute picks the color pair. The default is the primary pair, which draws attention, such as an
unread count. `variant` is the muted secondary-container pair for a count that is information rather than a call to
action, such as the votes on a poll option.

### Examples

<figure class="example"><figcaption>Count, text and dot badges</figcaption>

```html
<wy-badge>3</wy-badge>
<wy-badge>Draft</wy-badge>
<wy-badge title="You have a draft">Draft</wy-badge>
<wy-badge dot>New messages</wy-badge>
<wy-badge color="variant">12</wy-badge>
```

</figure>

### Fields

| Name       | Type                     | Default     | Description                                                              | Inherited From |
| ---------- | ------------------------ | ----------- | ------------------------------------------------------------------------ | -------------- |
| `dot`      | `boolean`                | `false`     | Show a generic dot indicator instead of the content.                     |                |
| `position` | `PositionType`           | `"inline"`  | Positioning of the badge                                                 |                |
| `color`    | `"primary" \| "variant"` | `"primary"` | Color pair of the badge: \`primary\` (default) or the muted \`variant\`. |                |
| `reveal`   | `boolean`                | `false`     | Whether to animate showing the badge                                     |                |
| `delayed`  | `boolean`                | `false`     | Whether to delay showing the badge                                       |                |
| `limit`    | `number`                 | `99`        | Limit for count truncation. Set to Infinity for no truncation.           |                |
| `title`    | `string`                 | `""`        | Optional hover text. No tooltip is shown unless explicitly provided.     |                |

### Attributes

| Name       | Field    | Inherited From |
| ---------- | -------- | -------------- |
| `dot`      | dot      |                |
| `position` | position |                |
| `color`    | color    |                |
| `reveal`   | reveal   |                |
| `delayed`  | delayed  |                |
| `limit`    | limit    |                |
| `title`    | title    |                |

### CSS Parts

| Name                      | Description                                                                   |
| ------------------------- | ----------------------------------------------------------------------------- |
| `wy-badge`                | Root badge container.                                                         |
| `wy-badge-variant`        | Modifier for the muted \`variant\` color.                                     |
| `wy-badge-reveal`         | Modifier styles for revealing the badge.                                      |
| `wy-badge-reveal-delayed` | Modifier styles for delaying the reveal.                                      |
| `wy-badge-count`          | Modifier when a count is displayed.                                           |
| `wy-badge-text`           | Modifier when a text label is displayed.                                      |
| `wy-badge-dot`            | Modifier when the dot indicator is displayed.                                 |
| `wy-badge-label`          | Visually hidden label inside a dot badge.                                     |
| `wy-badge-positioned`     | Modifier for using absolute positioning.                                      |
| `wy-badge-top-right`      | Modifier for positioning in top right corner with \`wy-badge-positioned\`.    |
| `wy-badge-top-left`       | Modifier for positioning in top left corner with \`wy-badge-positioned\`.     |
| `wy-badge-bottom-right`   | Modifier for positioning in bottom right corner with \`wy-badge-positioned\`. |
| `wy-badge-bottom-left`    | Modifier for positioning in bottom left corner with \`wy-badge-positioned\`.  |

<details><summary>Private API</summary>

### Fields

| Name          | Privacy   | Type     | Default                                           | Description                          | Inherited From |
| ------------- | --------- | -------- | ------------------------------------------------- | ------------------------------------ | -------------- |
| `exportParts` | protected |          | `new ShadowPartsController(this)`                 |                                      |                |
| `content`     | protected | `string` | `""`                                              | Trimmed text content of the element. |                |
| `#observer`   | private   |          | `new MutationObserver(() => this.#readContent())` |                                      |                |

### Methods

| Name           | Privacy | Description | Parameters | Return | Inherited From |
| -------------- | ------- | ----------- | ---------- | ------ | -------------- |
| `#readContent` | private |             |            |        |                |

</details>

<hr/>

## Exports

| Kind                        | Name       | Declaration | Module                        | Package |
| --------------------------- | ---------- | ----------- | ----------------------------- | ------- |
| `js`                        | `WyBadge`  | WyBadge     | lib/components/ui/wy-badge.ts |         |
| `custom-element-definition` | `wy-badge` | WyBadge     | lib/components/ui/wy-badge.ts |         |
