# chatty-presence

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

## Key rules

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

Shows its content while `show` is set and keeps it through a 150ms fade when `show` is removed; the exiting content is inert and hidden from assistive technology, then the host is hidden. Class `ChattyPresence`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `show` | `show` | `boolean` | `false` | Content is shown; removing it starts the exit fade. |
| `exiting` | `exiting` | `boolean` | `false` | Set while the exit fade runs; the content is inert. |

### Properties

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

Not declared in the manifest.

### Events

| Name | Detail type | Description |
| --- | --- | --- |
| `chatty-exited` | `Event` | The exit fade finished and the content is hidden. |

### Slots

| Name | Description |
| --- | --- |
| default | Content that enters and exits. |

### Parts

| Name | Description |
| --- | --- |
| `base` | Content wrapper. |

### CSS custom properties

| Name | Default | Description |
| --- | --- | --- |
| `--chatty-presence-duration` | – | Exit fade duration. |

## Usage

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

```html
<chatty-presence show>
  <p
    style="margin: 0; padding: 12px 16px; border: 1px solid var(--chatty-color-border); border-radius: 14px; color: var(--chatty-color-text)"
  >
    Shown while show is set; fades for 150ms when it is removed.
  </p>
</chatty-presence>
```

## 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-presence show>
  <p
    style="margin: 0; padding: 12px 16px; border: 1px solid var(--chatty-color-border); border-radius: 14px; color: var(--chatty-color-text)"
  >
    Shown while show is set; fades for 150ms when it is removed.
  </p>
</chatty-presence>
```

## 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-presence show>
  <p
    style="margin: 0; padding: 12px 16px; border: 1px solid var(--chatty-color-border); border-radius: 14px; color: var(--chatty-color-text)"
  >
    Shown while show is set; fades for 150ms when it is removed.
  </p>
</chatty-presence>
```

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

## Keyboard

No element-specific keys.

### Source

- chatty-ui/custom-elements.json
