# chatty-cart-confirmation

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

## Key rules

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

Receipt for one cart line or a group added together, with quantity pulses and an optional view-cart action. Class `ChattyCartConfirmation`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `heading` | `heading` | `string` | `'Added to cart'` | Heading and accessible name of the receipt. |
| `grouped` | `grouped` | `boolean` | `false` | One receipt for the cart-confirmation children in the items slot. |
| `show-all` | `showAll` | `boolean` | `false` | Show every grouped line (admin history); storefront shows three when there are more than four. |
| `quantity` | `quantity` | `number \| undefined` | `undefined` | quantity now in the cart |
| `quantity-label` | `quantityLabel` | `string` | `'Quantity in cart'` | Label before the quantity, e.g. `Quantity in cart`. |
| `price` | `price` | `string` | `''` | Formatted line price, e.g. `$48.00`. |

### 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 | Product title for a single-line receipt. |
| `items` | Cart confirmation lines added together; use grouped with this slot. |
| `more` | Localized overflow summary when more than four lines are collapsed. |
| `media` | Thumbnail, 64 × 80 for a single receipt or 40 × 50 in a group; omit for text-only. |
| `detail` | Variant line, e.g. `Size M / Blue`. |
| `action` | View-cart action, usually a plain `chatty-button`. |

### Parts

| Name | Description |
| --- | --- |
| `base` | Receipt section. |
| `label` | Heading line. |
| `media` | Thumbnail wrapper. |
| `line` | Quantity and price row. |

### CSS custom properties

| Name | Default | Description |
| --- | --- | --- |
| `--chatty-cart-confirmation-radius` | – | Corner radius. |
| `--chatty-cart-confirmation-background` | – | Background. |

## Usage

```js
import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/cart-confirmation.js';
import '@avada/chatty-ui/elements/button.js';
```

```html
<chatty-cart-confirmation quantity="2" price="$48.00">
  <img slot="media" src="/fixtures/tote.svg" alt="" />
  Canvas tote bag
  <span slot="detail">Natural / Large</span>
  <chatty-button slot="action" variant="plain">View cart</chatty-button>
</chatty-cart-confirmation>
<chatty-cart-confirmation quantity="1" price="$18.00">Ceramic mug</chatty-cart-confirmation>
```

## 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-cart-confirmation quantity="2" price="$48.00">
  <img slot="media" src="/fixtures/tote.svg" alt="" />
  Canvas tote bag
  <span slot="detail">Natural / Large</span>
  <chatty-button slot="action" variant="plain">View cart</chatty-button>
</chatty-cart-confirmation>
<chatty-cart-confirmation quantity="1" price="$18.00">Ceramic mug</chatty-cart-confirmation>
```

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

```html
<chatty-cart-confirmation grouped heading="Added 5 products to cart">
  <chatty-cart-confirmation slot="items" quantity="2" price="$48.00"
    ><img slot="media" src="/fixtures/tote.svg" alt="" />Canvas tote bag<span slot="detail"
      >Natural / Large</span
    ></chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$18.00"
    >Ceramic mug</chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$28.00"
    ><img slot="media" src="/fixtures/cap.svg" alt="" />Wool cap</chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$24.00"
    >Linen scarf</chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$18.00"
    >Leather wallet</chatty-cart-confirmation
  >
  <span slot="more">and 2 more products — view in cart</span>
  <chatty-button slot="action" variant="plain">View cart</chatty-button>
</chatty-cart-confirmation>
```

## 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-cart-confirmation quantity="2" price="$48.00">
  <img slot="media" src="/fixtures/tote.svg" alt="" />
  Canvas tote bag
  <span slot="detail">Natural / Large</span>
  <chatty-button slot="action" variant="plain">View cart</chatty-button>
</chatty-cart-confirmation>
<chatty-cart-confirmation quantity="1" price="$18.00">Ceramic mug</chatty-cart-confirmation>
```

| Part | Element | Source |
| --- | --- | --- |
| 1 | CSS part `base` | chatty-ui/custom-elements.json |
| 2 | CSS part `label` | chatty-ui/custom-elements.json |
| 3 | CSS part `media` | chatty-ui/custom-elements.json |
| 4 | CSS part `line` | chatty-ui/custom-elements.json |

## Keyboard

No element-specific keys.

### Source

- chatty-ui/custom-elements.json
