# chatty-block-suggestions

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

## Key rules

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

Host-owned suggestion text; connect chatty-suggest to composer.send(text). Class `ChattyBlockSuggestions`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `block` | `block` | `object` | `{}` | Suggestion block with data.suggestions text strings; data.layout row stacks conversation starters. |

### Properties

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

Not declared in the manifest.

### Events

| Name | Detail type | Description |
| --- | --- | --- |
| `chatty-suggest` | `CustomEvent<{text: string}>` | Suggestion selected by pointer or keyboard. |

### Slots

Not declared in the manifest.

### Parts

| Name | Description |
| --- | --- |
| `base` | Wrapping suggestion actions. |

### CSS custom properties

Not declared in the manifest.

## Usage

```js
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/chatty-block-suggestions.js';
import '@avada/chatty-ui/elements/composer.js';
export function Standard() {
  return html`<div
    @chatty-suggest=${event => {
      const composer = event.currentTarget.querySelector('chatty-composer');
      composer.send(event.detail.text);
    }}
    @chatty-send=${event => {
      event.currentTarget.querySelector('[role=status]').textContent = `Sent: ${event.detail.text}`;
    }}
  >
    <chatty-block-suggestions
      block='{"type":"suggestions","data":{"suggestions":["Find a bag","Track my order"]}}'
    ></chatty-block-suggestions
    ><chatty-composer></chatty-composer>
    <p role="status"></p>
  </div>`;
}
```

## 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.

```js
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/chatty-block-suggestions.js';
import '@avada/chatty-ui/elements/composer.js';
export function Standard() {
  return html`<div
    @chatty-suggest=${event => {
      const composer = event.currentTarget.querySelector('chatty-composer');
      composer.send(event.detail.text);
    }}
    @chatty-send=${event => {
      event.currentTarget.querySelector('[role=status]').textContent = `Sent: ${event.detail.text}`;
    }}
  >
    <chatty-block-suggestions
      block='{"type":"suggestions","data":{"suggestions":["Find a bag","Track my order"]}}'
    ></chatty-block-suggestions
    ><chatty-composer></chatty-composer>
    <p role="status"></p>
  </div>`;
}
```

## 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ố.

```js
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/chatty-block-suggestions.js';
import '@avada/chatty-ui/elements/composer.js';
export function Standard() {
  return html`<div
    @chatty-suggest=${event => {
      const composer = event.currentTarget.querySelector('chatty-composer');
      composer.send(event.detail.text);
    }}
    @chatty-send=${event => {
      event.currentTarget.querySelector('[role=status]').textContent = `Sent: ${event.detail.text}`;
    }}
  >
    <chatty-block-suggestions
      block='{"type":"suggestions","data":{"suggestions":["Find a bag","Track my order"]}}'
    ></chatty-block-suggestions
    ><chatty-composer></chatty-composer>
    <p role="status"></p>
  </div>`;
}
```

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

## Keyboard

No element-specific keys.

### Source

- chatty-ui/custom-elements.json
