# Suggestion chip

Chip của kit chung; Knowledge files dùng nó làm chip lọc có nút xoá.

## Key rules

- Dùng `Chip` với `size="small"`, `variant="outlined"` và `onDelete` cho bộ lọc đang bật.
- CSS trang khai báo chip 11px, padding 2px 6px, nút xoá 16px × 16px.
- Root `Chip` là `div` không tương tác; chỉ nút xoá là `button` có tên từ `deleteLabel`.
- Element `chatty-chip` ở 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 khi cần hiện một giá trị lọc đang chọn và cho gỡ từng giá trị. Chip không có prop selected, không có hành động trên thân chip và không có trạng thái disabled; gợi ý bước tiếp theo trong hội thoại không dùng component này trong source hiện tại.

### Use instead

| Component | Use when |
| --- | --- |
| `Chip` | Hiện giá trị lọc đang bật kèm nút xoá, như Explorer. |
| `Button` | Hành động có kết quả; thân `Chip` không nhận hành động. |

## Live preview

Example (Standard) — Element chatty-chip: variant, size và nút xoá; token admin, không màu merchant.

```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) — Element chatty-chip size sm như thanh lọc Knowledge files: cao 20px, nút xoá 24px.

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

Example (Current (React), being replaced) — Chip nhỏ, outlined và có nút xoá như Explorer; dữ liệu cục bộ.

```jsx
import React, {useState} from 'react';
import {Chip} from '@avada/chatty-ui/components/chip.js';

const filters = [
  {key: 'status', label: 'Status: Active'},
  {key: 'verified', label: 'Verified'},
  {key: 'topic', label: 'Topic: Shipping'}
];

