# chatty-pre-chat

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

## Key rules

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

Contact invitation or saved-email receipt under the original reply. Class `ChattyPreChat`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `email` | `email` | `string` | `''` | Saved email; a receipt replaces the invitation when present. |
| `label` | `label` | `string` | `'Get replies by email'` | Translated invitation. |
| `skip-label` | `skipLabel` | `string` | `'Chat anonymously'` | Translated anonymous option. |
| `confirmation` | `confirmation` | `string` | `'Replies will also go to {{email}}'` | Translated receipt template; {{email}} marks the saved email. |
| `skippable` | `skippable` | `boolean` | `false` | Shows the anonymous option. |

### 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<{}>` | Opens contact collection. |
| `chatty-skip` | `CustomEvent<{}>` | Requests anonymous chat. |
| `click` | `MouseEvent` | Native invitation button click. |

### Slots

Not declared in the manifest.

### Parts

| Name | Description |
| --- | --- |
| `base` | Contact invitation. |

### CSS custom properties

Not declared in the manifest.

## Usage

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

```html
<chatty-pre-chat skippable></chatty-pre-chat> 
```

## 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-pre-chat skippable></chatty-pre-chat> 
```

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

```html
<chatty-pre-chat email="customer@example.com"></chatty-pre-chat>
```

## 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-pre-chat skippable></chatty-pre-chat> 
```

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

## Keyboard

| Key | Action |
| --- | --- |
| Enter / Space | Activate the invitation or anonymous-chat button. |

### Source

- chatty-ui/custom-elements.json
