# chatty-popover

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

## Key rules

- `chatty-popover` khai báo 3 attribute, 1 property không có attribute, 1 event, 2 slot, 1 part và 2 CSS custom property.
- Import 1 module `@avada/chatty-ui/elements/popover.js` là define `chatty-popover`; 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 floating panel anchored to the trigger in the `trigger` slot, drawn in the top layer so a clipping ancestor (the glass composer dock) never cuts it. The trigger toggles it; Escape closes it and returns focus to the trigger; a pointer press outside closes it. Class `ChattyPopover`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `open` | `open` | `boolean` | `false` | Shows the panel; the trigger's aria-expanded follows it. |
| `placement` | `placement` | `'top' \| 'bottom'` | `'bottom'` | Preferred side of the trigger; the panel flips when that side has no room. |
| `label` | `label` | `string` | `''` | Accessible name of the panel. |

### Properties

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

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `panelRole` | `'dialog' \| 'menu'` | `'dialog'` | ARIA role of the panel; aria-haspopup on the trigger follows it. |

### Events

| Name | Detail type | Description |
| --- | --- | --- |
| `toggle` | `ToggleEvent` | The panel opened or closed; newState is open or closed. |

### Slots

| Name | Description |
| --- | --- |
| default | Panel content. |
| `trigger` | The control that opens the panel; it receives aria-haspopup and aria-expanded. |

### Parts

| Name | Description |
| --- | --- |
| `base` | The top-layer panel. |

### CSS custom properties

| Name | Default | Description |
| --- | --- | --- |
| `--chatty-popover-min-width` | – | Minimum panel width. |
| `--chatty-popover-padding` | – | Panel padding. |

## Usage

```js
import '@avada/chatty-ui/tokens/tokens.css';
import {IconSmile} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-popover prototype chatty-ui ports from (chatty-ui/src/elements/popover.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/popover.js';

export function Standard() {
  return html`
    <chatty-popover open label="Emoji" style="margin-block-end: 180px">
      <button
        slot="trigger"
        type="button"
        aria-label="Emoji"
        style="display:inline-grid;place-items:center;width:32px;height:32px;padding:0;border:1px solid var(--chatty-color-border);border-radius:999px;background:var(--chatty-color-bg-surface);color:var(--chatty-color-text);cursor:pointer"
      >
        ${IconSmile({size: 16})}
      </button>
      <div style="display: grid; grid-template-columns: repeat(4, 36px); gap: 4px; font-size: 20px">
        <button
          type="button"
          aria-label="Thumbs up"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          👍
        </button>
        <button
          type="button"
          aria-label="Heart"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          ❤️
        </button>
        <button
          type="button"
          aria-label="Smile"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          😊
        </button>
        <button
          type="button"
          aria-label="Party"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          🎉
        </button>
      </div>
    </chatty-popover>
  `;
}
```

## 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 {IconSmile} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-popover prototype chatty-ui ports from (chatty-ui/src/elements/popover.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/popover.js';

export function Standard() {
  return html`
    <chatty-popover open label="Emoji" style="margin-block-end: 180px">
      <button
        slot="trigger"
        type="button"
        aria-label="Emoji"
        style="display:inline-grid;place-items:center;width:32px;height:32px;padding:0;border:1px solid var(--chatty-color-border);border-radius:999px;background:var(--chatty-color-bg-surface);color:var(--chatty-color-text);cursor:pointer"
      >
        ${IconSmile({size: 16})}
      </button>
      <div style="display: grid; grid-template-columns: repeat(4, 36px); gap: 4px; font-size: 20px">
        <button
          type="button"
          aria-label="Thumbs up"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          👍
        </button>
        <button
          type="button"
          aria-label="Heart"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          ❤️
        </button>
        <button
          type="button"
          aria-label="Smile"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          😊
        </button>
        <button
          type="button"
          aria-label="Party"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          🎉
        </button>
      </div>
    </chatty-popover>
  `;
}
```

## 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 {IconSmile} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-popover prototype chatty-ui ports from (chatty-ui/src/elements/popover.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/popover.js';

export function Standard() {
  return html`
    <chatty-popover open label="Emoji" style="margin-block-end: 180px">
      <button
        slot="trigger"
        type="button"
        aria-label="Emoji"
        style="display:inline-grid;place-items:center;width:32px;height:32px;padding:0;border:1px solid var(--chatty-color-border);border-radius:999px;background:var(--chatty-color-bg-surface);color:var(--chatty-color-text);cursor:pointer"
      >
        ${IconSmile({size: 16})}
      </button>
      <div style="display: grid; grid-template-columns: repeat(4, 36px); gap: 4px; font-size: 20px">
        <button
          type="button"
          aria-label="Thumbs up"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          👍
        </button>
        <button
          type="button"
          aria-label="Heart"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          ❤️
        </button>
        <button
          type="button"
          aria-label="Smile"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          😊
        </button>
        <button
          type="button"
          aria-label="Party"
          style="height: 36px; border: 0; border-radius: 10px; background: none; cursor: pointer"
        >
          🎉
        </button>
      </div>
    </chatty-popover>
  `;
}
```

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

## Keyboard

| Key | Action |
| --- | --- |
| Enter / Space | Activate the trigger. |
| Escape | Dismiss and return focus to the trigger. |

### Source

- chatty-ui/custom-elements.json
