Key rules
- Classic: card rộng 205px và cuộn ngang;
SlideButtonchỉ hiện khi còn chỗ cuộn. - AI Mode: card chat rộng 184px; chỉ render sản phẩm được reply nhắc tới (
getMentionedProducts). - Admin: dùng lại carousel Classic với
isAdmin; nút thêm giỏ bị khoá. - Chọn card mở chi tiết trong chat khi có thể; trường hợp merchant ẩn chi tiết hoặc cần báo giá mở trang store.
On this page
Use when / Avoid
Dùng khi reply nhắc tới sản phẩm cụ thể. Danh mục chung hoặc kết quả tìm kiếm dài dùng trang kết quả riêng.
Use instead
| Component | Use when |
|---|---|
ChatbotProductsMessage |
Carousel sản phẩm của Classic và inbox. |
ChatProductCarousel |
Carousel sản phẩm của AI Mode. |
ProductCard |
Card sản phẩm của AI Mode; Classic có card riêng trong ChatbotProductsMessage. |
Entry points
| Surface | Owner |
|---|---|
| Classic | Reply có chatbotProducts, render bởi ChatbotProductsMessage |
| AI Mode | Block products trong ChatMessage |
| Admin | Block ChatbotProductsBlock trong inbox |
Flow
| Surface | Step | Trigger | UI shown | Component | Copy + i18n key | Timing |
|---|---|---|---|---|---|---|
| Classic | Hiện carousel | Reply có sản phẩm | Row cuộn ngang các card | ChatbotProductsMessage | Không có chuỗi riêng | Cuộn smooth |
| Classic | Chọn ảnh | Click nút media | Chi tiết trong chat, hoặc tab mới khi bị ẩn hoặc cần báo giá | ProductCard | View product details / View product details | Ngay khi click |
| Classic | View similar | Click nút overlay | Gửi tin nhắn tìm sản phẩm tương tự | ProductCard | View similar / View similar | Ngay khi click |
| AI Mode | Hiện carousel | Reply nhắc tới sản phẩm | Carousel card 184px | ChatProductCarousel | Không có chuỗi riêng | Không có timeout trong component |
| AI Mode | Chọn card | Click hoặc Enter/ |
Chi tiết trong panel, hoặc trang store khi không có handle | ProductCard | View product / View product | Ngay khi chọn |
| AI Mode | Thêm giỏ | Bấm nút thêm giỏ | Thêm thẳng hoặc mở chi tiết | AddToCartButton | Add to cart / Add to cart | Theo request của caller |
| Admin | Hiện carousel | Block có sản phẩm | Carousel Classic, nút thêm giỏ khoá | ChatbotProductsBlock | Không có chuỗi riêng | Không có timeout trong block |
Edge cases
| Surface | Case | Behaviour |
|---|---|---|
| Classic | Hết hàng | Nút thêm giỏ disabled và có tooltip Out of stock |
| Classic | Cần báo giá | Không có khối thêm giỏ; ảnh mở link trang store |
| AI Mode | Không có sản phẩm được nhắc | Không render carousel |
| AI Mode | Launcher bị ẩn | Card mở trang store cùng tab |
| Admin | Block không có sản phẩm | Trả null |
Live preview
Classic: bubble thu gọn là fixture từ chatty-icon-button; Current: FloatButtonWidget, chưa có element. Bag và menu (…) ở header: N/A trong preview.
AI Mode: SignIn, EmailContinue, Reset và Bag ở header: N/A trong preview.
Standard
Widget thread Standard; tương tác bằng dữ liệu fixture.
Show code
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import {IconClose, IconMessage} from '@avada/chatty-ui/elements/icon-glyphs.js';
import '@avada/chatty-ui/elements/surface.js';
import '@avada/chatty-ui/elements/avatar.js';
import '@avada/chatty-ui/elements/badge.js';
import '@avada/chatty-ui/elements/icon-button.js';
import '@avada/chatty-ui/elements/launcher.js';
import '@avada/chatty-ui/elements/button.js';
import {sameGroup} from '@avada/chatty-ui/behaviors/messages.js';
// Reference viewport: 1280 × 900 desktop, 390 × 900 mobile.
const sizes = {
classic: {width: 400, height: 700},
'ai-mode': {width: 820, height: 657},
admin: {width: 527, height: 842}
};
const question = {
id: 'question',
senderType: 'customer',
text: 'Can you help me?',
createdAt: '2026-01-15T10:00:00Z'
};
/** Viewport-relative sizing survives the initial hidden iframe layout. */
function widgetSize(surface) {
const mode = new URLSearchParams(location.search).get('mobile');
const isMobile = mode === null ? innerWidth < 900 : mode === 'true';
const width = `min(${sizes[surface].width}px, max(0px, 100vw - 40px))`;
const height = isMobile
? `min(${surface === 'admin' ? 848 : 888}px, round(down, calc(${width} * 2.2), 1px))`
: `${sizes[surface].height}px`;
return {...sizes[surface], height, mobile: isMobile};
}
/** Local immutable message state with real subscriptions for live previews. */
function fixtureStore(initial) {
let state = {messages: initial};
const listeners = new Set();
return {
getState: () => state,
subscribe(listener) {
listeners.add(listener);
return () => listeners.delete(listener);
},
setMessages(messages) {
state = {messages};
listeners.forEach(listener => listener());
}
};
}
/** Appends the viewer message without replacing the existing conversation. */
function appendViewer(store, surface, text) {
const message = {
id: `viewer-${store.getState().messages.length}`,
senderType: surface === 'admin' ? 'agent' : 'customer',
senderMeta: {name: surface === 'admin' ? 'Alex' : 'You'},
text,
createdAt: new Date().toISOString()
};
store.setMessages([...store.getState().messages, message]);
}
/**
* One shell owns surface sizing, header, thread and composer for every pattern.
* @param {string} surface
* @param {Object} store
* @param {Object} strings
* @param {Object} content
* @param {Function} renderMessage
* @param {Function} onSend
* @param {Object} registry
* @param {boolean} composerHidden
* @param {string} title
* @param {Object} headerStart
* @param {Object} headerActions
* @param {boolean} sheet
* @param {string | null} status
* @returns {Object}
*/
function patternShell({
surface,
store,
strings = {header: 'Store assistant', message: 'Message', send: 'Send'},
content,
renderMessage,
onSend,
registry,
title,
headerStart,
headerActions,
status = 'online',
sheet = false,
composerHidden = false
}) {
const size = widgetSize(surface);
const mobileSheet = sheet && size.mobile;
if (mobileSheet) {
size.width = 'none';
size.height = 'calc(100dvh - 12px)';
}
const toggle = (event, closed) => {
const frame = event.currentTarget.closest('[data-pattern-frame]');
const panel = frame.querySelector('chatty-surface');
const launcher = frame.querySelector('[data-pattern-launcher]');
panel.hidden = closed;
frame.dataset.closed = String(closed);
const background = frame.querySelector('[data-sheet-page]');
if (background) background.inert = !closed && surface === 'ai-mode';
launcher.hidden = !closed;
if (closed) {
launcher.style.insetBlockEnd = `${Math.max(surface === 'ai-mode' ? 40 : 16, frame.getBoundingClientRect().bottom - innerHeight + 20)}px`;
launcher.focus({preventScroll: true});
} else {
const composer = panel.querySelector('chatty-composer');
const input = !composer.hidden
? composer.renderRoot.querySelector('textarea')
: (panel
.querySelector('chatty-contact-form:not([hidden])')
?.renderRoot.querySelector('chatty-text-field') ??
panel.querySelector('form chatty-text-field') ??
panel.querySelector('[data-welcome-invitation]:not([hidden]) chatty-button') ??
panel
.querySelector('chatty-pre-chat:not([hidden])')
?.renderRoot.querySelector('chatty-button'));
input?.focus({preventScroll: true});
}
};
const sender = message => {
const content = renderMessage?.(message) ?? {};
const messages = store.getState().messages;
const previous = messages[messages.indexOf(message) - 1];
if (message.senderType !== 'bot' || sameGroup(message, previous)) return content;
return {
...content,
sender: html`<span style="display:inline-flex;align-items:center;gap:6px"
><chatty-avatar size="sm" label="Assistant">A</chatty-avatar
>${content.sender ?? message.senderName ?? message.senderMeta?.name ?? 'Assistant'}</span
>`
};
};
return html`<style>
[data-pattern-frame] {
display: flex;
position: relative;
justify-content: center;
inline-size: 100%;
min-inline-size: 0;
}
[data-pattern-frame='classic'] {
justify-content: flex-end;
}
[data-pattern-frame] chatty-surface::part(header) {
padding: 0;
}
[data-pattern-frame='classic'] chatty-surface::part(header),
[data-pattern-frame='ai-mode'] chatty-surface::part(header) {
border-bottom-width: 0;
}
[data-pattern-frame] [hidden] {
display: none !important;
}
[data-pattern-header] {
display: flex;
align-items: center;
gap: 10px;
box-sizing: border-box;
min-inline-size: 0;
block-size: 52px;
padding: 0 16px;
}
[data-pattern-frame='classic'] [data-pattern-header] {
block-size: 56px;
background: var(--chatty-color-accent);
color: var(--chatty-color-on-accent);
}
[data-pattern-frame='classic'] [data-pattern-header] chatty-icon-button {
--chatty-color-border-focus: var(--chatty-color-on-accent);
}
[data-pattern-frame='admin'] [data-pattern-header] {
block-size: 68px;
padding: 8px 12px;
}
[data-pattern-header] chatty-avatar {
--chatty-avatar-size: 32px;
}
[data-pattern-frame='classic'] [data-pattern-header] chatty-avatar {
--chatty-avatar-background: #fff;
}
[data-pattern-frame='classic'] [data-pattern-header] chatty-avatar::part(base) {
color: #303030;
border: 1px solid #767676;
}
[data-pattern-actions] {
display: flex;
align-items: center;
gap: 8px;
}
[data-pattern-title] {
flex: 1;
min-inline-size: 0;
display: flex;
flex-direction: column;
}
[data-pattern-frame='admin'] [data-pattern-title] {
gap: 4px;
}
[data-pattern-frame='admin'] [data-pattern-title] strong {
display: flex;
align-items: center;
min-block-size: 28px;
font: var(--p-font-weight-semibold, 650) var(--p-text-heading-md-font-size, 14px) /
var(--p-text-heading-md-font-line-height, 20px) var(--p-font-family-sans, system-ui);
}
[data-pattern-title] strong {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
[data-pattern-header] chatty-icon-button {
--chatty-icon-button-size: 32px;
--chatty-icon-button-color: currentColor;
}
@media (max-width: 899px), (pointer: coarse) {
[data-pattern-header] chatty-icon-button {
--chatty-icon-button-size: 44px;
}
}
[data-pattern-launcher] {
position: absolute;
inset-inline-end: 0;
inset-block-end: 0;
}
[data-pattern-frame='ai-mode'] [data-pattern-launcher] {
inset-inline-end: auto;
inset-inline-start: 50%;
transform: translateX(-50%);
}
[data-pattern-frame='classic'] [data-pattern-launcher] {
--chatty-icon-button-size: 56px;
border-radius: 50%;
background: var(--chatty-color-accent);
--chatty-icon-button-color: var(--chatty-color-on-accent);
}
[data-sheet-mobile='true'] {
position: fixed;
inset: 0;
inline-size: 100vw;
}
[data-sheet-mobile='true'] chatty-surface::part(base) {
border-radius: 16px 16px 0 0;
}
[data-sheet-mobile='true'] chatty-surface {
position: relative;
z-index: 2;
margin-block-start: 12px;
}
[data-sheet-page],
[data-sheet-scrim] {
position: absolute;
inset: 0;
box-sizing: border-box;
}
[data-sheet-page] {
padding: 20px;
background: var(--chatty-color-bg-surface);
color: var(--chatty-color-text);
}
[data-sheet-scrim] {
z-index: 1;
border: 0;
background: rgb(0 0 0 / 40%);
animation: sheet-scrim 400ms ease;
}
[data-sheet-mobile='true'][data-closed='true'] [data-sheet-scrim] {
display: none;
}
[data-sheet-mobile='true'] [data-pattern-launcher] {
z-index: 3;
}
@keyframes sheet-scrim {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@media (prefers-reduced-motion: reduce) {
[data-sheet-scrim] {
animation: none;
}
}
</style>
<div
data-pattern-frame=${surface}
data-sheet-mobile=${String(mobileSheet)}
data-closed="false"
style=${`block-size:calc(${size.height} + ${mobileSheet ? 12 : 0}px)`}
>
${
mobileSheet
? html`<div data-sheet-page .inert=${surface === 'ai-mode'}>
<p>Example storefront</p>
<chatty-button
variant="secondary"
type="button"
@click=${event => {
event.currentTarget.textContent = 'Products opened';
}}
>
Browse products
</chatty-button>
</div>
${surface === 'ai-mode' ? html`<button type="button" data-sheet-scrim tabindex="-1" aria-label="Close chat background" @click=${event => toggle(event, true)}></button>` : ''}`
: ''
}
<chatty-surface
data-chatty-surface=${surface}
data-chatty-theme=${surface === 'admin' ? 'light' : (document.documentElement.dataset.chattyTheme ?? document.documentElement.dataset.theme ?? 'light')}
style=${`inline-size:100%;max-inline-size:${mobileSheet ? 'none' : `${size.width}px`};--chatty-surface-height:${size.height}`}
.store=${store}
.registry=${registry ?? null}
viewer-type=${surface === 'admin' ? 'agent' : 'customer'}
.selfTypes=${surface === 'admin' ? ['agent', 'bot'] : null}
.renderMessage=${sender}
>
<div slot="header" data-pattern-header>
${headerStart ?? ''}
${surface === 'admin' ? '' : html`<chatty-avatar label="Store" .status=${status}>S</chatty-avatar>`}
<span data-pattern-title
><strong
>${title ?? (surface === 'admin' ? 'Customer conversation' : strings.header)}</strong
>${surface === 'admin' ? html`<chatty-badge size="sm" variant="secondary" style="align-self:flex-start">Customer</chatty-badge>` : status == null ? '' : html`<small data-pattern-status>${status === 'online' ? 'Open' : 'Closed'}</small>`}</span
>
<span data-pattern-actions>${headerActions ?? ''}</span>
${
surface === 'admin'
? ''
: html`<chatty-icon-button label="Close panel" @click=${event => toggle(event, true)}
>${IconClose()}</chatty-icon-button
>`
}
</div>
<chatty-thread .strings=${{bot: 'Assistant', ...strings}}></chatty-thread>${content ?? ''}
<chatty-composer
slot="footer"
?hidden=${composerHidden}
.label=${strings.message}
.sendLabel=${strings.send}
@chatty-send=${event => {
appendViewer(store, surface, event.detail.text);
if (onSend) onSend(event.detail.text, event.currentTarget);
else if (surface !== 'admin')
store.setMessages([
...store.getState().messages,
{
id: `fixture-${store.getState().messages.length}`,
senderType: 'bot',
text: `You asked: “${event.detail.text}”. I can help with that.`,
hasEventTime: false
}
]);
}}
></chatty-composer> </chatty-surface
>${
surface === 'admin'
? ''
: surface === 'ai-mode'
? html`<chatty-launcher
data-pattern-launcher
hidden
label="Open chat"
@chatty-open=${event => toggle(event, false)}
>${IconMessage({size: 20, slot: 'icon'})}Ask a question</chatty-launcher
>`
: html`<chatty-icon-button
data-pattern-launcher
hidden
size="lg"
label="Open chat"
@click=${event => toggle(event, false)}
>${IconMessage({size: 24})}</chatty-icon-button
>`
}
</div>`;
}
import '@avada/chatty-ui/elements/chatty-block-products.js';
const products = [
{
id: 'tote',
title: 'Canvas tote',
amount: 24,
price: '$24.00',
compareAtPrice: '$32.00',
image: 'https://chatty-ui-research.avada-tesla-chatty.workers.dev/fixtures/tote.svg'
},
{
id: 'cap',
title: 'Cotton cap',
amount: 18,
price: '$18.00',
image: 'https://chatty-ui-research.avada-tesla-chatty.workers.dev/fixtures/cap.svg',
available: false
},
{
id: 'mug',
title: 'Stoneware mug',
amount: 16,
price: '$16.00',
image: 'https://chatty-ui-research.avada-tesla-chatty.workers.dev/fixtures/mug.svg',
cartState: 'error',
cartError: 'Could not add to cart'
}
];
/** Builds a shopping thread with isolated host-owned fixture cart state.
* @param {string} surface
* @returns {Object}
*/
function cartPattern(surface) {
const store = fixtureStore([
question,
{
id: 'products',
senderType: 'bot',
text: 'Here are three options for you.',
blocks: [{type: 'products', data: {products}}]
}
]);
const add = event => {
const product = event.detail.product;
const update = cartState =>
store.setMessages(
store.getState().messages.map(m =>
m.id !== 'products'
? m
: {
...m,
blocks: [
{
type: 'products',
data: {
products: m.blocks[0].data.products.map(p =>
p.id === product.id ? {...p, cartState} : p
)
}
}
]
}
)
);
update('loading');
const finish = () => {
update('added');
if (surface === 'ai-mode')
store.setMessages([
...store.getState().messages,
{
id: `receipt-${store.getState().messages.length}`,
senderType: 'bot',
blocks: [
{
type: 'cart-confirmation',
data: {
receipts: [
{title: product.title, quantity: 1, linePrice: product.amount, currency: 'USD'}
]
}
}
]
}
]);
setTimeout(() => update('idle'), surface === 'classic' ? 2000 : 1650);
};
if (matchMedia('(prefers-reduced-motion: reduce)').matches) finish();
else setTimeout(finish, 450);
};
if (surface === 'admin')
store.setMessages([
...store.getState().messages,
{
id: 'receipt',
senderType: 'bot',
blocks: [
{
type: 'cart-confirmation',
data: {receipts: [{title: 'Canvas tote', quantity: 1, linePrice: 24, currency: 'USD'}]}
}
]
}
]);
return html`<div
style="inline-size:100%;min-inline-size:0"
@chatty-add-to-cart=${add}
@chatty-view-cart=${event => {
const line = store
.getState()
.messages.flatMap(message => message.blocks ?? [])
.filter(block => block.type === 'cart-confirmation')
.at(-1).data.receipts[0];
store.setMessages([
...store.getState().messages,
{
id: `bag-${store.getState().messages.length}`,
senderType: 'bot',
text: `Your bag: ${line.title} × ${line.quantity} — ${new Intl.NumberFormat('en', {style: 'currency', currency: line.currency}).format(line.linePrice)}`
}
]);
}}
>
${patternShell({surface, store})}
</div>`;
}
export function Standard({surface}) {
return cartPattern(surface);
}Chọn ảnh/card → chi tiết: N/A trong preview. View similar: N/A trong preview; slot overlay của card nằm trong open button nên chưa hỗ trợ interactive overlay độc lập mà không lồng button. Cart action dùng fixture; Admin chỉ đọc. Quote/launcher navigation: N/A trong preview.
Current
Classic
Import / element
ChatbotProductsMessage
| Component / element | Import / file | Scope root |
|---|---|---|
ChatbotProductsMessage |
import ChatbotProductsMessage from '@scripttag/ |
.Avada- |
Anatomy
ChatbotProductsMessage
| Part | Element |
|---|---|
| 1 | Nút Avada- khi có anchor. |
| 2 | Wrapper Avada- chứa SlideButton prev/ |
| 3 | Row cuộn Avada-. |
| 4 | Một ProductCard cho mỗi sản phẩm. |
Placement / order
ChatbotProductsMessage
| Context | Order |
|---|---|
| Reply có sản phẩm | Anchor tương tự (nếu có) rồi wrapper: prev, row card, next. Trong card: ảnh với View similar, tiêu đề, rating, giá, nút thêm giỏ. |
Props
ChatbotProductsMessage
| Prop | Type | Values | Default | Notes |
|---|---|---|---|---|
products |
array | Sản phẩm được nhắc tới | Không có | Chỉ nhắc tới sản phẩm có trong reply |
isAdmin |
boolean | true / false | Không có | Admin: giá format theo shop, nút thêm giỏ khoá |
wizard |
boolean | true / false | false |
Preview wizard: nút không hoạt động |
variantMode |
string | PRODUCT_ |
PRODUCT_ |
Chọn variant hiển thị trên card |
Sizes
ChatbotProductsMessage
| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
|---|---|---|---|---|---|---|---|
| card | Theo nội dung | Info 10px 12px 12px | Info 10px | 14px | Theo Info; không đặt role ở wrapper | Ảnh là nút inset: 0 phủ cả ảnh |
Width 205px; flex: 0 0 205px |
| row | Theo card | — | 8px | — | — | — | Cuộn ngang, scroll-; ẩn scrollbar |
Tokens
ChatbotProductsMessage
| Part | Token | Light | Dark |
|---|---|---|---|
| Card | color; background; border |
#232323; rgba(255, 255, 255, 0.75); 1px #f2f2f2 | #ffffff; transparent; 1px #303030 |
| Info | background- |
#ffffff | #303030 |
States
ChatbotProductsMessage
| State | Trigger | Visual change (values) | ARIA/attribute |
|---|---|---|---|
| Media focus- |
keyboard | Outline 2px var(, offset -3px. |
Native button |
| Media disabled | Không mở được chi tiết | Con trỏ mặc định. | disabled |
| Overlay hover / focus | pointer hoặc keyboard | Padding 6px 12px; chữ rộng tối đa 120px, opacity 1. | Native button |
| Thêm giỏ bị khoá | Hết hàng, admin hoặc đang busy | isAddToCartDisabled; nút disabled. |
disabled |
Behaviour
ChatbotProductsMessage
| Interaction | Result |
|---|---|
| Chọn ảnh | Mở chi tiết trong chat khi không disableProductDetail và không cần báo giá; ngược lại mở link ở tab mới. |
| Chọn tiêu đề | Link target="_blank" mở trang sản phẩm. |
| View similar | Gửi tin nhắn tìm sản phẩm tương tự; admin không kích hoạt. |
Copy
ChatbotProductsMessage
| String | i18n key | Where |
|---|---|---|
| Similar to | Similar to | Anchor, khi có findSimilar |
| View similar | View similar | Nút overlay trên ảnh card |
| Out of stock | Out of stock | Tooltip nút thêm giỏ |
Source
ChatbotProductsMessage
| File | Evidence |
|---|---|
| Carousel và card | |
| Card markup | |
| Card style |
AI Mode
`ChatProductCarousel` thật với ba card: giảm giá, giá thường, hết hàng.
Show code
import React from 'react';
import {ChatProductCarousel} from '@scripttag/v2/views/chat/ChatProductCarousel.jsx';
import {ChatNavigationContext} from '@scripttag/v2/views/chat/chatNavigationContext.js';
const product = (id, title, slug, image, price, compareAt, availableForSale = true) => ({
productId: `gid://shopify/Product/${id}`,
title,
url: `https://shop.example/products/${slug}`,
image,
imageAlt: title,
availableForSale,
currency: 'USD',
prices: [price],
compareAtPrices: compareAt ? [compareAt] : [],
variantOptions: [`Default Title: ${id}1`]
});
const products = [
product(101, 'Canvas tote bag', 'canvas-tote', '/fixtures/tote.svg', '$24.00', '$32.00'),
product(102, 'Ceramic mug', 'ceramic-mug', '/fixtures/mug.svg', '$18.00'),
product(103, 'Wool cap', 'wool-cap', '/fixtures/cap.svg', '$28.00', null, false)
];
export function Carousel() {
return (
<ChatNavigationContext.Provider value>
<ChatProductCarousel messageId="guide-recommendation" products={products} />
</ChatNavigationContext.Provider>
);
}Import / element
ChatProductCarousel
| Component / element | Import / file | Scope root |
|---|---|---|
ChatProductCarousel |
@scripttag/ |
.chatty- |
ProductCard
| Component / element | Import / file | Scope root |
|---|---|---|
ProductCard |
@scripttag/ |
.chatty- |
Anatomy
ChatProductCarousel
| Part | Element |
|---|---|
| 1 | Anchor chatty- khi có nguồn tương tự. |
| 2 | Carousel với class chatty-. |
| 3 | Mỗi sản phẩm là ProductCard với AddToCartButton. |
ProductCard
| Part | Element |
|---|---|
| 1 | Root chatty-. |
| 2 | Vùng mở chi tiết chatty- với role="button". |
| 3 | Media chatty- với ProductImage. |
| 4 | Tên chatty-; rating tuỳ chọn. |
| 5 | Hàng giá PriceRow. |
| 6 | Slot action và footer dưới thông tin. |
Placement / order
ChatProductCarousel
| Context | Order |
|---|---|
| Reply có sản phẩm | Carousel render theo thứ tự sản phẩm được nhắc trong nội dung reply; không có sản phẩm được nhắc thì không render. |
ProductCard
| Context | Order |
|---|---|
| Trong carousel | Link (media, tên, rating, giá) rồi action rồi footer. |
Props
ChatProductCarousel
| Prop | Type | Values | Default | Notes |
|---|---|---|---|---|
messageId |
string | Id của reply | Không có | Gắn vào tracking click card |
products |
array | Sản phẩm của reply | Không có | Rỗng thì trả null |
tracksAiLinks |
boolean | true / false | false |
AI chọn sản phẩm: click sang store tính là AI link |
ProductCard
| Prop | Type | Values | Default | Notes |
|---|---|---|---|---|
product |
object | Trường hiển thị của card | Bắt buộc | Có id, handle, name, img, price |
onOpen |
function | Nhận trigger của card | Bắt buộc | Gọi khi click hoặc Enter/ |
selected |
boolean | true / false | false |
Thêm class is- |
skeleton |
boolean | true / false | false |
Cùng box với card đã tải |
Sizes
ChatProductCarousel
| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
|---|---|---|---|---|---|---|---|
| card | Theo nội dung | Theo ProductCard | - 12px |
Theo ProductCard | Theo ProductCard | Card là vùng nhấn | Width 184px; flex: 0 0 184px |
| track | Theo card | — | 12px | — | — | Cuộn ngang scroll- |
Mobile ẩn arrow |
| arrow | Theo - |
— | 8px | — | — | 32px desktop | Mobile ẩn arrow |
ProductCard
| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
|---|---|---|---|---|---|---|---|
| card | Theo nội dung | 10px | 8px | - (20px) |
Role theo type của surface | Vùng link phủ media, tên, giá | Width 184px do carousel |
| media | Tỉ lệ aspect- |
— | — | 14px | — | Thuộc vùng link | Ảnh object- |
Tokens
ChatProductCarousel
| Part | Token | Light | Dark |
|---|---|---|---|
| Khoảng cách card | - |
12px | Same |
| Arrow | - |
32px | Same; mobile ẩn |
| Arrow shadow | - |
Theo foundation của AI Mode | Same |
ProductCard
| Part | Token | Light | Dark |
|---|---|---|---|
| Viền khi chọn | - |
Merchant accent theo foundation | Same |
| Màu chữ | color: inherit |
Kế thừa từ surface | Kế thừa từ surface |
States
ChatProductCarousel
| State | Trigger | Visual change (values) | ARIA/attribute |
|---|---|---|---|
| Arrow active | pointer down | scale(; giữ translateY( trên desktop. |
Native button |
| Arrow chỉ khi còn chỗ cuộn | Có thể cuộn tới mốc | Nút prev hoặc next hiện. | aria- Previous |
ProductCard
| State | Trigger | Visual change (values) | ARIA/attribute |
|---|---|---|---|
| Hover (hover: hover và pointer: fine) | pointer | Card translateY(; ảnh scale(; tên gạch chân. |
Không thêm ARIA |
| Focus- |
keyboard | Outline 2px var(, offset 2px. |
Native focus |
| Selected | selected true |
Viền -. |
Class is- |
| Reduced motion | prefers- |
Card animation: none; ảnh transition: none. |
Không đổi |
Behaviour
ChatProductCarousel
| Interaction | Result |
|---|---|
| Chọn card | Có handle thì mở chi tiết trong panel; không thì mở trang store. |
| Launcher bị ẩn và không có navigate | Mở trang store cùng tab, không bật panel. |
| Nút thêm giỏ | Thêm thẳng khi có variant duy nhất và còn hàng; không thì mở chi tiết. |
ProductCard
| Interaction | Result |
|---|---|
| Click hoặc Enter/ |
Gọi onOpen với trigger card. |
| Tên dài | Tên bị cắt ở 2 dòng bằng chatty-. |
Copy
ChatProductCarousel
| String | i18n key | Where |
|---|---|---|
| Similar to | Similar to | Anchor nguồn tương tự |
| Previous | Previous | aria- nút prev |
ProductCard
| String | i18n key | Where |
|---|---|---|
| View product | View product | aria- của vùng link, kèm tên sản phẩm |
Source
ChatProductCarousel
| File | Evidence |
|---|---|
| Carousel và card | |
| Layout carousel | |
| Caller trong thread |
ProductCard
| File | Evidence |
|---|---|
| Markup card | |
| Style card | |
| Media và interaction dùng chung |
Admin
Admin read-only Standard.
Show code
import '@avada/chatty-ui/tokens/admin.css';
import {html} from 'lit';
import {IconClose, IconMessage} from '@avada/chatty-ui/elements/icon-glyphs.js';
import '@avada/chatty-ui/elements/surface.js';
import '@avada/chatty-ui/elements/avatar.js';
import '@avada/chatty-ui/elements/badge.js';
import '@avada/chatty-ui/elements/icon-button.js';
import '@avada/chatty-ui/elements/launcher.js';
import '@avada/chatty-ui/elements/button.js';
import {sameGroup} from '@avada/chatty-ui/behaviors/messages.js';
// Reference viewport: 1280 × 900 desktop, 390 × 900 mobile.
const sizes = {
classic: {width: 400, height: 700},
'ai-mode': {width: 820, height: 657},
admin: {width: 527, height: 842}
};
const question = {
id: 'question',
senderType: 'customer',
text: 'Can you help me?',
createdAt: '2026-01-15T10:00:00Z'
};
/** Viewport-relative sizing survives the initial hidden iframe layout. */
function widgetSize(surface) {
const mode = new URLSearchParams(location.search).get('mobile');
const isMobile = mode === null ? innerWidth < 900 : mode === 'true';
const width = `min(${sizes[surface].width}px, max(0px, 100vw - 40px))`;
const height = isMobile
? `min(${surface === 'admin' ? 848 : 888}px, round(down, calc(${width} * 2.2), 1px))`
: `${sizes[surface].height}px`;
return {...sizes[surface], height, mobile: isMobile};
}
/** Local immutable message state with real subscriptions for live previews. */
function fixtureStore(initial) {
let state = {messages: initial};
const listeners = new Set();
return {
getState: () => state,
subscribe(listener) {
listeners.add(listener);
return () => listeners.delete(listener);
},
setMessages(messages) {
state = {messages};
listeners.forEach(listener => listener());
}
};
}
/** Appends the viewer message without replacing the existing conversation. */
function appendViewer(store, surface, text) {
const message = {
id: `viewer-${store.getState().messages.length}`,
senderType: surface === 'admin' ? 'agent' : 'customer',
senderMeta: {name: surface === 'admin' ? 'Alex' : 'You'},
text,
createdAt: new Date().toISOString()
};
store.setMessages([...store.getState().messages, message]);
}
/**
* One shell owns surface sizing, header, thread and composer for every pattern.
* @param {string} surface
* @param {Object} store
* @param {Object} strings
* @param {Object} content
* @param {Function} renderMessage
* @param {Function} onSend
* @param {Object} registry
* @param {boolean} composerHidden
* @param {string} title
* @param {Object} headerStart
* @param {Object} headerActions
* @param {boolean} sheet
* @param {string | null} status
* @returns {Object}
*/
function patternShell({
surface,
store,
strings = {header: 'Store assistant', message: 'Message', send: 'Send'},
content,
renderMessage,
onSend,
registry,
title,
headerStart,
headerActions,
status = 'online',
sheet = false,
composerHidden = false
}) {
const size = widgetSize(surface);
const mobileSheet = sheet && size.mobile;
if (mobileSheet) {
size.width = 'none';
size.height = 'calc(100dvh - 12px)';
}
const toggle = (event, closed) => {
const frame = event.currentTarget.closest('[data-pattern-frame]');
const panel = frame.querySelector('chatty-surface');
const launcher = frame.querySelector('[data-pattern-launcher]');
panel.hidden = closed;
frame.dataset.closed = String(closed);
const background = frame.querySelector('[data-sheet-page]');
if (background) background.inert = !closed && surface === 'ai-mode';
launcher.hidden = !closed;
if (closed) {
launcher.style.insetBlockEnd = `${Math.max(surface === 'ai-mode' ? 40 : 16, frame.getBoundingClientRect().bottom - innerHeight + 20)}px`;
launcher.focus({preventScroll: true});
} else {
const composer = panel.querySelector('chatty-composer');
const input = !composer.hidden
? composer.renderRoot.querySelector('textarea')
: (panel
.querySelector('chatty-contact-form:not([hidden])')
?.renderRoot.querySelector('chatty-text-field') ??
panel.querySelector('form chatty-text-field') ??
panel.querySelector('[data-welcome-invitation]:not([hidden]) chatty-button') ??
panel
.querySelector('chatty-pre-chat:not([hidden])')
?.renderRoot.querySelector('chatty-button'));
input?.focus({preventScroll: true});
}
};
const sender = message => {
const content = renderMessage?.(message) ?? {};
const messages = store.getState().messages;
const previous = messages[messages.indexOf(message) - 1];
if (message.senderType !== 'bot' || sameGroup(message, previous)) return content;
return {
...content,
sender: html`<span style="display:inline-flex;align-items:center;gap:6px"
><chatty-avatar size="sm" label="Assistant">A</chatty-avatar
>${content.sender ?? message.senderName ?? message.senderMeta?.name ?? 'Assistant'}</span
>`
};
};
return html`<style>
[data-pattern-frame] {
display: flex;
position: relative;
justify-content: center;
inline-size: 100%;
min-inline-size: 0;
}
[data-pattern-frame='classic'] {
justify-content: flex-end;
}
[data-pattern-frame] chatty-surface::part(header) {
padding: 0;
}
[data-pattern-frame='classic'] chatty-surface::part(header),
[data-pattern-frame='ai-mode'] chatty-surface::part(header) {
border-bottom-width: 0;
}
[data-pattern-frame] [hidden] {
display: none !important;
}
[data-pattern-header] {
display: flex;
align-items: center;
gap: 10px;
box-sizing: border-box;
min-inline-size: 0;
block-size: 52px;
padding: 0 16px;
}
[data-pattern-frame='classic'] [data-pattern-header] {
block-size: 56px;
background: var(--chatty-color-accent);
color: var(--chatty-color-on-accent);
}
[data-pattern-frame='classic'] [data-pattern-header] chatty-icon-button {
--chatty-color-border-focus: var(--chatty-color-on-accent);
}
[data-pattern-frame='admin'] [data-pattern-header] {
block-size: 68px;
padding: 8px 12px;
}
[data-pattern-header] chatty-avatar {
--chatty-avatar-size: 32px;
}
[data-pattern-frame='classic'] [data-pattern-header] chatty-avatar {
--chatty-avatar-background: #fff;
}
[data-pattern-frame='classic'] [data-pattern-header] chatty-avatar::part(base) {
color: #303030;
border: 1px solid #767676;
}
[data-pattern-actions] {
display: flex;
align-items: center;
gap: 8px;
}
[data-pattern-title] {
flex: 1;
min-inline-size: 0;
display: flex;
flex-direction: column;
}
[data-pattern-frame='admin'] [data-pattern-title] {
gap: 4px;
}
[data-pattern-frame='admin'] [data-pattern-title] strong {
display: flex;
align-items: center;
min-block-size: 28px;
font: var(--p-font-weight-semibold, 650) var(--p-text-heading-md-font-size, 14px) /
var(--p-text-heading-md-font-line-height, 20px) var(--p-font-family-sans, system-ui);
}
[data-pattern-title] strong {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
[data-pattern-header] chatty-icon-button {
--chatty-icon-button-size: 32px;
--chatty-icon-button-color: currentColor;
}
@media (max-width: 899px), (pointer: coarse) {
[data-pattern-header] chatty-icon-button {
--chatty-icon-button-size: 44px;
}
}
[data-pattern-launcher] {
position: absolute;
inset-inline-end: 0;
inset-block-end: 0;
}
[data-pattern-frame='ai-mode'] [data-pattern-launcher] {
inset-inline-end: auto;
inset-inline-start: 50%;
transform: translateX(-50%);
}
[data-pattern-frame='classic'] [data-pattern-launcher] {
--chatty-icon-button-size: 56px;
border-radius: 50%;
background: var(--chatty-color-accent);
--chatty-icon-button-color: var(--chatty-color-on-accent);
}
[data-sheet-mobile='true'] {
position: fixed;
inset: 0;
inline-size: 100vw;
}
[data-sheet-mobile='true'] chatty-surface::part(base) {
border-radius: 16px 16px 0 0;
}
[data-sheet-mobile='true'] chatty-surface {
position: relative;
z-index: 2;
margin-block-start: 12px;
}
[data-sheet-page],
[data-sheet-scrim] {
position: absolute;
inset: 0;
box-sizing: border-box;
}
[data-sheet-page] {
padding: 20px;
background: var(--chatty-color-bg-surface);
color: var(--chatty-color-text);
}
[data-sheet-scrim] {
z-index: 1;
border: 0;
background: rgb(0 0 0 / 40%);
animation: sheet-scrim 400ms ease;
}
[data-sheet-mobile='true'][data-closed='true'] [data-sheet-scrim] {
display: none;
}
[data-sheet-mobile='true'] [data-pattern-launcher] {
z-index: 3;
}
@keyframes sheet-scrim {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@media (prefers-reduced-motion: reduce) {
[data-sheet-scrim] {
animation: none;
}
}
</style>
<div
data-pattern-frame=${surface}
data-sheet-mobile=${String(mobileSheet)}
data-closed="false"
style=${`block-size:calc(${size.height} + ${mobileSheet ? 12 : 0}px)`}
>
${
mobileSheet
? html`<div data-sheet-page .inert=${surface === 'ai-mode'}>
<p>Example storefront</p>
<chatty-button
variant="secondary"
type="button"
@click=${event => {
event.currentTarget.textContent = 'Products opened';
}}
>
Browse products
</chatty-button>
</div>
${surface === 'ai-mode' ? html`<button type="button" data-sheet-scrim tabindex="-1" aria-label="Close chat background" @click=${event => toggle(event, true)}></button>` : ''}`
: ''
}
<chatty-surface
data-chatty-surface=${surface}
data-chatty-theme=${surface === 'admin' ? 'light' : (document.documentElement.dataset.chattyTheme ?? document.documentElement.dataset.theme ?? 'light')}
style=${`inline-size:100%;max-inline-size:${mobileSheet ? 'none' : `${size.width}px`};--chatty-surface-height:${size.height}`}
.store=${store}
.registry=${registry ?? null}
viewer-type=${surface === 'admin' ? 'agent' : 'customer'}
.selfTypes=${surface === 'admin' ? ['agent', 'bot'] : null}
.renderMessage=${sender}
>
<div slot="header" data-pattern-header>
${headerStart ?? ''}
${surface === 'admin' ? '' : html`<chatty-avatar label="Store" .status=${status}>S</chatty-avatar>`}
<span data-pattern-title
><strong
>${title ?? (surface === 'admin' ? 'Customer conversation' : strings.header)}</strong
>${surface === 'admin' ? html`<chatty-badge size="sm" variant="secondary" style="align-self:flex-start">Customer</chatty-badge>` : status == null ? '' : html`<small data-pattern-status>${status === 'online' ? 'Open' : 'Closed'}</small>`}</span
>
<span data-pattern-actions>${headerActions ?? ''}</span>
${
surface === 'admin'
? ''
: html`<chatty-icon-button label="Close panel" @click=${event => toggle(event, true)}
>${IconClose()}</chatty-icon-button
>`
}
</div>
<chatty-thread .strings=${{bot: 'Assistant', ...strings}}></chatty-thread>${content ?? ''}
<chatty-composer
slot="footer"
?hidden=${composerHidden}
.label=${strings.message}
.sendLabel=${strings.send}
@chatty-send=${event => {
appendViewer(store, surface, event.detail.text);
if (onSend) onSend(event.detail.text, event.currentTarget);
else if (surface !== 'admin')
store.setMessages([
...store.getState().messages,
{
id: `fixture-${store.getState().messages.length}`,
senderType: 'bot',
text: `You asked: “${event.detail.text}”. I can help with that.`,
hasEventTime: false
}
]);
}}
></chatty-composer> </chatty-surface
>${
surface === 'admin'
? ''
: surface === 'ai-mode'
? html`<chatty-launcher
data-pattern-launcher
hidden
label="Open chat"
@chatty-open=${event => toggle(event, false)}
>${IconMessage({size: 20, slot: 'icon'})}Ask a question</chatty-launcher
>`
: html`<chatty-icon-button
data-pattern-launcher
hidden
size="lg"
label="Open chat"
@click=${event => toggle(event, false)}
>${IconMessage({size: 24})}</chatty-icon-button
>`
}
</div>`;
}
import '@avada/chatty-ui/elements/chatty-block-products.js';
const products = [
{
id: 'tote',
title: 'Canvas tote',
amount: 24,
price: '$24.00',
compareAtPrice: '$32.00',
image: 'https://chatty-ui-research.avada-tesla-chatty.workers.dev/fixtures/tote.svg'
},
{
id: 'cap',
title: 'Cotton cap',
amount: 18,
price: '$18.00',
image: 'https://chatty-ui-research.avada-tesla-chatty.workers.dev/fixtures/cap.svg',
available: false
},
{
id: 'mug',
title: 'Stoneware mug',
amount: 16,
price: '$16.00',
image: 'https://chatty-ui-research.avada-tesla-chatty.workers.dev/fixtures/mug.svg',
cartState: 'error',
cartError: 'Could not add to cart'
}
];
/** Builds a shopping thread with isolated host-owned fixture cart state.
* @param {string} surface
* @returns {Object}
*/
function cartPattern(surface) {
const store = fixtureStore([
question,
{
id: 'products',
senderType: 'bot',
text: 'Here are three options for you.',
blocks: [{type: 'products', data: {products}}]
}
]);
const add = event => {
const product = event.detail.product;
const update = cartState =>
store.setMessages(
store.getState().messages.map(m =>
m.id !== 'products'
? m
: {
...m,
blocks: [
{
type: 'products',
data: {
products: m.blocks[0].data.products.map(p =>
p.id === product.id ? {...p, cartState} : p
)
}
}
]
}
)
);
update('loading');
const finish = () => {
update('added');
if (surface === 'ai-mode')
store.setMessages([
...store.getState().messages,
{
id: `receipt-${store.getState().messages.length}`,
senderType: 'bot',
blocks: [
{
type: 'cart-confirmation',
data: {
receipts: [
{title: product.title, quantity: 1, linePrice: product.amount, currency: 'USD'}
]
}
}
]
}
]);
setTimeout(() => update('idle'), surface === 'classic' ? 2000 : 1650);
};
if (matchMedia('(prefers-reduced-motion: reduce)').matches) finish();
else setTimeout(finish, 450);
};
if (surface === 'admin')
store.setMessages([
...store.getState().messages,
{
id: 'receipt',
senderType: 'bot',
blocks: [
{
type: 'cart-confirmation',
data: {receipts: [{title: 'Canvas tote', quantity: 1, linePrice: 24, currency: 'USD'}]}
}
]
}
]);
return html`<div
style="inline-size:100%;min-inline-size:0"
@chatty-add-to-cart=${add}
@chatty-view-cart=${event => {
const line = store
.getState()
.messages.flatMap(message => message.blocks ?? [])
.filter(block => block.type === 'cart-confirmation')
.at(-1).data.receipts[0];
store.setMessages([
...store.getState().messages,
{
id: `bag-${store.getState().messages.length}`,
senderType: 'bot',
text: `Your bag: ${line.title} × ${line.quantity} — ${new Intl.NumberFormat('en', {style: 'currency', currency: line.currency}).format(line.linePrice)}`
}
]);
}}
>
${patternShell({surface, store})}
</div>`;
}
export function StandardAdmin() {
return cartPattern('admin');
}Import / element
ChatbotProductsBlock
| Component / element | Import / file | Scope root |
|---|---|---|
ChatbotProductsBlock |
@assets/ |
.inbox- |
Anatomy
ChatbotProductsBlock
| Part | Element |
|---|---|
| 1 | Render lại ChatbotProductsMessage với isAdmin. |
| 2 | Nút Avada- khi có anchor. |
| 3 | Wrapper Avada- chứa SlideButton prev/ |
| 4 | Row cuộn Avada-. |
| 5 | Một ProductCard cho mỗi sản phẩm. |
Placement / order
ChatbotProductsBlock
| Context | Order |
|---|---|
| Block products trong inbox | Trả null khi không có sản phẩm; ngược lại cùng thứ tự carousel như Classic. |
Props
ChatbotProductsBlock
| Prop | Type | Values | Default | Notes |
|---|---|---|---|---|
block |
object | block?.products |
Bắt buộc | Danh sách sản phẩm của block |
vm |
object | isAdminViewer( |
Bắt buộc | Truyền isAdmin cho carousel |
Sizes
ChatbotProductsBlock
| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
|---|---|---|---|---|---|---|---|
| card | Theo nội dung | Info 10px 12px 12px | Info 10px | 14px | Theo Info; không đặt role ở wrapper | Ảnh là nút inset: 0 phủ cả ảnh |
Width 205px; flex: 0 0 205px |
| row | Theo card | — | 8px | — | — | — | Cuộn ngang, scroll-; ẩn scrollbar |
Tokens
ChatbotProductsBlock
| Part | Token | Light | Dark |
|---|---|---|---|
| Card | color; background; border |
#232323; rgba(255, 255, 255, 0.75); 1px #f2f2f2 | No Dark skin |
| Info | background- |
#ffffff | No Dark skin |
States
ChatbotProductsBlock
| State | Trigger | Visual change (values) | ARIA/attribute |
|---|---|---|---|
| Media focus- |
keyboard | Outline 2px var(, offset -3px. |
Native button |
| Media disabled | Không mở được chi tiết | Con trỏ mặc định. | disabled |
| Overlay hover / focus | pointer hoặc keyboard | Padding 6px 12px; chữ rộng tối đa 120px, opacity 1. | Native button |
| Thêm giỏ bị khoá | Hết hàng, admin hoặc đang busy | isAddToCartDisabled; nút disabled. |
disabled |
Behaviour
ChatbotProductsBlock
| Interaction | Result |
|---|---|
| Chọn ảnh | Mở chi tiết trong chat khi không disableProductDetail và không cần báo giá; ngược lại mở link ở tab mới. |
| Chọn tiêu đề | Link target="_blank" mở trang sản phẩm. |
| View similar | Gửi tin nhắn tìm sản phẩm tương tự; admin không kích hoạt. |
Copy
ChatbotProductsBlock
| String | i18n key | Where |
|---|---|---|
| Similar to | Similar to | Anchor, khi có findSimilar |
| View similar | View similar | Nút overlay trên ảnh card |
| Out of stock | Out of stock | Tooltip nút thêm giỏ |
Source
ChatbotProductsBlock
| File | Evidence |
|---|---|
| Block inbox | |
| Carousel và card | |
| Card style |
Do / Don't
Accessibility
| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
|---|---|---|---|---|
| Classic | Nút ảnh có aria- theo tên sản phẩm |
Nút native; focus ring theo States | Không có | Light 15.72:1Measured(#232323 / #ffffff = 15.72:1); Dark 13.20:1Measured(#ffffff / #303030 = 13.20:1) |
| AI Mode | Vùng link có role="button" và aria- |
tabIndex 0; Enter hoặc Space mở card |
Không có | Kế thừa color: inherit từ surface |
| Admin | Giống Classic | Nút ảnh native; nút thêm giỏ disabled | Không có | Light 15.72:1Measured(#232323 / #ffffff = 15.72:1) |