# chatty-chip

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

## Key rules

- `chatty-chip` khai báo 4 attribute, 0 property không có attribute, 2 event, 2 slot, 3 part và 3 CSS custom property.
- Import 1 module `@avada/chatty-ui/elements/chip.js` là define `chatty-chip`; 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 compact value pill (an active filter); removable chips add a remove button. Class `ChattyChip`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `variant` | `variant` | `'secondary' \| 'tertiary'` | `'tertiary'` | tertiary = outlined (default, suggestions and filters); secondary = filled, the selected look. |
| `size` | `size` | `'sm' \| 'md'` | `'md'` | sm is the admin 20px tag; md is the storefront chip. |
| `removable` | `removable` | `boolean` | `false` | Adds a remove button that fires chatty-remove. |
| `remove-label` | `removeLabel` | `string` | `'Remove'` | Accessible name of the remove button. |

### Properties

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

Not declared in the manifest.

### Events

| Name | Detail type | Description |
| --- | --- | --- |
| `chatty-remove` | `CustomEvent<void>` | The remove button was activated; the host removes the chip. |
| `click` | `MouseEvent` | Native click, retargeted to the host; the remove button also fires chatty-remove. |

### Slots

| Name | Description |
| --- | --- |
| default | Chip text. |
| `remove-icon` | Replaces the default × glyph of the remove button. |

### Parts

| Name | Description |
| --- | --- |
| `base` | Pill box. |
| `label` | Text wrapper. |
| `remove` | Native remove button. |

### CSS custom properties

| Name | Default | Description |
| --- | --- | --- |
| `--chatty-chip-background` | – | Background scoped by variant (secondary = filled, the selected look). |
| `--chatty-chip-color` | – | Text colour. |
| `--chatty-chip-radius` | – | Corner radius. |

## Usage

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

```html
<chatty-chip>Shipping</chatty-chip>
<chatty-chip>Returns</chatty-chip>
<chatty-chip variant="secondary">Selected</chatty-chip>
<chatty-chip size="sm">Orders</chatty-chip>
<chatty-chip removable remove-label="Remove filter Website">Website</chatty-chip>
```

## 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-chip>Shipping</chatty-chip>
<chatty-chip>Returns</chatty-chip>
<chatty-chip variant="secondary">Selected</chatty-chip>
<chatty-chip size="sm">Orders</chatty-chip>
<chatty-chip removable remove-label="Remove filter Website">Website</chatty-chip>
```

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

```html
<chatty-chip size="sm" removable remove-label="Remove filter PDF">PDF</chatty-chip>
<chatty-chip size="sm" removable remove-label="Remove filter Website">Website</chatty-chip>
<chatty-chip size="sm" variant="secondary" removable remove-label="Remove filter Covered">Covered</chatty-chip>
```

## 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-chip>Shipping</chatty-chip>
<chatty-chip>Returns</chatty-chip>
<chatty-chip variant="secondary">Selected</chatty-chip>
<chatty-chip size="sm">Orders</chatty-chip>
<chatty-chip removable remove-label="Remove filter Website">Website</chatty-chip>
```

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

## Keyboard

| Key | Action |
| --- | --- |
| Enter / Space | Activate the remove button when removable. |

### Source

- chatty-ui/custom-elements.json
