# chatty-ad-referral

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

## Key rules

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

The ad a customer came from, as a preview card above their first bubble in the inbox. The caption clamps to two lines; the chevron expands the caption and the details (media, product). Class `ChattyAdReferral`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `heading` | `heading` | `string` | `''` | Channel label, e.g. `Facebook ad`, `Instagram ad`, `Clicked your ad`. |
| `href` | `href` | `string` | `''` | Public post URL; http(s) only, otherwise the link is hidden. |
| `link-label` | `linkLabel` | `string` | `'View post'` | Text of the view-post link. |
| `toggle-label` | `toggleLabel` | `string` | `'Ad details'` | Accessible name of the chevron. |
| `expanded` | `expanded` | `boolean` | `false` | Shows the full caption and the details; hides the thumbnail. |

### Properties

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

Not declared in the manifest.

### Events

| Name | Detail type | Description |
| --- | --- | --- |
| `toggle` | `Event` | `expanded` changed from the chevron. |
| `click` | `MouseEvent` | Native activation of the toggle. |

### Slots

| Name | Description |
| --- | --- |
| default | Caption: ad title and body. |
| `thumb` | 48px thumbnail, hidden while expanded. |
| `details` | Media and product shown while expanded. |

### Parts

| Name | Description |
| --- | --- |
| `base` | Card container. |
| `label` | Channel label, e.g. `Facebook ad`. |
| `link` | View-post link. |
| `caption` | Clamped caption. |
| `toggle` | Expand button. |
| `details` | Expanded details wrapper. |

### CSS custom properties

| Name | Default | Description |
| --- | --- | --- |
| `--chatty-ad-referral-radius` | – | Corner radius. |
| `--chatty-ad-referral-background` | – | Background. |

## Usage

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

```html
<chatty-ad-referral heading="Facebook ad"
  >Summer collection<br />Explore our collection</chatty-ad-referral
>
<chatty-ad-referral heading="WhatsApp ad" href="https://example.com/post">
  <img slot="thumb" src="/fixtures/tote.svg" alt="" />
  Canvas tote bag<br />Carry everything, every day.
  <img
    slot="details"
    src="/fixtures/tote.svg"
    alt="Canvas tote bag"
    style="max-width: 100%; max-height: 240px; border-radius: 8px"
  />
</chatty-ad-referral>
```

## 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-ad-referral heading="Facebook ad"
  >Summer collection<br />Explore our collection</chatty-ad-referral
>
<chatty-ad-referral heading="WhatsApp ad" href="https://example.com/post">
  <img slot="thumb" src="/fixtures/tote.svg" alt="" />
  Canvas tote bag<br />Carry everything, every day.
  <img
    slot="details"
    src="/fixtures/tote.svg"
    alt="Canvas tote bag"
    style="max-width: 100%; max-height: 240px; border-radius: 8px"
  />
</chatty-ad-referral>
```

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

```html
<chatty-ad-referral heading="Instagram ad" expanded>
  Canvas tote bag<br />Carry everything, every day.
  <img
    slot="details"
    src="/fixtures/tote.svg"
    alt="Canvas tote bag"
    style="width: 160px; border-radius: 8px"
  />
</chatty-ad-referral>
```

## 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-ad-referral heading="Facebook ad"
  >Summer collection<br />Explore our collection</chatty-ad-referral
>
<chatty-ad-referral heading="WhatsApp ad" href="https://example.com/post">
  <img slot="thumb" src="/fixtures/tote.svg" alt="" />
  Canvas tote bag<br />Carry everything, every day.
  <img
    slot="details"
    src="/fixtures/tote.svg"
    alt="Canvas tote bag"
    style="max-width: 100%; max-height: 240px; border-radius: 8px"
  />
</chatty-ad-referral>
```

| Part | Element | Source |
| --- | --- | --- |
| 1 | CSS part `base` | chatty-ui/custom-elements.json |
| 2 | CSS part `label` | chatty-ui/custom-elements.json |
| 3 | CSS part `link` | chatty-ui/custom-elements.json |
| 4 | CSS part `caption` | chatty-ui/custom-elements.json |
| 5 | CSS part `toggle` | chatty-ui/custom-elements.json |
| 6 | CSS part `details` | chatty-ui/custom-elements.json |

## Keyboard

| Key | Action |
| --- | --- |
| Enter / Space | Toggle details; Enter follows the link. |

### Source

- chatty-ui/custom-elements.json
