# chatty-badge

API chuẩn của element chatty-badge, sinh từ custom-elements.json của prototype trong guide.

## Key rules

- `chatty-badge` khai báo 3 attribute, 0 property không có attribute, 0 event, 1 slot, 1 part và 3 CSS custom property.
- Import 1 module `@avada/chatty-ui/elements/badge.js` là define `chatty-badge`; chunk chỉ import element nó dùng. Prototype chuẩn:  trong guide.
- Đổi tên attribute, event, slot, part hay CSS custom property là đổi API: diff của custom-elements.json phải có trong 1 MR.

## Overview

A short, non-interactive status label; the meaning lives in the text, the tone only repeats it. Class `ChattyBadge`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `variant` | `variant` | `'primary' \| 'secondary' \| 'tertiary'` | `'primary'` | primary = solid tone fill, secondary = subtle fill, tertiary = outline. |
| `tone` | `tone` | `'neutral' \| 'critical' \| 'success' \| 'caution'` | `'neutral'` | Colour by meaning; the text must still state the status. |
| `size` | `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | sm is the admin 20px badge; md and lg grow text and padding. |

### Properties

Attributes also expose the properties listed in the Property column above.

Not declared in the manifest.

### Events

Not declared in the manifest.

### Slots

| Name | Description |
| --- | --- |
| default | Label text. |

### Parts

| Name | Description |
| --- | --- |
| `base` | Pill box. |

### CSS custom properties

| Name | Default | Description |
| --- | --- | --- |
| `--chatty-badge-background` | – | Background scoped by variant and tone. |
| `--chatty-badge-color` | – | Text colour scoped by variant and tone. |
| `--chatty-badge-radius` | – | Corner radius. |

## Usage

```js
import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/badge.js';
```

```html
<chatty-badge>New</chatty-badge>
<chatty-badge variant="secondary">Draft</chatty-badge>
<chatty-badge variant="tertiary">Covered</chatty-badge>
<chatty-badge size="sm">3</chatty-badge>
<chatty-badge size="lg">Open</chatty-badge>
<chatty-badge tone="critical">Failed</chatty-badge>
<chatty-badge tone="success">Synced</chatty-badge>
<chatty-badge tone="caution">Pending</chatty-badge>
<chatty-badge variant="secondary" tone="success">Active</chatty-badge>
<chatty-badge variant="tertiary" tone="critical">Not covered</chatty-badge>
```

## Live preview

Component thật dùng cùng story với trang component; dữ liệu mẫu nằm trong frame cục bộ.

Example (Standard) — Default: trạng thái mặc định và nội dung mẫu của element.

```html
<chatty-badge>New</chatty-badge>
<chatty-badge variant="secondary">Draft</chatty-badge>
<chatty-badge variant="tertiary">Covered</chatty-badge>
<chatty-badge size="sm">3</chatty-badge>
<chatty-badge size="lg">Open</chatty-badge>
<chatty-badge tone="critical">Failed</chatty-badge>
<chatty-badge tone="success">Synced</chatty-badge>
<chatty-badge tone="caution">Pending</chatty-badge>
<chatty-badge variant="secondary" tone="success">Active</chatty-badge>
<chatty-badge variant="tertiary" tone="critical">Not covered</chatty-badge>
```

Example (Standard) — Các variant hoặc state chính đặt cạnh nhau trong cùng ví dụ.

```html
<chatty-badge size="sm" variant="tertiary">Draft</chatty-badge>
<chatty-badge size="sm" variant="tertiary" tone="success">Covered</chatty-badge>
<chatty-badge size="sm" variant="tertiary" tone="caution">Pending</chatty-badge>
<chatty-badge size="sm" variant="tertiary" tone="critical">Not covered</chatty-badge>
```

## Anatomy

Số trong hình khớp bảng bên dưới. Phần chỉ hiện ở state khác được ghi Not shown; ví dụ không thêm phần tử giả.

Example (Standard) — Anatomy: một instance mặc định riêng, có khoảng trống quanh các phần được đánh số.

```html
<chatty-badge>New</chatty-badge>
<chatty-badge variant="secondary">Draft</chatty-badge>
<chatty-badge variant="tertiary">Covered</chatty-badge>
<chatty-badge size="sm">3</chatty-badge>
<chatty-badge size="lg">Open</chatty-badge>
<chatty-badge tone="critical">Failed</chatty-badge>
<chatty-badge tone="success">Synced</chatty-badge>
<chatty-badge tone="caution">Pending</chatty-badge>
<chatty-badge variant="secondary" tone="success">Active</chatty-badge>
<chatty-badge variant="tertiary" tone="critical">Not covered</chatty-badge>
```

| Part | Element | Source |
| --- | --- | --- |
| 1 | CSS part `base` | chatty-ui/custom-elements.json |

## Keyboard

No element-specific keys.

### Source

- chatty-ui/custom-elements.json
