# chatty-tooltip

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

## Key rules

- `chatty-tooltip` khai báo 3 attribute, 0 property không có attribute, 0 event, 2 slot, 1 part và 1 CSS custom property.
- Import 1 module `@avada/chatty-ui/elements/tooltip.js` là define `chatty-tooltip`; 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 one-line reminder for the control in the default slot, drawn in the top layer so glass or overflow clipping never cuts it. Shows after `delay` on mouse hover or at once on keyboard focus; hides on leave, blur, press, scroll and Escape. The trigger keeps its own accessible name: the tooltip only echoes it, so it is hidden from assistive technology. Class `ChattyTooltip`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `open` | `open` | `boolean` | `false` | Shows the bubble; hover, focus, Escape and a press set it. |
| `placement` | `placement` | `'top' \| 'bottom'` | `'bottom'` | Preferred side of the trigger; the bubble flips when that side has no room. |
| `delay` | `delay` | `number` | `350` | Milliseconds of mouse hover before it shows; keyboard focus shows it at once. |

### Properties

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

Not declared in the manifest.

### Events

Not declared in the manifest.

### Slots

| Name | Description |
| --- | --- |
| default | The trigger control. |
| `content` | Tooltip text. |

### Parts

| Name | Description |
| --- | --- |
| `base` | The top-layer tooltip bubble. |

### CSS custom properties

| Name | Default | Description |
| --- | --- | --- |
| `--chatty-tooltip-max-width` | – | Widest bubble before the text wraps. |

## Usage

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

export function Standard() {
  return html`
    <chatty-tooltip open style="margin: 40px 48px 48px 24px">
      <button
        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>
      <span slot="content">Emoji</span>
    </chatty-tooltip>
    <chatty-tooltip open placement="top" style="margin: 48px 24px 40px 48px">
      <button
        type="button"
        aria-label="Add to cart, out of stock"
        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"
      >
        +
      </button>
      <span slot="content">Out of stock</span>
    </chatty-tooltip>
  `;
}
```

## 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-tooltip prototype chatty-ui ports from (chatty-ui/src/elements/tooltip.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/tooltip.js';

export function Standard() {
  return html`
    <chatty-tooltip open style="margin: 40px 48px 48px 24px">
      <button
        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>
      <span slot="content">Emoji</span>
    </chatty-tooltip>
    <chatty-tooltip open placement="top" style="margin: 48px 24px 40px 48px">
      <button
        type="button"
        aria-label="Add to cart, out of stock"
        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"
      >
        +
      </button>
      <span slot="content">Out of stock</span>
    </chatty-tooltip>
  `;
}
```

## 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-tooltip prototype chatty-ui ports from (chatty-ui/src/elements/tooltip.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/tooltip.js';

export function Standard() {
  return html`
    <chatty-tooltip open style="margin: 40px 48px 48px 24px">
      <button
        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>
      <span slot="content">Emoji</span>
    </chatty-tooltip>
    <chatty-tooltip open placement="top" style="margin: 48px 24px 40px 48px">
      <button
        type="button"
        aria-label="Add to cart, out of stock"
        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"
      >
        +
      </button>
      <span slot="content">Out of stock</span>
    </chatty-tooltip>
  `;
}
```

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

## Keyboard

| Key | Action |
| --- | --- |
| Tab | Focus the trigger and show its tooltip. |
| Escape | Hide the tooltip. |

### Source

- chatty-ui/custom-elements.json
