Element prototype là chuẩn để chatty-ui port theo.
Host giữ dữ liệu, dịch nhãn và xử lý event; preview chỉ dùng dữ liệu cục bộ.
On this page
Use when / Avoid
Dùng trong cuộc trò chuyện. Tránh nối trực tiếp element với API của shop.
Use instead
Component
Use when
MessageFrame
Implementation React đang chạy.
Element prototype
Consumer chuyển sang custom element.
Live preview
Standard
Standard
LightDarkDesktopMobile
Element prototype với token trung tính.
Show codechatty-message.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/message.js';
const message = {
id: 'answer',
senderType: 'bot',
senderName: 'Assistant',
text: 'Try the **canvas tote**. It is lightweight and reusable.',
status: 'sent',
createdAt: '2026-01-15T10:01:00Z',
};
export function Standard() {
return html`<chatty-message .message=${message} viewer-type="customer"></chatty-message>`;
}
Standard
LightDarkDesktopMobile
Standard: Admin viewer keeps customer messages on the leading side.
Show codechatty-message.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/admin.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/message.js';
const message = {
id: 'answer',
senderType: 'bot',
senderName: 'Assistant',
text: 'Try the **canvas tote**. It is lightweight and reusable.',
status: 'sent',
createdAt: '2026-01-15T10:01:00Z',
};
export function StandardAdmin() {
return html`<chatty-message
.message=${message}
viewer-type="agent"
self-types='["agent","bot"]'
></chatty-message>`;
}
Admin chỉ dùng trong inbox và chỉ light; admin-dark là N/A.
self-types nhận JSON array, hoặc gán .selfTypes; null dùng viewer-type. Inbox truyền ["agent", "bot"] để AI, Auto và agent cùng phía self; badge chỉ ghi nguồn gốc. Admin dùng tên sender cho cả nhãn và aria.
Gán property .store với getState() và subscribe(listener); thay mảng messages theo immutable update và giữ reference các message chưa đổi. .message, .prev, .next hỗ trợ row độc lập. Thread dùng ID để giữ node khi prepend; group chỉ đổi khi sender, thời gian hoặc layout đổi.
Registry mặc định nhận product, products, suggestions, cart-confirmation, loading và reasoning; tin chỉ có type lạ được ẩn. Products giữ shape {type:'products', data:{products, messageId}}, nằm trước text và chiếm cả cột ở AI Mode. Registry nhận tag string hoặc {tag, beforeText, wide}. Suggestions phát chatty-suggest để host gọi composer send(text); action Add to cart phát chatty-add-to-cart, host tự cập nhật store. Receipt dùng data.receipts (giữ đọc receipt hoặc receipts cũ) như React. .registry là registry riêng của consumer, map type sang tag tin cậy. .message.blocks giữ dữ liệu block; adapter product nhận title, price và image, rồi ghép product-card có sẵn.
Standard
LightDarkDesktopMobile
Product block adapter dùng cùng product-card, không tự dựng card mới.
Show codechatty-block-product.element.jsWrap code linesCopy
Mặc định meta là giờ locale, full datetime ở time/title; chỉ pending/failed có status đã dịch qua .strings. Peer run đầu có sender. layout=centered dành cho activity không có bubble.
Standard
LightDarkDesktopMobile
Activity row canh giữa: Agent joined.
Show codechatty-message.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/message.js';
const message = {
id: 'answer',
senderType: 'bot',
senderName: 'Assistant',
text: 'Try the **canvas tote**. It is lightweight and reusable.',
status: 'sent',
createdAt: '2026-01-15T10:01:00Z',
};
export function Centered() {
return html`<chatty-message
.message=${{
id: 'joined',
senderType: 'system',
layout: 'centered',
text: 'Agent joined',
createdAt: '2026-01-15T10:05:00Z',
}}
></chatty-message>`;
}