Key rules
- AI Mode:
ProductCardtừ@scripttag/v2/ui/ProductCard.jsx; card rộng 184px, ảnh 4 / 5contain, tên tối đa 2 dòng. - Classic: dùng
ProductCarddefault export của ChatbotProductsMessage; card rộng 205px, ảnh 4 / 5contain. - AI Mode: hover chuột dùng
--chatty-shadow-card-hover; cảm ứng giữ shadow nghỉ, nhấn xuống scale(0.98). - Classic: tên và giá dùng
body-medium, giá weight 600; ảnh và nút "View similar" là haibuttonriêng. - Hai surface không chung component React; chuẩn port là
chatty-product-card(Standard).
On this page
Use when / Avoid
Dùng cho đối tượng có ảnh, tên và giá trong hội thoại. Admin chưa có product card riêng trong code. Khi dữ liệu sản phẩm lỗi, dùng text thay vì card rỗng.
Use instead
| Component | Use when |
|---|---|
ProductCard |
AI Mode: caller truyền product, onOpen và action. |
ProductCard |
Classic: default export nhận product, removedBubblingEvents, isFromFindSimilar, wizard. |
AddToCartButton |
AI Mode: nút thêm vào giỏ trình bày sẵn, caller sở hữu lời gọi giỏ hàng. |
Live preview
Standard
Thread AI Mode có năm sản phẩm, rating, giá so sánh và trạng thái sold out; arrows desktop, dots touch.
Show code
<style>
.product-thread {
box-sizing: border-box;
width: min(100%, var(--chatty-layout-panel-chat));
margin-inline: auto;
padding: var(--chatty-layout-inset-desktop);
background: var(--chatty-color-bg-surface);
}
.product-thread.classic {
width: min(100%, var(--chatty-layout-panel-classic));
padding: 8px 12px 4px;
overflow-x: hidden;
overflow-y: auto;
scrollbar-gutter: stable;
}
@media (max-width: 899px) {
.product-thread {
width: 100%;
padding: 24px var(--chatty-layout-inset-mobile);
}
}
</style>
<section class="product-thread" aria-label="Recommended products">
<chatty-product-row surface="ai-mode">
<chatty-product-card
layout="inset"
price="$24"
compare-at-price="$32"
label="View 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 layout="inset" price="$18" label="View Ceramic mug">
<chatty-image
slot="media"
src="/fixtures/mug.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Ceramic mug
<span slot="rating" style="display:inline-flex;align-items:center;gap:4px">
<chatty-rating
readonly
value="4.8"
label="Rated 4.8 out of 5"
style="--chatty-rating-size:16px"
></chatty-rating>
<b>4.8</b> (54)
</span>
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card layout="inset" price="$28" label="View 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>
<chatty-product-card layout="inset" price="$24" label="View Natural canvas tote bag large">
<chatty-image
slot="media"
src="/fixtures/tote.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Natural canvas tote bag large
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card layout="inset" price="$24" label="View Everyday ceramic mug">
<chatty-image
slot="media"
src="/fixtures/mug.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Everyday ceramic mug
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
</chatty-product-row>
</section>Panel Classic có năm sản phẩm; arrows desktop, dots touch. Classic dark: Standard dùng nền tối; widget đang ship khối trắng.
Show code
<style>
.product-thread {
box-sizing: border-box;
width: min(100%, var(--chatty-layout-panel-chat));
margin-inline: auto;
padding: var(--chatty-layout-inset-desktop);
background: var(--chatty-color-bg-surface);
}
.product-thread.classic {
width: min(100%, var(--chatty-layout-panel-classic));
padding: 8px 12px 4px;
overflow-x: hidden;
overflow-y: auto;
scrollbar-gutter: stable;
}
@media (max-width: 899px) {
.product-thread {
width: 100%;
padding: 24px var(--chatty-layout-inset-mobile);
}
}
</style>
<section class="product-thread classic" aria-label="Recommended products">
<chatty-product-row surface="classic">
<chatty-product-card
layout="flush"
price="$24"
compare-at-price="$32"
label="View 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 layout="flush" price="$18" label="View Ceramic mug">
<chatty-image
slot="media"
src="/fixtures/mug.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Ceramic mug
<span slot="rating" style="display:inline-flex;align-items:center;gap:4px">
<chatty-rating
readonly
value="4.8"
label="Rated 4.8 out of 5"
style="--chatty-rating-size:16px"
></chatty-rating>
<b>4.8</b> (54)
</span>
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card layout="flush" price="$28" label="View 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>
<chatty-product-card layout="flush" price="$24" label="View Natural canvas tote bag large">
<chatty-image
slot="media"
src="/fixtures/tote.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Natural canvas tote bag large
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card layout="flush" price="$24" label="View Everyday ceramic mug">
<chatty-image
slot="media"
src="/fixtures/mug.svg"
alt=""
ratio="4 / 5"
fit="contain"
></chatty-image>
Everyday ceramic mug
<chatty-button slot="action" size="sm">Add to cart</chatty-button>
</chatty-product-card>
</chatty-product-row>
</section>Prototype Product card và style đi kèm là chuẩn: package được port 1:1 từ prototype, và manifest phần tử được sinh từ cùng nguồn. Ảnh, tên, đánh giá, badge giảm giá và nút đi vào qua slot (chatty-image, chatty-rating, chatty-badge, chatty-button); giá truyền dạng chuỗi đã format. Classic dùng layout="flush". Chưa surface nào dùng element thật; các mục AI Mode và Classic bên dưới mô tả React đang chạy.
Element
| Element | Module |
|---|---|
chatty- |
@avada/ |
API
chatty-product-row (cùng module product-card.js) bọc các card trong default slot; ẩn scrollbar; fine pointer desktop dùng prev/next (AI Mode hiện khi hover hoặc focus trong hàng; Classic luôn hiện khi cuộn tiếp được), touch hoặc mobile dùng dots khi tràn. surface="classic" trượt một card + gap 8px, AI Mode trượt 80% viewport; arrow biến mất ở đầu/cuối, RTL đảo hướng, reduced-motion cuộn ngay. strings đặt nhãn previous/next. Arrow nhận focus; ArrowLeft/ArrowRight và Home/End vẫn cuộn hàng. Hàng giữ title hai dòng để giá thẳng hàng; card ngoài hàng chỉ chiếm số dòng title thực tế.
| Kind | Name | Type | Default | Description |
|---|---|---|---|---|
| attribute | price |
string | '' |
Giá đã format, ví dụ $24; rỗng thì ẩn hàng giá. |
| attribute | compare- |
string | '' |
Giá so sánh đã format, gạch ngang trước giá. |
| attribute | label |
string | '' |
Tên truy cập của vùng mở chi tiết; rỗng thì lấy chữ bên trong. |
| attribute | layout |
inset, flush | 'inset' |
inset (AI Mode): card có padding, ảnh bo góc; flush (Classic): ảnh tràn mép dưới góc card, chữ nằm trong khối có padding. |
| attribute | selected |
boolean | false |
Viền màu accent khi sản phẩm đã chọn; đi kèm pill ở slot overlay. |
| attribute | skeleton |
boolean | false |
Render khung chờ cùng hộp với card đã tải, aria- |
| event | chatty- |
CustomEvent<{}> | – | Bấm, Enter hoặc Space trên vùng mở chi tiết; phím trên action không kích hoạt. |
| slot | default | – | – | Tên sản phẩm, bị kẹp dòng. |
| slot | media |
– | – | Ảnh sản phẩm, thường là chatty- với fit contain. |
| slot | overlay |
– | – | Nội dung nằm trên ảnh, ví dụ pill đã chọn. |
| slot | rating |
– | – | Đánh giá sao, thường là chatty- readonly. |
| slot | badge |
– | – | Dấu hiệu giảm giá cạnh giá, thường là chatty-. |
| slot | action |
– | – | Action dưới vùng mở chi tiết, thường là nút thêm vào giỏ. |
| slot | footer |
– | – | Hàng cuối cho thông báo lỗi thêm giỏ. |
| part | base |
– | – | Khung card. |
| part | open |
– | – | Vùng mở chi tiết (role button). |
| part | media |
– | – | Vùng chứa ảnh. |
| part | name |
– | – | Vùng chứa tên. |
| part | price |
– | – | Hàng giá. |
| css- |
- |
– | – | Bo góc card. |
| css- |
- |
– | – | Nền card. |
| css- |
- |
– | – | Bo góc ảnh. |
AI Mode
Hàng card layout inset: giá so sánh kèm badge giảm giá secondary "−25%" và sao lẻ, card đã chọn có pill Selected, card hết hàng; nút thẳng hàng ở đáy.
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>Đang thêm giỏ kèm lỗi ở footer, và skeleton cùng hộp card.
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>Card đã tải có giá và giá so sánh, card đã chọn, hết hàng và skeleton.
Show code
import React, {useState} from 'react';
import {ChatProductCarousel} from '@scripttag/v2/views/chat/ChatProductCarousel.jsx';
import {ChatNavigationContext} from '@scripttag/v2/views/chat/chatNavigationContext.js';
import {selectionStore} from '@scripttag/v2/stores/selectionStore.js';
import {ProductCard} from '@scripttag/v2/ui/ProductCard.jsx';
import ChatbotProductsMessage from '@scripttag/v1/Parts/InsertProduct/ChatbotProductsMessage/ChatbotProductsMessage.js';
import {
WidgetChatStateProvider,
createWidgetChatStateStore
} from '@scripttag/v1/WidgetChatState.js';
import {t} from '@scripttag/v2/helpers/i18n.js';
// PercentOffBadge's screen-reader phrase uses this class on both surfaces; the widget roots load it,
// the story does not mount them.
import '@scripttag/v1/Parts/InsertProduct/offerA11y.scss';
const variant = id => [`Default Title: ${id}`];
const products = [
{
productId: 'gid://shopify/Product/101',
title: 'Canvas tote bag',
url: 'https://shop.example/products/canvas-tote',
image: '/fixtures/tote.svg',
imageAlt: 'Canvas tote bag',
availableForSale: true,
currency: 'USD',
prices: ['$24.00'],
compareAtPrices: ['$32.00'],
variantOptions: variant('1001')
},
{
productId: 'gid://shopify/Product/102',
title: 'Ceramic mug',
url: 'https://shop.example/products/ceramic-mug',
image: '/fixtures/mug.svg',
imageAlt: 'Ceramic mug',
availableForSale: true,
currency: 'USD',
prices: ['$18.00'],
compareAtPrices: [],
variantOptions: variant('1002')
},
{
productId: 'gid://shopify/Product/103',
title: 'Wool cap',
url: 'https://shop.example/products/wool-cap',
image: '/fixtures/cap.svg',
imageAlt: 'Wool cap',
availableForSale: false,
currency: 'USD',
prices: ['$28.00'],
compareAtPrices: [],
variantOptions: variant('1003')
}
];
function AiCatalogue() {
selectionStore.setState({
selected: [{handle: 'ceramic-mug', title: 'Ceramic mug', image: '/fixtures/mug.svg'}]
});
return (
<div className="specimen-grid" style={{minWidth: 0}}>
<section style={{minWidth: 0}}>
<h4>Carousel: loaded, selected, sold out</h4>
<ChatNavigationContext.Provider value>
<ChatProductCarousel messageId="guide-carousel" products={products} />
</ChatNavigationContext.Provider>
</section>
<section style={{minWidth: 0}}>
<h4>Skeleton</h4>
<div style={{width: 184}}>
<ProductCard skeleton />
</div>
</section>
</div>
);
}
// Classic reads its translator from the widget chat state, whose default echoes the phrase without
// interpolating {{value}}; the live widget installs the real one.
const classicState = createWidgetChatStateStore({
i18n: Object.assign((...args) => t(...args), {locale: 'en'})
});
function ClassicCatalogue() {
return (
<div className="specimen-grid" style={{minWidth: 0}}>
<section style={{minWidth: 0}}>
<h4>Compare-at price, in stock, sold out</h4>
<div style={{width: 360, maxWidth: '100%'}}>
<WidgetChatStateProvider store={classicState}>
<ChatbotProductsMessage products={products} messageId="guide-classic" />
</WidgetChatStateProvider>
</div>
</section>
</div>
);
}
export function Catalogue() {
const [surface, setSurface] = useState(null);
const ref = node => {
const found = node?.closest('[data-surface]')?.dataset.surface;
if (found && found !== surface) setSurface(found);
};
return (
<div ref={ref} style={{minWidth: 0, width: '100%'}}>
{surface === 'classic' ? <ClassicCatalogue /> : surface ? <AiCatalogue /> : null}
</div>
);
}Import / element
| Component / element | Import / file | Scope root |
|---|---|---|
ProductCard |
@scripttag/ |
.chatty- |
AddToCartButton |
@scripttag/ |
.chatty- |
Anatomy
| Part | Element |
|---|---|
| 1 | Vùng mở chi tiết chatty- với role="button" và tabIndex={. |
| 2 | Media chatty- chứa ảnh và slot overlay. |
| 3 | Tên chatty- kẹp 2 dòng bằng chatty-. |
| 4 | Đánh giá sao chatty-, chỉ khi có dữ liệu. |
| 5 | Hàng giá chatty- với giá so sánh chatty- rồi giá. |
| 6 | Slot action dưới vùng mở chi tiết, chỉ hiện khi canShowAction. |
| 7 | Slot footer cuối card cho thông báo lỗi. |
Placement / order
| Context | Order |
|---|---|
| Carousel chat | Mỗi card rộng 184px, flex: 0 0 184px, theo hàng trong track; width do carousel đặt, không do card. |
| Trong card | Ảnh, tên, đánh giá, giá, rồi action, rồi footer; overlay nằm trên ảnh. |
Props
| Prop | Type | Values | Default | Notes |
|---|---|---|---|---|
product |
object | id, handle, name, img, imageAlt, price, compareAtPrice, pricing, availableForSale | Caller | Trường đã sẵn sàng hiển thị; id dùng tra đánh giá. |
onOpen |
Function | Handler nhận trigger của card | Caller | Gọi khi bấm hoặc nhấn Enter / Space trên vùng chi tiết. |
action |
any | Node, thường là AddToCartButton | Caller | Render dưới khối thông tin. |
footer |
any | Node | Caller | Render cuối cùng, dưới action. |
overlay |
any | Node | Caller | Render trên ảnh. |
selected |
boolean | true / false | false | Thêm class is-. |
index |
number | Vị trí trong danh sách | 0 | Đặt - cho stagger khi vào. |
cardRef |
object | ref | Caller | Chuyển tới root để fly- |
className |
string | CSS classes | Caller | Gộp vào root. |
skeleton |
boolean | true / false | false | Render placeholder cùng hộp với card đã tải. |
Sizes
| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
|---|---|---|---|---|---|---|---|
| Card | Theo nội dung | 10px | 8px | 20px (-) |
Không có chữ | Cả vùng chi tiết | width 184px do carousel đặt |
| Media | Theo aspect- |
Không khai báo | Không khai báo | 14px | Không có chữ | Thuộc vùng chi tiết | Không override theo viewport |
| Tên | Tối thiểu 2 dòng của line- |
Không khai báo | Không khai báo | Không khai báo | body-: 15pxDerived(15px = type(body- |
Thuộc vùng chi tiết | JS .is- |
| Giá | Theo line- |
Không khai báo | 6px | Không khai báo | body-: 15pxDerived(15px = type(body- |
Thuộc vùng chi tiết | Cùng breakpoint với Tên |
| Giá so sánh | Theo line- |
Không khai báo | Không khai báo | Không khai báo | body-: 14pxDerived(14px = type(body- |
Thuộc vùng chi tiết | Cùng breakpoint với Tên |
| Action | Theo nút chatty- |
padding- |
Không khai báo | Theo nút | button-: 14pxDerived(14px = type(button- |
Native box, chatty- |
Mobile đổi sang chip-: 14pxDerived(14px = type(chip- |
| Pill chọn | height/ |
var(- |
Theo token | 16px | chip-: 14pxDerived(14px = type(chip- |
Mobile mở rộng tới 44px bằng ::before inset -8px |
Desktop hiện khi hover; mobile hiện sẵn |
| Skeleton | Action 32px | Không khai báo | Không khai báo | Action 10px; bone 6px | Không có chữ | Không tương tác | Giá rộng 45% và cao 1.8em |
Tokens
| Part | Token | Light | Dark |
|---|---|---|---|
| Nền card | - |
#fbfaf7, kèm - |
Theo chatty- |
| Nền khi hover | - |
Không đổi nền; dùng shadow | rgba(255,255,255,0.14) |
| Shadow hover | - |
0 0 0 1px rgb(0 0 0 / 0.06), 0 2px 4px rgb(0 0 0 / 0.06), 0 4px 12px -4px rgb(0 0 0 / 0.18) | 0 0 0 1px rgb(255 255 255 / 0.12), 0 2px 4px rgb(0 0 0 / 0.3), 0 4px 12px -4px rgb(0 0 0 / 0.54) |
| Tên | - |
rgba(20,19,24,0.94) | rgba(255,255,255,0.96) |
| Giá so sánh | - |
rgba(20,19,24,0.62) | rgba(255,255,255,0.62) |
| Viền khi đã chọn | - |
Merchant - |
Same definition |
| Vòng focus | - |
-: rgba(20,19,24,0.94) |
-: rgba(255,255,255,0.96) |
| Lỗi | - |
#ef4444 | #ef4444 |
| Chuyển động hover | - |
250ms cho transform; 150ms cho shadow và nền | Same |
States
| State | Trigger | Visual change (values) | ARIA/attribute |
|---|---|---|---|
| Rest | Mặc định | box-. |
Không thêm ARIA |
| Hover | pointer có hover và pointer fine | translateY(-2px); -; ảnh scale(1.03); tên gạch chân. |
Không thêm ARIA |
| Focus- |
Focus trong card | Touch hoặc mobile dùng - và không transform. |
Không thêm ARIA |
| Focus- |
keyboard trên vùng chi tiết | outline 2px solid -, offset 2px. |
role="button", tabIndex={ |
| Touch active | hover: none hoặc pointer: coarse | scale(0.98); nền color-; thời gian -. |
Không thêm ARIA |
| Selected | selected true |
border- là -. |
Class is- |
| Skeleton | skeleton true |
Class chatty-; không pointer, không animation, cùng hộp card. |
aria- |
| In stock / sold out | availableForSale true / false |
Thêm class is- hoặc is-; nút action do caller vô hiệu bằng soldOut. |
Native disabled trên nút action |
| Adding | status ADDING của AddToCartButton |
Class is-; nút vô hiệu để chặn bấm lặp. |
aria- |
| Reduced motion | prefers- |
animation: none; transform none; ảnh không phóng khi hover. |
Không thêm ARIA |
Behaviour
| Interaction | Result |
|---|---|
| Mở chi tiết | Bấm, hoặc Enter / Space khi focus nằm trên chính vùng chi tiết, gọi onOpen. |
| Hiện action | Slot action chỉ render khi canAddToCart trả true theo pricing, khách ẩn giá và legacyPricing. |
| Tên dài | Kẹp 2 dòng; chiều cao tối thiểu bằng 2 line- |
| Hết hàng | Card chỉ đặt class theo availableForSale; caller sở hữu nút vô hiệu và tra cứu tồn kho khi chưa biết. |
| Lỗi thêm giỏ | Caller truyền thông báo vào footer; class chatty- dùng - và role body-. |
Copy
| String | i18n key | Where |
|---|---|---|
| View product | View product | aria- vùng chi tiết, ghép với tên |
| Added to cart | Added to cart | successLabel của AddToCartFeedback |
| Add to cart | Add to cart | Nhãn nút khi idle |
| Sold out | Sold out | Nhãn nút khi hết hàng |
| Added | Added | Nhãn trạng thái đã thêm |
| Try again | Try again | Nhãn trạng thái lỗi |
| Tên, giá | Caller- |
Dữ liệu product, không có chuỗi mặc định |
Source
| File | Evidence |
|---|---|
| API, anatomy và action | |
| Kích thước, trạng thái và theme | |
| Media canvas và hover |
Classic
Layout flush của Classic: ảnh tràn mép dưới góc card, khối chữ có padding, badge giảm giá, card hết hàng.
Show code
<chatty-product-card
layout="flush"
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">Add to cart</chatty-button>
</chatty-product-card>
<chatty-product-card
style="align-self: stretch"
layout="flush"
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" disabled>Sold out</chatty-button>
</chatty-product-card>Đang thêm giỏ kèm lỗi ở footer, và skeleton cùng hộp card.
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>Card Classic có giá so sánh, nút thêm vào giỏ bị vô hiệu và thông báo lỗi.
Show code
import React, {useState} from 'react';
import {ChatProductCarousel} from '@scripttag/v2/views/chat/ChatProductCarousel.jsx';
import {ChatNavigationContext} from '@scripttag/v2/views/chat/chatNavigationContext.js';
import {selectionStore} from '@scripttag/v2/stores/selectionStore.js';
import {ProductCard} from '@scripttag/v2/ui/ProductCard.jsx';
import ChatbotProductsMessage from '@scripttag/v1/Parts/InsertProduct/ChatbotProductsMessage/ChatbotProductsMessage.js';
import {
WidgetChatStateProvider,
createWidgetChatStateStore
} from '@scripttag/v1/WidgetChatState.js';
import {t} from '@scripttag/v2/helpers/i18n.js';
// PercentOffBadge's screen-reader phrase uses this class on both surfaces; the widget roots load it,
// the story does not mount them.
import '@scripttag/v1/Parts/InsertProduct/offerA11y.scss';
const variant = id => [`Default Title: ${id}`];
const products = [
{
productId: 'gid://shopify/Product/101',
title: 'Canvas tote bag',
url: 'https://shop.example/products/canvas-tote',
image: '/fixtures/tote.svg',
imageAlt: 'Canvas tote bag',
availableForSale: true,
currency: 'USD',
prices: ['$24.00'],
compareAtPrices: ['$32.00'],
variantOptions: variant('1001')
},
{
productId: 'gid://shopify/Product/102',
title: 'Ceramic mug',
url: 'https://shop.example/products/ceramic-mug',
image: '/fixtures/mug.svg',
imageAlt: 'Ceramic mug',
availableForSale: true,
currency: 'USD',
prices: ['$18.00'],
compareAtPrices: [],
variantOptions: variant('1002')
},
{
productId: 'gid://shopify/Product/103',
title: 'Wool cap',
url: 'https://shop.example/products/wool-cap',
image: '/fixtures/cap.svg',
imageAlt: 'Wool cap',
availableForSale: false,
currency: 'USD',
prices: ['$28.00'],
compareAtPrices: [],
variantOptions: variant('1003')
}
];
function AiCatalogue() {
selectionStore.setState({
selected: [{handle: 'ceramic-mug', title: 'Ceramic mug', image: '/fixtures/mug.svg'}]
});
return (
<div className="specimen-grid" style={{minWidth: 0}}>
<section style={{minWidth: 0}}>
<h4>Carousel: loaded, selected, sold out</h4>
<ChatNavigationContext.Provider value>
<ChatProductCarousel messageId="guide-carousel" products={products} />
</ChatNavigationContext.Provider>
</section>
<section style={{minWidth: 0}}>
<h4>Skeleton</h4>
<div style={{width: 184}}>
<ProductCard skeleton />
</div>
</section>
</div>
);
}
// Classic reads its translator from the widget chat state, whose default echoes the phrase without
// interpolating {{value}}; the live widget installs the real one.
const classicState = createWidgetChatStateStore({
i18n: Object.assign((...args) => t(...args), {locale: 'en'})
});
function ClassicCatalogue() {
return (
<div className="specimen-grid" style={{minWidth: 0}}>
<section style={{minWidth: 0}}>
<h4>Compare-at price, in stock, sold out</h4>
<div style={{width: 360, maxWidth: '100%'}}>
<WidgetChatStateProvider store={classicState}>
<ChatbotProductsMessage products={products} messageId="guide-classic" />
</WidgetChatStateProvider>
</div>
</section>
</div>
);
}
export function Catalogue() {
const [surface, setSurface] = useState(null);
const ref = node => {
const found = node?.closest('[data-surface]')?.dataset.surface;
if (found && found !== surface) setSurface(found);
};
return (
<div ref={ref} style={{minWidth: 0, width: '100%'}}>
{surface === 'classic' ? <ClassicCatalogue /> : surface ? <AiCatalogue /> : null}
</div>
);
}Import / element
| Component / element | Import / file | Scope root |
|---|---|---|
ProductCard |
import ProductCard from '@scripttag/ |
.Avada- |
Anatomy
| Part | Element |
|---|---|
| 1 | Root Card với class Avada-. |
| 2 | Vùng ảnh Avada- với button mở chi tiết. |
| 3 | Nút overlay "View similar", anh em của nút ảnh để không lồng button. |
| 4 | Khối thông tin Avada-. |
| 5 | Tên là thẻ a mở tab mới. |
| 6 | Đánh giá sao, chỉ khi có dữ liệu. |
| 7 | Giá qua WithheldPrice, kèm giá so sánh khi có. |
| 8 | Nút Button thêm vào giỏ trong tooltip wrapper. |
| 9 | Thông báo lỗi role="alert". |
Placement / order
| Context | Order |
|---|---|
| Carousel chat | ChatbotProductsMessage render một ProductCard cho mỗi sản phẩm; mỗi card rộng 205px, flex: 0 0 205px. |
| Trong card | Ảnh (overlay "View similar" ở góc phải dưới), tên, đánh giá, giá, rồi nút thêm vào giỏ; lỗi nằm cuối. |
Props
| Prop | Type | Values | Default | Notes |
|---|---|---|---|---|
product |
object | imageUrl, title, price, comparePrice, link, productId, availableForSale | Caller | Card đọc widget và store của Classic. |
removedBubblingEvents |
object | Handlers | Caller | Spread vào Card. |
isFromFindSimilar |
boolean | true / false | Caller | Ghi nhận hoạt động khi bấm tên từ danh sách tương tự. |
wizard |
boolean | true / false | false | Xem trước trong wizard: nút còn hiện nhưng bấm không làm gì. |
availableForSale |
boolean | true / false | false | Quyết định nút thêm vào giỏ và tooltip hết hàng. |
Sizes
| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
|---|---|---|---|---|---|---|---|
| Card | height auto | Không khai báo | Không khai báo | 14px | Không có chữ | Theo phần tử con | width 205px; border 1px; margin- |
| Media | Theo aspect- |
Không khai báo | Không khai báo | 14px | Không có chữ | Nút ảnh phủ kín vùng ảnh | Không override theo viewport |
| Overlay | Theo nội dung | 6px; hover 6px 12px | 6px khi hover | 10px | button-: 14pxDerived(14px = type(button- |
Native box | Chữ mở rộng tới max- |
| Thông tin | Theo nội dung | 10px 12px 12px | 10px | Không khai báo | Không có chữ | Không tương tác | Không override theo viewport |
| Tên | Kẹp 2 dòng | Không khai báo | 4px | Không khai báo | body-: 15pxDerived(15px = type(body- |
Thẻ a theo dòng chữ |
JS mobile class; mobileMaxWidth 899px |
| Giá | min- |
Không khai báo | 4px 6px | Không khai báo | body-: 15pxDerived(15px = type(body- |
Không tương tác | Cùng breakpoint với Tên |
| Giá so sánh | Theo line- |
margin- |
Không khai báo | Không khai báo | body-: 14pxDerived(14px = type(body- |
Không tương tác | Cùng breakpoint với Tên |
| Thêm vào giỏ | Theo nội dung | 10px 12px; mobile 6px 12px | Không khai báo | 10px | button-: 14pxDerived(14px = type(button- |
Native box, rộng 100% | Class Avada- khi isMobile |
Tokens
| Part | Token | Light | Dark |
|---|---|---|---|
| Chữ card | color |
#232323 | #ffffff |
| Nền card | background |
rgba(255,255,255,0.75) | transparent |
| Viền card | border |
#f2f2f2 | #303030 |
| Nền khối thông tin | background- |
#ffffff | #303030 |
| Nút thêm vào giỏ | background-; color |
Nền #ffffff; chữ #232323; hover nền #f8f9ff | Nền #ffffff; chữ #232323; hover nền #f8f9ff |
| Nút overlay | background-; color |
Nền #ffffff; chữ #303030 | Nền #232323; chữ #ffffff |
| Giá so sánh | color |
#000000bf | rgba(255,255,255,0.6) |
| Vòng focus | - |
Fallback #232323 | Fallback #232323 |
| Lỗi | - |
Fallback #b42318 | Fallback #b42318 |
States
| State | Trigger | Visual change (values) | ARIA/attribute |
|---|---|---|---|
| Hover card | pointer có hover và pointer fine | translateY(-2px); -; ảnh scale(1.03); tên gạch chân. |
Không thêm ARIA |
| Touch active | hover: none hoặc pointer: coarse | scale(0.98); nền color-. |
Không thêm ARIA |
| Focus- |
keyboard | outline 2px solid; outline- |
aria- "View product details" + tên |
| Focus- |
keyboard | outline 2px solid; offset 2px; nhãn mở rộng như hover. | aria- "View similar" + tên |
| Focus- |
keyboard | outline 2px solid currentColor; offset 2px; radius 4px. | Thẻ a native |
| Focus- |
keyboard | outline 2px solid; offset 2px. | aria- "Add to cart" + tên |
| Giỏ vô hiệu | !availableForSale hoặc đang thêm |
opacity 0.5; tooltip "Out of stock" khi hết hàng. | native disabled |
| Đang thêm | isBusy |
Hiện Spinner small trước nhãn; nút vô hiệu để chặn bấm lặp. |
aria- |
| Lỗi thêm giỏ | addError có giá trị |
Dòng chữ lỗi dưới nút, role body-, màu -. |
role="alert" |
| Reduced motion | prefers- |
transform none trên card, hover và active. | Không thêm ARIA |
Behaviour
| Interaction | Result |
|---|---|
| Bấm ảnh | Mở chi tiết ngay trong chat qua setProduct; nếu tắt chi tiết hoặc cần báo giá thì mở link ở tab mới; không làm gì khi wizard hoặc khối chat box. |
| Bấm tên | Thẻ a mở tab mới với noopener noreferrer; wizard chặn điều hướng. |
| View similar | Gửi tin nhắn chat yêu cầu sản phẩm tương tự và ghi nhận hoạt động; vô hiệu khi wizard; ẩn trong quản trị. |
| Thêm vào giỏ | Sản phẩm một biến thể và lô bằng 1 thì thêm trực tiếp; còn lại mở bộ chọn giỏ hàng; báo giá hoặc quản trị thì không thêm. |
| Giá bị ẩn | WithheldPrice quyết định hiển thị theo pricing, priceHidden và isAdmin; thiếu price thì không render hàng giá. |
Copy
| String | i18n key | Where |
|---|---|---|
| View product details | View product details | aria- nút ảnh, ghép với tên |
| View similar | View similar | Nhãn nút overlay |
| Add to cart | Add to cart | Nhãn nút giỏ |
| Added to cart | Added to cart | successLabel sau khi thêm |
| Out of stock | Out of stock | Tooltip khi hết hàng |
| Could not add to cart | Could not add to cart | Thông báo lỗi thêm giỏ |
Source
| File | Evidence |
|---|---|
| API, anatomy và hành vi | |
| Kích thước, màu và trạng thái | |
| Media canvas và hover |
Do / Don't
Accessibility
| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
|---|---|---|---|---|
| AI Mode | Vùng chi tiết role="button" có aria- "View product" ghép với tên; skeleton aria-. |
tabIndex={; Enter và Space chỉ kích hoạt khi focus nằm trên chính vùng chi tiết. |
Không có live region trong card | Đọc - trên nền card trong owning scope; nền Dark theo chatty- nên chưa đo ở đây. |
| Classic | Nút ảnh, overlay và giỏ có aria- ghép tên sản phẩm; tên là thẻ a; ảnh dùng alt hoặc tiêu đề. |
Nút ảnh và overlay là anh em, không lồng; mỗi phần tử có outline 2px khi focus- |
role="alert" cho lỗi thêm giỏ |
Chữ trên khối thông tin: Light 15.72:1Measured(#232323 / #ffffff = 15.72:1); Dark 13.20:1Measured(#ffffff / #303030 = 13.20:1) |