# chatty-launcher

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

## Key rules

- `chatty-launcher` khai báo 6 attribute, 0 property không có attribute, 3 event, 3 slot, 5 part và 2 CSS custom property.
- Import 1 module `@avada/chatty-ui/elements/launcher.js` là define `chatty-launcher`; 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

AI Mode resting launcher: a pill with the assistant orb and an invite line that opens the panel, and an optional bag button that opens the cart. Pointer enter or focus asks the host to preload the panel once. Class `ChattyLauncher`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `label` | `label` | `string` | `''` | Accessible name of the trigger, e.g. `Open Chatty`. |
| `bag` | `bag` | `boolean` | `false` | Show the bag button; a confirmed empty cart removes it. |
| `count` | `count` | `number` | `0` | Items in the cart; the badge shows above 0, capped at 99+. |
| `bag-label` | `bagLabel` | `string` | `'Shopping bag'` | Bag button name when the count is 0. |
| `count-label` | `countLabel` | `string` | `'{count} items in cart'` | Bag name when count is above 0; `{count}` is replaced. |
| `live` | `live` | `boolean` | `false` | Show the online dot on the orb. |

### Properties

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

Not declared in the manifest.

### Events

| Name | Detail type | Description |
| --- | --- | --- |
| `chatty-open` | `CustomEvent<{target: 'panel' \| 'bag'}>` | The trigger or the bag was activated. |
| `chatty-preload` | `CustomEvent<{}>` | First pointer enter or focus; load the panel ahead. |
| `click` | `MouseEvent` | Native activation of the trigger or bag. |

### Slots

| Name | Description |
| --- | --- |
| default | Invite line, e.g. `Ask a question`. |
| `icon` | Assistant icon inside the 40px orb. |
| `bag-icon` | Bag icon; shown when `bag` is set. |

### Parts

| Name | Description |
| --- | --- |
| `base` | Pill container. |
| `trigger` | Button that opens the panel. |
| `orb` | Assistant orb. |
| `bag` | Bag button. |
| `count` | Bag count badge. |

### CSS custom properties

| Name | Default | Description |
| --- | --- | --- |
| `--chatty-launcher-width` | – | Pill width. |
| `--chatty-launcher-background` | – | Pill background. |

## Usage

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

```html
<chatty-launcher label="Open Chatty" live>
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
</chatty-launcher>
<chatty-launcher label="Open Chatty" bag count="2">
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
  <svg
    slot="bag-icon"
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="1.8"
    aria-hidden="true"
  >
    <path d="M5 8h14l-1 12H6zM9 8a3 3 0 0 1 6 0" />
  </svg>
</chatty-launcher>
```

## 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-launcher label="Open Chatty" live>
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
</chatty-launcher>
<chatty-launcher label="Open Chatty" bag count="2">
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
  <svg
    slot="bag-icon"
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="1.8"
    aria-hidden="true"
  >
    <path d="M5 8h14l-1 12H6zM9 8a3 3 0 0 1 6 0" />
  </svg>
</chatty-launcher>
```

## 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-launcher label="Open Chatty" live>
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
</chatty-launcher>
<chatty-launcher label="Open Chatty" bag count="2">
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
  <svg
    slot="bag-icon"
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="1.8"
    aria-hidden="true"
  >
    <path d="M5 8h14l-1 12H6zM9 8a3 3 0 0 1 6 0" />
  </svg>
</chatty-launcher>
```

| Part | Element | Source |
| --- | --- | --- |
| 1 | CSS part `base` | chatty-ui/custom-elements.json |
| 2 | CSS part `trigger` | chatty-ui/custom-elements.json |
| 3 | CSS part `orb` | chatty-ui/custom-elements.json |
| 4 | CSS part `bag` | chatty-ui/custom-elements.json |
| 5 | CSS part `count` | chatty-ui/custom-elements.json |

## Keyboard

| Key | Action |
| --- | --- |
| Enter / Space | Activate the launcher or bag action. |

### Source

- chatty-ui/custom-elements.json
