Key rules
chatty-product-cardkhai báo 6 attribute, 0 property không có attribute, 1 event, 7 slot, 5 part và 3 CSS custom property.- Import 1 module
@avada/chatty-ui/elements/product-card.jslà definechatty-product-card; 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.
On this page
Overview
A product in the conversation: the image, name, rating and price open the product; the action and footer sit below that open area. Class ChattyProductCard.
Attributes
| Name | Property | Type | Default | Description |
|---|---|---|---|---|
price |
price |
string |
'' |
Formatted price, e.$24. |
compare- |
compareAtPrice |
string |
'' |
Formatted compare- |
label |
label |
string |
'' |
Accessible name of the open area; defaults to its text. |
layout |
layout |
'inset' | 'flush' |
'inset' |
inset (AI Mode): padded card with a rounded image. flush (Classic): the image runs edge to edge under the card's own corners and the text sits in a padded block. |
selected |
selected |
boolean |
false |
Border cue for a chosen product; pair it with a pill in the overlay slot. |
skeleton |
skeleton |
boolean |
false |
Placeholder in the same box as a loaded card; hidden from assistive technology. |
Properties
Attributes also expose the properties listed in the Property column above.
Not declared in the manifest.
Events
| Name | Detail type | Description |
|---|---|---|
chatty- |
CustomEvent<{ |
Click, Enter or Space on the open area. |
Slots
| Name | Description |
|---|---|
| default | Product name; clamped to two lines. |
media |
Product image, usually chatty- with ratio 4 / 5 and fit contain. |
overlay |
Content laid over the image, such as a selected pill. |
rating |
Star rating, usually a read-chatty-. |
badge |
Sale cue beside the price, usually chatty-. |
action |
Action under the open area, usually an add-chatty-. |
footer |
Last row, for an add- |
Parts
| Name | Description |
|---|---|
base |
Card container. |
open |
Area that opens the product (role button). |
media |
Image wrapper. |
name |
Name wrapper. |
price |
Price row. |
CSS custom properties
| Name | Default | Description |
|---|---|---|
- |
– | Card corner radius. |
- |
– | Card background. |
- |
– | Image corner radius. |
Usage
import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/product-card.js';
import '@avada/chatty-ui/elements/image.js';
import '@avada/chatty-ui/elements/rating.js';
import '@avada/chatty-ui/elements/badge.js';
import '@avada/chatty-ui/elements/button.js';
<chatty-product-card
style="align-self: stretch"
price="$24"
compare-at-price="$32"
label="View product Canvas tote bag"
>
<chatty-image
slot="media"
src="/fixtures/tote.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Canvas tote bag
<span slot="rating" style="display: inline-flex; align-items: center; gap: 4px">
<chatty-rating
readonly
value="4.6"
label="Rated 4.6 out of 5"
style="--chatty-rating-size: 16px"
></chatty-rating>
<b>4.6</b> (128)
</span>
<chatty-badge slot="badge" variant="secondary" size="sm">−25%</chatty-badge>
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card
style="align-self: stretch"
price="$18"
selected
label="View product Ceramic mug"
>
<chatty-image
slot="media"
src="/fixtures/mug.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
<chatty-badge slot="overlay" variant="primary">
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.5"
aria-hidden="true"
style="vertical-align: -2px"
>
<path d="m5 12 5 5 9-10" />
</svg>
Selected
</chatty-badge>
Ceramic mug
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card style="align-self: stretch" price="$28" label="View product Wool cap">
<chatty-image
slot="media"
src="/fixtures/cap.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Wool cap
<chatty-button slot="action" size="sm" disabled>Sold out</chatty-button>
</chatty-product-card>
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ộ.
Default: trạng thái mặc định và nội dung mẫu của element.
Show code
<chatty-product-card
style="align-self: stretch"
price="$24"
compare-at-price="$32"
label="View product Canvas tote bag"
>
<chatty-image
slot="media"
src="/fixtures/tote.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Canvas tote bag
<span slot="rating" style="display: inline-flex; align-items: center; gap: 4px">
<chatty-rating
readonly
value="4.6"
label="Rated 4.6 out of 5"
style="--chatty-rating-size: 16px"
></chatty-rating>
<b>4.6</b> (128)
</span>
<chatty-badge slot="badge" variant="secondary" size="sm">−25%</chatty-badge>
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card
style="align-self: stretch"
price="$18"
selected
label="View product Ceramic mug"
>
<chatty-image
slot="media"
src="/fixtures/mug.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
<chatty-badge slot="overlay" variant="primary">
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.5"
aria-hidden="true"
style="vertical-align: -2px"
>
<path d="m5 12 5 5 9-10" />
</svg>
Selected
</chatty-badge>
Ceramic mug
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card style="align-self: stretch" price="$28" label="View product Wool cap">
<chatty-image
slot="media"
src="/fixtures/cap.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Wool cap
<chatty-button slot="action" size="sm" disabled>Sold out</chatty-button>
</chatty-product-card>Các variant hoặc state chính đặt cạnh nhau trong cùng ví dụ.
Show code
<chatty-product-card
style="align-self: stretch"
price="$24"
label="View product Canvas tote bag"
>
<chatty-image
slot="media"
src="/fixtures/tote.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Canvas tote bag
<chatty-button slot="action" size="sm" loading>Adding</chatty-button>
<span slot="footer" role="alert" style="color: var(--chatty-color-critical); font-size: 14px"
>Could not add to cart</span
>
</chatty-product-card>
<chatty-product-card style="align-self: stretch" skeleton></chatty-product-card>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ả.
Anatomy: một instance mặc định riêng, có khoảng trống quanh các phần được đánh số.
Show code
<chatty-product-card
style="align-self: stretch"
price="$24"
compare-at-price="$32"
label="View product Canvas tote bag"
>
<chatty-image
slot="media"
src="/fixtures/tote.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Canvas tote bag
<span slot="rating" style="display: inline-flex; align-items: center; gap: 4px">
<chatty-rating
readonly
value="4.6"
label="Rated 4.6 out of 5"
style="--chatty-rating-size: 16px"
></chatty-rating>
<b>4.6</b> (128)
</span>
<chatty-badge slot="badge" variant="secondary" size="sm">−25%</chatty-badge>
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card
style="align-self: stretch"
price="$18"
selected
label="View product Ceramic mug"
>
<chatty-image
slot="media"
src="/fixtures/mug.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
<chatty-badge slot="overlay" variant="primary">
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.5"
aria-hidden="true"
style="vertical-align: -2px"
>
<path d="m5 12 5 5 9-10" />
</svg>
Selected
</chatty-badge>
Ceramic mug
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card style="align-self: stretch" price="$28" label="View product Wool cap">
<chatty-image
slot="media"
src="/fixtures/cap.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Wool cap
<chatty-button slot="action" size="sm" disabled>Sold out</chatty-button>
</chatty-product-card>| Part | Element | Source |
|---|---|---|
| 1 | CSS part base |
chatty- |
| 2 | CSS part open |
chatty- |
| 3 | CSS part media |
chatty- |
| 4 | CSS part name |
chatty- |
| 5 | CSS part price |
chatty- |
Keyboard
| Key | Action |
|---|---|
| Enter / Space | Open the product; action slots keep their own keyboard behavior. |
Source
- chatty-ui/custom-elements.json