# Badge

Nhãn ngắn của kit chung; Knowledge files bọc nó bằng class và data-tone riêng.

## Key rules

- Dùng `Badge` với `variant="outline"` và class `kb-ide__badge`; màu theo `data-tone`.
- CSS trang khai báo chữ 11px, weight 500, bo 4px, padding 1px 5px.
- `Badge` là `div` không tương tác; nghĩa của status phải nằm trong chữ, không chỉ trong màu.
- Element `chatty-badge` ở mục Standard là chuẩn chatty-ui port theo; các mục theo surface mô tả component React đang chạy.

## Use when / Avoid

Dùng cho nhãn status ngắn cạnh một đối tượng. Không dùng làm nút và không nhét câu dài. Wrapper `KnowledgeBadge` có trong source nhưng hiện chưa có file nào import nó; các nhãn đang hiện trong màn Knowledge files gọi Polaris `Badge`.

### Use instead

| Component | Use when |
| --- | --- |
| `Badge` | Nhãn status của kit chung, dùng class trang cho màu. |
| `Badge` | Màn Knowledge files hiện gọi Polaris `Badge` với `tone`, không phải kit. |

## Live preview

Example (Standard) — Element chatty-badge: variant, size và tone; token admin, không màu merchant.

```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) — Element chatty-badge size sm viền như nhãn Knowledge files.

```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>
```

Example (Current (React), being replaced) — Badge outline với class Knowledge files; dữ liệu cục bộ.

```jsx
import React from 'react';
import {Badge} from '@avada/chatty-ui/components/badge.js';
export function Status() {
  return <div><Badge variant="outline" className="kb-ide__badge" data-tone="covered">Covered</Badge><Badge variant="outline" className="kb-ide__badge">99+</Badge></div>;
}
```

## Standard

Example (Standard) — Element chatty-badge: variant, size và tone; token admin, không màu merchant.

```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>
```

Prototype  (cùng `badge.styles.js` và ) là chuẩn: chatty-ui port 1:1 các file này, và `chatty-ui/custom-elements.json` sinh từ chính prototype. Chưa surface nào dùng element thật; các mục theo surface bên dưới mô tả React đang chạy. Knowledge files vẫn chuyển sang Polaris theo Target; preview admin-kb chỉ để xem element dưới token admin.

### Element

| Element | Module |
| --- | --- |
| `chatty-badge` | @avada/chatty-ui/elements/badge.js |

### API

| Kind | Name | Type | Default | Description |
| --- | --- | --- | --- | --- |
| attribute | `variant` | primary, secondary, tertiary | `'primary'` | primary nền tone đặc, secondary nền nhạt, tertiary chỉ viền. |
| attribute | `tone` | neutral, critical, success, caution | `'neutral'` | Ý nghĩa màu; chữ trong badge vẫn phải tự nói status. |
| attribute | `size` | sm, md, lg | `'md'` | Cỡ chữ và padding. |
| slot | default | – | – | Chữ của badge. |
| part | `base` | – | – | Khung pill. |
| css-property | `--chatty-badge-background` | – | – | Nền theo variant và tone. |
| css-property | `--chatty-badge-color` | – | – | Màu chữ theo variant và tone. |
| css-property | `--chatty-badge-radius` | – | – | Bo góc; mặc định pill. |

## Admin · Knowledge files

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `Badge` | @avada/chatty-ui/components/badge.js | .kb-ide-page > .kb-ide |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | Root `div` của `Badge` mang class kit, `className` và props. |
| 2 | Nội dung `children` trong root; caller cấp chữ. |

### Placement / order

| Context | Order |
| --- | --- |
| Wrapper trang | `KnowledgeBadge` render một `Badge` duy nhất với `children`; không có icon. |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `variant` | string | default, secondary, destructive, outline, success, warning | `default` | KnowledgeBadge luôn truyền `outline`. |
| `size` | string | sm, default, lg | `default` | KnowledgeBadge không truyền size. |
| `className` | string | CSS classes | undefined | Gộp cuối; trang truyền `kb-ide__badge`. |
| `data-tone` | attribute | error, conflict, warning, pending, partial, audited, covered, draft | Không có | Trang đổi màu theo attribute; component chuyển qua props. |
| `children` | ReactNode | Chữ của caller | undefined | Không giới hạn độ dài hay định dạng số. |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| kit sm | Theo nội dung | `chatty:px-2` / `chatty:py-0.5` | Không khai báo | `chatty:rounded-full` | `chatty:text-xs` | Không tương tác | Class theo `size` |
| kit default | Theo nội dung | `chatty:px-2.5` / `chatty:py-0.5` | Không khai báo | `chatty:rounded-full` | `chatty:text-sm` | Không tương tác | Class theo `size` |
| kit lg | Theo nội dung | `chatty:px-3` / `chatty:py-1` | Không khai báo | `chatty:rounded-full` | `chatty:text-base` | Không tương tác | Class theo `size` |
| Knowledge files page | `line-height: 1.5` | 1px 5px | Không khai báo | 4px | `font-size: 11px`; weight 500 | Không tương tác | Rule không có media query |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Base text | `--p-color-text-secondary` | #616161 | No Dark skin |
| Base fill | `--p-color-bg-surface-secondary` | #f7f7f7 | No Dark skin |
| Base border | `--p-color-border-secondary` | #ebebeb | No Dark skin |
| error / conflict text | `--p-color-text-critical` | #8e0b21 | No Dark skin |
| error / conflict fill | `--p-color-bg-surface-critical` | #fee8eb | No Dark skin |
| error / conflict border | `--p-color-border-critical-secondary` | #8e0b21 | No Dark skin |
| warning / pending / partial text | `--p-color-text-caution` | #4f4700 | No Dark skin |
| warning / pending / partial fill | `--p-color-bg-surface-caution` | #fff8db | No Dark skin |
| warning / pending / partial border | `--p-color-border-caution-secondary` | Không khai báo trong Polaris 13.9.5 | No Dark skin |
| audited / covered text | `--p-color-text-success` | #014b40 | No Dark skin |
| audited / covered fill | `--p-color-bg-surface-success` | #cdfed4 | No Dark skin |
| audited / covered border | `--p-color-border-success-secondary` | Không khai báo trong Polaris 13.9.5 | No Dark skin |
| draft text | `--p-color-text-link` | #005bd3 | No Dark skin |
| draft fill | `--p-color-bg-surface-info` | #eaf4ff | No Dark skin |
| draft border | `--p-color-border-info-secondary` | Không khai báo trong Polaris 13.9.5 | No Dark skin |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Base | Không có `data-tone` | Màu theo Tokens dòng Base | Không thêm ARIA |
| error / conflict | `data-tone` = error hoặc conflict | Chữ, nền, viền theo Tokens | `data-tone` attribute |
| warning / pending / partial | `data-tone` = warning, pending hoặc partial | Chữ, nền, viền theo Tokens | `data-tone` attribute |
| audited / covered | `data-tone` = audited hoặc covered | Chữ, nền, viền theo Tokens | `data-tone` attribute |
| draft | `data-tone` = draft | Chữ, nền, viền theo Tokens | `data-tone` attribute |

### Behaviour

| Interaction | Result |
| --- | --- |
| Chữ dài | Rule trang có `width: fit-content` và `flex-shrink: 0`; không có cắt dòng riêng. |
| Focus | Kit có class focus ring cho root; root là div, caller không thêm tabindex trong wrapper. |
| Count | Component không giới hạn hay định dạng số; `children` hiển thị nguyên. |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| Caller label | Caller-owned | `children` của wrapper |

### Source

| File | Evidence |
| --- | --- |
|  | API và class kit |
|  | Wrapper trang |
|  | Style và tone |

## Do / Don't

Do: viết status bằng chữ ngắn và để `data-tone` chỉ làm tăng nhận biết.

Don't: dùng màu làm dấu hiệu duy nhất; không biến `Badge` thành nút.

## Accessibility

| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
| --- | --- | --- | --- | --- |
| Admin · Knowledge files | div không role; tên là chữ children | Không focusable, không có handler | Không có | Base Measured(#616161 / #f7f7f7 = 5.78:1); error Measured(#8e0b21 / #fee8eb = 8.09:1); warning Measured(#4f4700 / #fff8db = 8.82:1); covered Measured(#014b40 / #cdfed4 = 8.99:1); draft Measured(#005bd3 / #eaf4ff = 5.49:1) |

## Target

```target
| Surface | Now | Target | Source |
| --- | --- | --- | --- |
| Admin · Knowledge files | Viền của tone warning, covered và draft dùng token không khai báo trong Polaris 13.9.5 | Not in code yet — build with the body values. Dùng token viền có khai báo `--p-color-border-caution`, `--p-color-border-success`, `--p-color-border-info`; giữ border 1px solid và radius 4px, không đổi chữ hay nền. |  |
| Admin · Knowledge files | Badge của kit chung trong Knowledge files | Not available — new build follows Target. Knowledge files không dùng `chatty-*`: chuyển sang Polaris `Badge`, vì trang admin ngoài inbox giữ Polaris. | [Shopify: Built for Shopify requirements](https://shopify.dev/docs/apps/launch/built-for-shopify/requirements) |
| Classic · AI Mode · Admin | Component React theo surface | Not available — new build follows Target. Port `chatty-badge` từ mục Standard rồi chuyển caller từng surface; Inbox Target dùng token chatty-ui literal theo giá trị 2.0; gỡ wrapper hiện tại ở phase 1b trước khi chuyển caller. |  |
| Admin | Component Inbox đúng Target chưa ship | Not available — new build follows Target. **Badge**: neutral/caution; info/success/warning/critical; progress complete/partial/incomplete; 20px, radius tag 6px, badge-label 12px/18px w500. Dùng ở Return customer (10), order badges (15), Verified, Change request, Resolved. Không dùng component Polaris trong Inbox; giữ App Bridge cho phần khung embedded. | [Shopify: Built for Shopify requirements](https://shopify.dev/docs/apps/launch/built-for-shopify/requirements) |
```

![Inbox Badge design target](https://chatty-ui-research.avada-tesla-chatty.workers.dev/maps/inbox-target-overview.webp)

Ảnh Target từ mock; các trạng thái chưa xuất hiện trong ảnh vẫn là yêu cầu triển khai, không claim đã ship.


- [Shopify: Built for Shopify requirements](https://shopify.dev/docs/apps/launch/built-for-shopify/requirements)
- [MDN: Web Components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components)
