Key rules
- Prototype element trong guide (
chatty-ui/src/) là chuẩn; chatty-ui port 1:1, code lệch thì sửa theo guide. - Tag
chatty-<danh từ>; 1 element là 1 subpath import, và import là define element. - Mặc định open shadow root; light DOM chỉ dùng cho 3 trường hợp ở bảng Shadow and light DOM.
- Theme đi qua 3 tầng theo thứ tự: token toàn cục, tham số
--chatty-<element>-*, rồi::part(). - Admin: Target Inbox dùng thuần chatty-ui; 4 phần embedded App Bridge giữ app nav, contextual save bar, toast và modal max.
On this page
Principle
chatty-ui sẽ thành thư viện Web Component chatty-* dùng chung cho storefront Classic, AI Mode, guide này và inbox của admin. Một element chạy được trong Preact của storefront lẫn React 18 của admin, nên không phải giữ hai bộ component song song. Công cụ là Lit 3 cùng base class ChattyElement (). State và logic ở chat-core hoặc module JS thuần; element chỉ hiển thị.
CSS custom property là API công khai của thư viện: merchant, consumer và guide đều chỉnh giao diện qua token, tham số của element và ::part(), không qua class bên trong. Đây là thay đổi phá vỡ cho customCss hiện có, nên mỗi đợt storefront migrate customCss của từng shop trước khi bật.
Các trang admin khác inbox (AI Assistant, Settings, Analytics, Home, Integrations, Subscription) giữ Polaris React. Lý do: Shopify yêu cầu app trong admin có giao diện giống admin, và Polaris là cách chắc nhất để đạt điều đó. Target Inbox dùng chatty-ui với token literal light/dark theo giá trị 2.0; source còn wrapper var(--p-*), phase 1b chưa ship. Giữ nút chính đen/trắng theo BFS 4.1.1; màu brand sẽ không đạt điều kiện đó.
Prototype trong chatty-ui/src/ của guide là chuẩn: cùng cấu trúc thư mục với , Lit 3, chỉ import lit và file nội bộ, JSDoc đủ @slot, @csspart, @cssprop, @fires. custom-elements.json sinh từ chính prototype; mục Standard của trang component phải khớp manifest. Surface nào đã dùng element thật thì ghi ở bảng Adoption của trang component.
Rule details
Naming and API
| Aspect | Convention | Example |
|---|---|---|
| Tag | chatty-<danh từ>, gạch nối |
chatty-, chatty-, chatty-, chatty- + chatty- + chatty- |
| Attribute | kebab- |
variant, size, tone, open, disabled |
| Property | camelCase; dữ liệu phức tạp chỉ qua property | .message, .product, .store, .strings |
| Vocabulary | variant primary / secondary / tertiary / plain; tone neutral / critical / success / caution; size sm / md / lg |
size="default" là alias của md |
| Event | Hành vi native giữ tên native; event riêng là chatty-<động từ>; luôn bubbles + composed; kiểu detail ghi bằng JSDoc @fires |
click, input, change, toggle; chatty-, chatty-, chatty- |
| Slot | default, start, end, icon, label, help, cộng slot riêng của element |
header, footer, actions |
| Part | base, label, control, icon, start, end, panel; đã public thì không đổi tên |
::part( |
| CSS custom property | Token toàn cục -; tham số element - |
-, - |
| Import | 1 subpath mỗi element, import là define; storefront không có barrel define- |
@avada/ (dự kiến) |
| Docs in code | JSDoc @slot, @csspart, @cssprop, @fires trên class; analyzer sinh custom- |
@cssprop - |
Shadow and light DOM
| Case | Approach | Why |
|---|---|---|
| Mặc định | Open shadow root | Test, dev SDK và customCss của merchant vẫn với vào được |
| Nội dung cần index, chọn chữ, dịch trang (câu trả lời FAQ, trang FAQ) | Text đi qua slot từ light DOM; element chỉ lo khung | SEO và công cụ dịch đọc DOM thường; không dựa vào việc Google render shadow DOM |
| Input cần autofill hoặc password manager (email, số điện thoại) | Input trong shadow; nếu QA thấy autofill hỏng thì cho phép <input slot="input"> ở light DOM |
Autofill trong shadow root chưa đồng đều giữa trình duyệt, chưa đo |
| Quan hệ ARIA bằng ID (tabs và panel, combobox và listbox) | Các phần là con light DOM của element cha, cùng tree scope | ID ref không đi xuyên shadow root |
| Bố cục thuần (stack, box) | Không làm element; dùng CSS và token | Element bọc layout thêm tầng mà không cô lập được gì |
Theming
| Layer | API | Example |
|---|---|---|
| 1. Global token | Semantic token đọc từ tổ tiên bất kỳ | - |
| 2. Element parameter | -, khai báo bằng @cssprop |
- |
| 3. Part | ::part( cho trường hợp đặc biệt |
chatty- |
Merchant customCss |
Inject vào shadow root của surface, chỉ có hiệu lực qua 3 tầng trên | Host giữ id và class cũ ở light DOM cho rule vị trí và ẩn hiện |
Tokens
| Layer | Name pattern | Declared on | Example |
|---|---|---|---|
| Semantic | Tên do mixin foundations. và type. sinh: -, type role, -, -; radius - |
Light trên :root,; Dark dưới [data- |
-, -, -, - |
| Component | - |
Element static styles |
chatty- có đúng 6: -, -, -, -, -, - |
| Merchant brand | - map sang semantic token 1 lần ở gốc surface; element chỉ đọc semantic token |
Gốc surface | - → - |
| Admin (inbox) | Code hiện tại: output admin của mixin còn wrapper Polaris; Target Inbox phase 1b dùng literal token chatty- |
Gốc inbox | Current wrapper, không dùng làm hướng dẫn cho Inbox mới; xem Target |
| Element | Không nạp file token vào shadow root của mình; chỉ đọc var( để Dark và màu merchant từ token chatty- |
— | background: var( |
@property |
Gom 1 file, base class chèn vào document 1 lần | Document | @property trong shadow root bị bỏ qua |
Form-associated
| Concern | Rule |
|---|---|
| Elements | chatty-, chatty-, chatty-, chatty-, chatty-, chatty- với type=submit hoặc reset |
| Value | static formAssociated + ElementInternals: setFormValue, setValidity với thông báo native |
| Lifecycle | formResetCallback, formDisabledCallback, formStateRestoreCallback |
| Test | jsdom không có attachInternals, nên test form chạy trong browser thật (Chromium và WebKit) |
Accessibility in shadow
| Concern | Rule |
|---|---|
| Role và trạng thái | Đặt ở host qua internals., internals.; trình duyệt chưa hỗ trợ thì set attribute trên host |
| Focus | Element tương tác bật delegatesFocus: true |
| Nhãn | Nhãn thuộc về chính element (label attribute hoặc slot label); không trỏ ID từ ngoài vào |
| Overlay | Dialog, popover, menu, tooltip dùng <dialog> hoặc Popover API trong top layer; trap, restore focus và Escape; không portal ra document. |
| Gate | axe- |
Internationalisation, RTL and light/dark
| Concern | Rule |
|---|---|
| Chuỗi | Element không giữ catalog dịch; chuỗi đi qua attribute hoặc property .strings, mặc định tiếng Anh; consumer truyền từ translationSettings |
| Ngày giờ và số | Intl với locale lấy từ lang của tổ tiên gần nhất |
| RTL | Logical property (margin-) và :host( |
| Light/ |
Token đổi theo [data- trên tổ tiên bất kỳ, kèm color-; element không có attribute theme riêng |
Preact and React 18
| Consumer | How | Note |
|---|---|---|
| Storefront (Preact) | Dùng tag trực tiếp; Preact đặt property khi prop in el; event viết onchatty- |
Không cần wrapper |
| Inbox (React 18) | Wrapper @lit/ sinh từ manifest |
Chỉ phục vụ inbox; bỏ khi admin lên React 19 |
| Type | jsx. cho React và Preact sinh từ manifest |
Tên attribute và event sai thì báo ở editor |
| Guide | Story src/stories/<tag>.element.js import prototype <name>.js, trả template lithtml; snippet là markup trong fence html |
lit lấy từ dependency của guide |
Surface
| Surface | Uses chatty-* |
Keeps | Why |
|---|---|---|---|
| Classic | Toàn bộ widget, theo từng đợt | Host giữ id và class cũ ở light DOM | customCss và script theme đang bám vào host |
| AI Mode | Toàn bộ widget, theo từng đợt | Host #chatty- và .chatty- ở light DOM |
Như Classic |
| Admin (inbox) | Target: mọi vùng Inbox dùng chatty- |
Chỉ embedded App Bridge: s- |
Giá trị 2.0 và nút chính đen/ |
| Admin (other pages) | Không | Polaris React | Shopify yêu cầu giao diện admin giống core admin |
| Guide | Story element và trang API sinh từ manifest | Brand và chrome của guide | Preview nằm trong iframe; chrome không cấp màu cho frame |
Live preview
Prototype chuẩn chatty-button: element render trong shadow root của frame với token chuẩn, không màu merchant.
Show code
import '@avada/chatty-ui/tokens/tokens.css';
// Standard: the chatty-button prototype chatty-ui ports from (chatty-ui/src/elements/button.js).
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/button.js';
export function Standard({surface}) {
const store = fixtureStore([
{id: 'transcript', senderType: 'bot', text: 'You can email this conversation to yourself.'}
]);
const content = html`
<form
aria-label="Email a transcript"
style="box-sizing:border-box;display:grid;gap:8px;width:100%;max-width:400px"
>
<label style="display:grid;gap:4px">
Email this transcript to
<input
class="Avada-Faq_Transcript-Email-Input"
aria-label="Email address"
type="email"
autocomplete="email"
value="you@example.com"
required
style="box-sizing:border-box;width:100%;min-height:40px;padding:8px 12px;border:1px solid var(--chatty-color-border);border-radius:8px;background:var(--chatty-color-bg-surface);color:inherit;font:inherit"
/>
</label>
<div style="display:flex;flex-wrap:wrap;gap:8px;align-items:center">
<chatty-button variant="primary">Send</chatty-button>
<chatty-button variant="secondary">Cancel</chatty-button>
</div>
</form>
<style>
:host([data-chatty-surface='ai-mode']) form {
--chatty-button-primary-bg: #303030;
--chatty-button-primary-hover: color-mix(in srgb, #303030 85%, black);
--chatty-button-primary-active: var(--chatty-button-primary-hover);
}
</style>
`;
// Keep public Code executable rather than extracting only the static form.
return html`${patternShell({surface, store, content})}`;
}Do / Don't
Target
Target: mẫu giá trị Inbox được duyệt; không phải implementation production.
Show code
import React from 'react';
const radii = {"container": "20px", "dialog": "20px", "popover": "12px", "control": "10px", "element": "8px", "tag": "6px", "checkbox": "4px", "avatar": "clamp(6px, 30%, 12px)", "action": "9999px", "chat-control": ".5rem", "option-item": ".5rem", "kbd": ".25rem"};
const themes = {"light": {"--chatty-color-bg": "#fff", "--chatty-color-bg-fill-caution-secondary": "oklch(.9167 .1785 98.00)", "--chatty-color-bg-fill-critical": "oklch(.9470 .0300 20.50)", "--chatty-color-bg-fill-info-secondary": "oklch(.8637 .1018 216.95)", "--chatty-color-bg-fill-inverse": "#1b1b1b", "--chatty-color-bg-fill-secondary": "#ebebeb", "--chatty-color-bg-fill-success": "oklch(.9672 .0599 131.73)", "--chatty-color-bg-fill-success-secondary": "oklch(.9053 .1942 133.49)", "--chatty-color-bg-fill-tertiary": "#ddd", "--chatty-color-bg-fill-tertiary-hover": "#d0d0d0", "--chatty-color-bg-surface": "#fff", "--chatty-color-bg-surface-critical": "oklch(.9470 .0300 20.50)", "--chatty-color-bg-surface-secondary": "#f7f7f7", "--chatty-color-bg-surface-secondary-selected": "#ebebeb", "--chatty-color-bg-surface-success": "oklch(.9672 .0599 131.73)", "--chatty-color-bg-surface-tertiary": "#f2f2f2", "--chatty-color-bg-surface-warning": "oklch(.9557 .0350 67.45)", "--chatty-color-border": "rgba(221,221,221,1)", "--chatty-color-border-secondary": "rgba(242,242,242,1)", "--chatty-color-border-tertiary": "rgba(192,192,192,1)", "--chatty-color-border-warning": "oklch(.9316 .0545 67.18)", "--chatty-color-icon-secondary": "#606060", "--chatty-color-text": "#101010", "--chatty-color-text-brand-on-accent": "#fff", "--chatty-color-text-caution": "oklch(.2708 .0638 90.28)", "--chatty-color-text-critical": "oklch(.2121 .0942 30.90)", "--chatty-color-text-info": "oklch(.2715 .0576 221.37)", "--chatty-color-text-link": "oklch(.4840 .2413 262.80)", "--chatty-color-text-link-inverse": "oklch(.7340 .1449 264.63)", "--chatty-color-text-on-accent": "#fff", "--chatty-color-text-secondary": "rgba(74,74,74,1)", "--chatty-color-text-success": "oklch(.2334 .0796 134.14)", "--chatty-color-text-warning": "oklch(.2475 .0726 51.49)"}, "dark": {"--chatty-color-bg": "#121212", "--chatty-color-bg-fill-caution-secondary": "#4f4700", "--chatty-color-bg-fill-critical": "#2f040b", "--chatty-color-bg-fill-info-secondary": "#003a5a", "--chatty-color-bg-fill-inverse": "#303030", "--chatty-color-bg-fill-secondary": "#373737", "--chatty-color-bg-fill-success": "#014b40", "--chatty-color-bg-fill-success-secondary": "#014b40", "--chatty-color-bg-fill-tertiary": "#414141", "--chatty-color-bg-fill-tertiary-hover": "#585858", "--chatty-color-bg-surface": "#1a1a1a", "--chatty-color-bg-surface-critical": "#5f0716", "--chatty-color-bg-surface-secondary": "#282828", "--chatty-color-bg-surface-secondary-selected": "#373737", "--chatty-color-bg-surface-success": "#073630", "--chatty-color-bg-surface-tertiary": "#2f2f2f", "--chatty-color-bg-surface-warning": "#412d00", "--chatty-color-border": "#ffffff17", "--chatty-color-border-secondary": "#ffffff0f", "--chatty-color-border-tertiary": "#ffffff2e", "--chatty-color-border-warning": "#956f00", "--chatty-color-icon-secondary": "#aaa", "--chatty-color-text": "#eee", "--chatty-color-text-brand-on-accent": "#121212", "--chatty-color-text-caution": "#ffeb78", "--chatty-color-text-critical": "#f78086", "--chatty-color-text-info": "#a8d8ff", "--chatty-color-text-link": "#c5d0ff", "--chatty-color-text-link-inverse": "#c5d0ff", "--chatty-color-text-on-accent": "#121212", "--chatty-color-text-secondary": "#aaa", "--chatty-color-text-success": "#2ced83", "--chatty-color-text-warning": "#ffc879"}};
const frameStyle = {
...themes.light,
...Object.fromEntries(Object.entries(radii).map(([role,value])=>['--chatty-radius-'+role,value])),
'--chatty-type-family':'ShopifyInter, ui-sans-serif, system-ui, sans-serif',
'--chatty-type-weight-regular':400,'--chatty-type-weight-medium':500,'--chatty-type-weight-semibold':600,
'--chatty-type-body-medium-size':'13px','--chatty-type-body-medium-line':'20px',
'--chatty-type-button-label-size':'12px','--chatty-type-button-label-line':'16px',
'--chatty-type-badge-label-size':'12px','--chatty-type-badge-label-line':'18px',
fontFamily:'var(--chatty-type-family)',fontSize:'var(--chatty-type-body-medium-size)',lineHeight:'var(--chatty-type-body-medium-line)',fontWeight:'var(--chatty-type-weight-regular)',
color:'var(--chatty-color-text)',background:'var(--chatty-color-bg-surface)',padding:16
};
const box = {border:'1px solid #888',background:'#f7f7f7',padding:12,color:'#101010',font:'inherit'};
function Target({children}) { return <div data-inbox-target style={frameStyle}><link rel="stylesheet" href="https://cdn.shopify.com/static/fonts/shopifyinter/v0/styles.css"/><p style={{marginTop:0}}>Target · design fixture · phase 1b chưa ship</p>{children}</div>; }
function RadiusSample({role,value}) {
const style={...box,borderRadius:`var(--chatty-radius-${role})`};
if(role==='checkbox')return <input aria-label="Checkbox radius sample" type="checkbox" style={{...style,appearance:'none',width:24,height:24,padding:0}}/>;
if(role==='avatar')return <span role="img" aria-label="Avatar initials" style={{...style,width:36,height:36,padding:0,display:'grid',placeItems:'center'}}>AB</span>;
if(role==='tag')return <span style={{...style,padding:'0 8px',display:'inline-block'}}>Status</span>;
if(role==='kbd')return <kbd style={{...style,padding:'0 6px'}}>A</kbd>;
if(['action','control','chat-control','option-item'].includes(role))return <button type="button" style={style}>Action</button>;
if(role==='dialog')return <dialog open aria-label="Dialog radius sample" style={{...style,position:'static',margin:0}}>Dialog</dialog>;
return <section aria-label={`${role} radius sample`} style={style}>{role}</section>;
}
export function Scope() {
return <Target><div style={{display:'grid',gap:12}}><section style={{...box,borderRadius:'var(--chatty-radius-container)'}}><strong style={{fontWeight:'var(--chatty-type-weight-semibold)'}}>Inbox · standalone + embedded</strong><p>chatty-ui Button · Badge · Avatar · Popover/Menu · Select · Tag input · Banner · TextField · picker · Tooltip</p><p>Token chatty-ui literal light/dark, weight400/500/600, radius theo vai; nguồn giá trị 2.0. Phase 1b gỡ lớp var(--p-*) trước khi chuyển component.</p></section><aside style={{...box,borderRadius:'var(--chatty-radius-popover)'}}><strong style={{fontWeight:'var(--chatty-type-weight-semibold)'}}>Shopify vẽ · embedded App Bridge</strong><p>s-app-nav · contextual save bar · toast · modal max</p></aside><p>Icon giữ quy tắc hiện hành: commerce, filter/sort dùng path Polaris; không cần component Polaris.</p></div></Target>;
}