export function Example() {
  const [active, setActive] = useState(filters);
  return (
    <div className="kb-ide__active-filters">
      {active.map(({key, label}) => (
        <Chip
          key={key}
          size="small"
          variant="outlined"
          deleteLabel={`Remove ${label} filter`}
          onDelete={() => setActive(current => current.filter(item => item.key !== key))}
        >
          {label}
        </Chip>
      ))}
    </div>
  );
}
```

## Standard

Example (Standard) — Element chatty-chip: variant, size và nút xoá; token admin, không màu merchant.

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

Prototype  (cùng `chip.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-chip` | @avada/chatty-ui/elements/chip.js |

### API

| Kind | Name | Type | Default | Description |
| --- | --- | --- | --- | --- |
| attribute | `variant` | secondary, tertiary | `'tertiary'` | tertiary viền (mặc định), secondary nền là trạng thái chọn. |
| attribute | `size` | sm, md | `'md'` | Cỡ chữ và padding. |
| attribute | `removable` | boolean | `false` | Thêm nút xoá ở cuối chip. |
| attribute | `remove-label` | string | `'Remove'` | Tên truy cập của nút xoá. |
| event | `chatty-remove` | `CustomEvent<void>` | – | Nút xoá được kích hoạt; host tự gỡ chip. |
| event | `click` | MouseEvent | – | Click native, retarget về host; nút xoá còn bắn chatty-remove. |
| slot | default | – | – | Chữ của chip. |
| slot | `remove-icon` | – | – | Thay glyph × mặc định của nút xoá. |
| part | `base` | – | – | Khung pill. |
| part | `label` | – | – | Vùng chứa chữ. |
| part | `remove` | – | – | Nút xoá native. |
| css-property | `--chatty-chip-background` | – | – | Nền theo variant. |
| css-property | `--chatty-chip-color` | – | – | Màu chữ. |
| css-property | `--chatty-chip-radius` | – | – | Bo góc; mặc định pill. |

## Admin · Knowledge files

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `Chip` | @avada/chatty-ui/components/chip.js | .kb-ide-page .kb-ide\_\_active-filters |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | Root `div` của Chip, mang class kit và props. |
| 2 | Nội dung `children` trong root. |
| 3 | Nút xoá `button` chỉ có khi truyền `onDelete`; mặc định hiện ×. |

### Placement / order

| Context | Order |
| --- | --- |
| Explorer filter | Một `Chip` cho mỗi bộ lọc đang bật, theo thứ tự activeFilters; cả khối chỉ render khi có ít nhất một bộ lọc. |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `variant` | string | filled, outlined | `filled` | Explorer truyền `outlined`. |
| `size` | string | small, medium | `medium` | Explorer truyền `small`. |
| `color` | string | default, khác default | `default` | Chỉ đổi fill của `filled`; `outlined` bỏ qua. |
| `onDelete` | function | Handler | undefined | Có giá trị thì render nút xoá. |
| `deleteIcon` | ReactNode | Icon của caller | undefined | Thay ký tự ×. |
| `deleteLabel` | string | Tên truy cập của nút xoá | `Remove` | Chuyển vào `aria-label`. |
| `className` | string | CSS classes | undefined | Gộp cuối. |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| kit small | Theo nội dung | `chatty:px-2` / `chatty:py-1` | `chatty:gap-1` | `chatty:rounded-full` | `chatty:text-xs` | Nút xoá `chatty:h-4` × `chatty:w-4` | Class theo `size` |
| kit medium | Theo nội dung | `chatty:px-3` / `chatty:py-1` | `chatty:gap-1` | `chatty:rounded-full` | `chatty:text-sm` | Nút xoá `chatty:h-4` × `chatty:w-4` | Class theo `size` |
| Knowledge files chip | Theo nội dung | 2px 6px | 4px giữa các chip | 8px | `font-size: 11px` | Không tương tác trên thân chip | Rule `.kb-ide__active-filters > div` |
| Knowledge files remove | 16px × 16px | 0 | Không khai báo | Không khai báo | Theo chip | 16px × 16px | Rule `.kb-ide__active-filters button` |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Chip text | `--p-color-text` | #303030 | No Dark skin |
| Chip fill | `--p-color-bg-fill-secondary` | #f1f1f1 | No Dark skin |
| Remove glyph | `--p-color-text-secondary` | #616161 | No Dark skin |
| Focus ring | `--p-color-border-focus` | #005bd3 | No Dark skin |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Default | Render | Chip: fill và chữ theo Tokens, `border: 0`; nút xoá `border: 0` | Không thêm ARIA trên root |
| Remove hover | pointer | Kit khai báo `hover:chatty:bg-black/10`; trang khai báo `--p-color-bg-surface-hover` cho button hover | Native |
| Remove focus-visible | keyboard | outline 2px, offset 2px (`outline-offset`) | Native focus |
| Remove disabled | Không có prop | Trang có rule cho button disabled nhưng Chip không truyền disabled xuống nút xoá | Not available |
| Selected / pressed | Không có prop | Not available | Not available |

### Behaviour

| Interaction | Result |
| --- | --- |
| Xoá | `onDelete` của Explorer đặt bộ lọc về false hoặc chuỗi rỗng. |
| Nhiều chip | Container `flex-wrap: wrap`, khoảng cách 4px, margin-top 8px. |
| Chữ dài | Không có clamp hay cắt dòng cho label; container chỉ wrap giữa các chip. |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| Remove … filter | Remove ${filterLabels[key]} filter | `deleteLabel` của Explorer |
| Remove | Remove | Mặc định của `deleteLabel` |
| Nhãn bộ lọc | Caller-owned | Nội dung chip do Explorer ghép |

### Source

| File | Evidence |
| --- | --- |
|  | API và class kit |
|  | Caller duy nhất |
|  | Style chip trong Explorer |

## Do / Don't

Do: đặt `deleteLabel` nêu rõ bộ lọc sẽ bị gỡ.

Don't: gắn onClick vào thân `Chip`; root là `div`, không có keyboard.

## Accessibility

| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
| --- | --- | --- | --- | --- |
| Admin · Knowledge files | Root div không role; nút xoá là `button` có `aria-label` từ `deleteLabel` | Thân không focus; nút xoá Tab và Enter/Space native | Không có | Text Measured(#303030 / #f1f1f1 = 11.69:1); remove glyph Measured(#616161 / #f1f1f1 = 5.48:1) |

## Target

```target
| Surface | Now | Target | Source |
| --- | --- | --- | --- |
| Admin · Knowledge files | Chip của kit chung làm chip lọc | Not available — new build follows Target. Knowledge files không dùng `chatty-*`: chuyển sang Polaris, 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-chip` 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. |  |
```


- [Shopify: Built for Shopify requirements](https://shopify.dev/docs/apps/launch/built-for-shopify/requirements)
