Key rules
- AI Mode: SurveyCard render
SurveyViewvới một radiogroup; sao 24px trong nút 40px desktop, 44px mobile. - Classic: SatisfactionSurveyForm render
SurveyView; sao 24px, nút 40px desktop, 44px mobile. - Cả hai surface chỉ có survey ở mức hội thoại; mã nguồn hiện không có phản hồi riêng cho từng câu trả lời.
- Host sở hữu persistence; Skip chỉ chuyển focus về composer khi host nhận.
On this page
Use when / Avoid
Dùng survey cuối chat để lấy một rating cho cả hội thoại. Phản hồi từng câu trả lời chưa có trong mã storefront hiện tại.
Use instead
| Component | Use when |
|---|---|
SurveyView |
Survey rating một lựa chọn kèm góp ý, Submit và Skip. |
SurveyRating |
Chỉ hàng chọn rating, dùng bên trong SurveyView. |
Entry points
| Surface | Owner |
|---|---|
| AI Mode | SurveyCard, render từ khối survey của ChatMessage |
| Classic | SurveyBlock gọi SatisfactionSurveyForm trong registry của widget |
Flow
| Surface | Step | Trigger | UI shown | Component | Copy + i18n key | Timing |
|---|---|---|---|---|---|---|
| AI Mode | Hiện survey | Khối survey trong thread | Card với tiêu đề, gợi ý, hàng rating | SurveyView | Choose stars to send | Caller render |
| AI Mode | Chọn rating | Click hoặc phím | Textarea góp ý xuất hiện | SurveyView | Feedback (optional) | Tức thì |
| AI Mode | Submit | Click Submit | Spinner trên Submit; đóng thì card chuyển sang lời cảm ơn, lỗi thì hiện alert | SurveyView | Submit | Caller async |
| AI Mode | Skip | Click Skip | Spinner trên Skip; host nhận thì card biến mất | SurveyView | Skip | Caller async |
| Classic | Submit | Click Submit | Spinner trên Submit; thành công thì chuyển sang lời cảm ơn | SurveyView | Submit | Caller async |
| Classic | Skip | Click Skip | Spinner trên Skip; thành công thì set skipped | SurveyView | Skip | Caller async |
Edge cases
| Surface | Case | Behaviour |
|---|---|---|
| AI Mode | Survey đã skip | SurveyCard trả về null |
| AI Mode | Survey của ticket | isTicketSurvey lấy rating và trạng thái từ surveyResult của khối |
| AI Mode | Định dạng emoji | emoji bật khi format là EMOJI, kèm renderEmoji |
| Classic | Người xem là admin | readOnly bật; submit và skip bị chặn |
| Classic | Chế độ preview | Submit và skip chỉ đổi state cục bộ, không gọi server |
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
Thread Standard dùng fixture cục bộ.
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 {createBlockRegistry} from '@avada/chatty-ui/behaviors/block-registry.js';
import '@avada/chatty-ui/elements/chatty-block-survey.js';
export function Standard({surface}) {
const registry = createBlockRegistry({survey: 'chatty-block-survey'});
const store = fixtureStore([
question,
{id: 'answer', senderType: 'bot', text: 'Your order is on its way.'},
{id: 'survey', senderType: 'bot', blocks: [{type: 'survey', data: {}}]}
]);
let failed = false;
const save = (event, skip = false) => {
const survey = event.composedPath().find(node => node.localName === 'chatty-survey');
const composer = event.currentTarget.querySelector('chatty-composer');
survey.busy = skip ? 'skip' : 'submit';
const finish = async () => {
if (skip) {
store.setMessages(store.getState().messages.filter(m => m.id !== 'survey'));
await composer.updateComplete;
composer.shadowRoot.querySelector('textarea').focus();
} else if (!failed) {
failed = true;
survey.busy = '';
survey.error = true;
await survey.updateComplete;
const alert = survey.shadowRoot.querySelector('[role=alert]');
alert.tabIndex = -1;
alert.focus();
} else {
survey.error = false;
survey.busy = '';
survey.submitted = true;
await survey.updateComplete;
const status = survey.shadowRoot.querySelector('[role=status]');
status.tabIndex = -1;
status.focus();
}
};
if (matchMedia('(prefers-reduced-motion: reduce)').matches) finish();
else setTimeout(finish, 450);
};
return html`<div
style="inline-size:100%;min-inline-size:0"
@chatty-submit=${event => save(event)}
@chatty-skip=${event => save(event, true)}
>
${patternShell({surface, store, registry})}
</div>`;
}Survey nằm trong tin bot qua registry opt-in. Submit lần đầu trả lỗi fixture; Submit lần hai thành công. Skip dùng request fixture thành công. History và restored rating: N/A trong preview.
Current
AI Mode
SurveyView thật theo CSS AI Mode; dữ liệu và callback chỉ ở mẫu, không lưu gì.
Show code
import React, {useState} from 'react';
import {SurveyView} from '@avada/chatty-ui/primitives/SurveyView.jsx';
export function Survey() {
const [rating, setRating] = useState(0);
const [comment, setComment] = useState('');
const [submitted, setSubmitted] = useState(false);
const [skipped, setSkipped] = useState(false);
if (skipped) return <p role="status">Survey skipped locally.</p>;
return (
<SurveyView
title="How was your experience?"
thanks="Thank you for your feedback."
translate={(text, values) => text.replace('{{rating}}', values?.rating ?? '')}
ratings={[1, 2, 3, 4, 5].map(id => ({id}))}
rating={rating}
onRatingChange={setRating}
comment={comment}
onCommentChange={setComment}
onSubmit={() => setSubmitted(true)}
onSkip={() => {setSkipped(true); return true;}}
submitted={submitted}
announce
/>
);
}Import / element
SurveyView
| Component / element | Import / file | Scope root |
|---|---|---|
SurveyView |
@avada/ |
.chatty- |
SurveyRating
| Component / element | Import / file | Scope root |
|---|---|---|
SurveyRating |
@avada/ |
.chatty- |
Anatomy
SurveyView
| Part | Element |
|---|---|
| 1 | h3 tiêu đề; sau khi gửi thay bằng khối cảm ơn. |
| 2 | p gợi ý Choose stars to send, ẩn khi đã gửi hoặc readOnly. |
| 3 | SurveyRating một hàng sao hoặc emoji. |
| 4 | label + textarea góp ý, chỉ hiện khi đã chọn rating. |
| 5 | Khối lỗi có role="alert". |
| 6 | Hai button: Submit và Skip. |
SurveyRating
| Part | Element |
|---|---|
| 1 | Container radiogroup; ở chế độ readOnly là img có aria-. |
| 2 | buttonrole="radio" cho mỗi rating. |
| 3 | span trang trí aria-: svg ngôi sao hoặc emoji. |
Placement / order
SurveyView
| Context | Order |
|---|---|
| Chưa gửi | Tiêu đề, gợi ý, rating, góp ý (khi có rating), lỗi (khi error), rồi Submit và Skip. |
| Đã gửi | Khối cảm ơn thay tiêu đề; gợi ý, góp ý và hai nút không render. |
SurveyRating
| Context | Order |
|---|---|
| Trong SurveyView | Đứng giữa gợi ý và ô góp ý, nhận labelledBy và describedBy từ tiêu đề và gợi ý. |
Props
SurveyView
| Prop | Type | Values | Default | Notes |
|---|---|---|---|---|
rating |
number | Rating đang chọn | Caller | Truyền xuống SurveyRating làm value. |
onSubmit |
Function | Callback của host | Caller | Host sở hữu persistence và chuyển trạng thái sau khi nhận. |
onSkip |
Function | Trả về truthy khi host nhận Skip | Caller | Chỉ khi truthy mới đưa focus về ô nhập của composer. |
busyAction |
string | submit hoặc skip | Không có | Khoá toàn bộ control; chỉ nút vừa bấm có aria- true. |
error |
boolean | true hoặc false | Không có | Hiện khối lỗi role="alert" phía trên hai nút. |
submitted |
boolean | true hoặc false | Không có | Chuyển sang khối cảm ơn. |
announce |
boolean | true hoặc false | Không có | Chỉ khi submitted và announce mới đặt role status. |
readOnly |
boolean | true hoặc false | Không có | Khoá control và ẩn hint, góp ý, hai nút. |
emoji |
boolean | true hoặc false | Không có | Chọn emoji thay sao; cần ratings và renderEmoji. |
SurveyRating
| Prop | Type | Values | Default | Notes |
|---|---|---|---|---|
ratings |
Object[] | Mỗi phần tử có id |
Bắt buộc | Số phần tử quyết định số sao hoặc emoji. |
value |
number | id đang chọn | 0 | Sao có id nhỏ hơn hoặc bằng giá trị được tô. |
onChange |
Function | Nhận id mới | Bắt buộc | Gọi khi click hoặc phím. |
readOnly |
boolean | true hoặc false | Không có | Render img và span thay cho nút. |
disabled |
boolean | true hoặc false | Không có | Khoá phím, hover preview và nút. |
Sizes
SurveyView
| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
|---|---|---|---|---|---|---|---|
| Card | Theo nội dung | 16px | 0 | 20px | Tiêu đề heading- |
Không tương tác | width 100%, max- |
| Action button | -: 40px desktop → 44px mobile |
0 12px; Submit thêm padding- |
6px trong nút; 8px giữa hai nút | 999px | button- |
40px desktop → 44px mobile | Mobile mixin khi có class mobile của surface hoặc max- |
| Comment textarea | -: 88px desktop → 96px mobile |
12px | 4px giữa nhãn và ô | 10px | input- |
Theo textarea | Mobile mixin như trên |
SurveyRating
| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
|---|---|---|---|---|---|---|---|
| Rating button | -: 40px desktop → 44px mobile |
0 | 4px giữa các nút | 8px | Không có chữ | 40px desktop → 44px mobile | Mobile mixin khi có class mobile của surface hoặc max- |
| Star art | 24px × 24px | Không có | Không có | Không có | Không có chữ | Nằm trong nút | Cùng kích thước ở mọi breakpoint |
Tokens
SurveyView
| Part | Token | Light | Dark |
|---|---|---|---|
| Card surface | - |
-: rgba(20, 19, 24, 0.04) dưới 900px; rgba(255, 255, 255, 0.42) từ 900px |
rgba(255, 255, 255, 0.06) |
| Card border | - |
-: rgba(20, 19, 24, 0.08) |
rgba(255, 255, 255, 0.12) |
| Text | - |
-: rgba(20, 19, 24, 0.94) |
rgba(255, 255, 255, 0.96) |
| Hint | - |
-: rgba(20, 19, 24, 0.74) |
rgba(255, 255, 255, 0.74) |
| Submit fill | - |
-: merchant -, fallback #8b7be8 |
Cùng định nghĩa |
| Submit text | - |
-: merchant -, fallback #fff |
Cùng định nghĩa |
| Error | - |
#c5280c | color- |
SurveyRating
| Part | Token | Light | Dark |
|---|---|---|---|
| Star active | - |
#b77900 | #f5c542 |
| Star outline | - |
-: rgba(20, 19, 24, 0.74) |
Fallback -: #aaa |
| Focus ring | - |
-: rgba(20, 19, 24, 0.94) |
rgba(255, 255, 255, 0.96) |
States
SurveyView
| State | Trigger | Visual change (values) | ARIA/attribute |
|---|---|---|---|
| Submit disabled | !rating hoặc đang busy |
Nền -, chữ - |
disabled |
| Submit busy | busyAction là submit |
Spinner 16px, viền 2px, 0.8s linear infinite | aria- true |
| Skip busy | busyAction là skip |
Spinner 16px cạnh nhãn Skip | aria- true |
| Skip hover / active | pointer | Nền color- |
Không thêm ARIA |
| Focus- |
keyboard | outline 2px solid -, offset 2px |
Native focus |
| Error | error true |
Chữ -, icon cạnh nội dung |
role="alert" |
| Submitted | submitted true |
Khối cảm ơn, rating chỉ đọc | role status khi announce |
| Reduced motion | prefers- |
Spinner animation: none |
Không thêm ARIA |
SurveyRating
| State | Trigger | Visual change (values) | ARIA/attribute |
|---|---|---|---|
| Hover | pointer, không disabled | Nền color- |
Không thêm ARIA |
| Active | pointer down | Nền color- |
Không thêm ARIA |
| Checked | rating.id === value |
Sao có id nhỏ hơn hoặc bằng giá trị đổi sang fill currentColor |
aria- |
| Disabled | disabled |
opacity: 1, con trỏ mặc định |
disabled |
| Focus- |
keyboard | outline 2px solid -, offset 2px |
Native focus |
Behaviour
SurveyView
| Interaction | Result |
|---|---|
| Skip | Gọi onSkip; nếu kết quả truthy, focus chuyển tới ô nhập của composer trong surface. |
| Góp ý | Textarea hiện sau khi có rating, giới hạn 250 ký tự. |
| Submit không có rating | Nút disabled và mô tả bởi gợi ý. |
| Host | Host sở hữu persistence và bước chuyển sau submit hoặc skip. |
SurveyRating
| Interaction | Result |
|---|---|
| Phím mũi tên | Phải hoặc xuống chọn rating kế tiếp, trái hoặc lên chọn rating trước, vòng tròn ở hai đầu. |
| Space và Enter | Chọn rating của nút đang focus. |
| Tab stop | Một tab stop: nút đang chọn, hoặc nút đầu khi chưa chọn. |
| Hover | Chỉ xem trước; không đổi giá trị đã chọn. |
Copy
SurveyView
| String | i18n key | Where |
|---|---|---|
| Choose stars to send | Choose stars to send | Gợi ý dưới tiêu đề, qua translate |
| Rate your experience | Rate your experience | Nhãn tóm tắt khi chưa có rating |
| Feedback (optional) | Feedback (optional) | Nhãn textarea |
| Tell us about your experience | Tell us about your experience | Placeholder textarea |
| Something went wrong. Please try again. | Something went wrong. Please try again. | Khối lỗi |
| Submit | Submit | Nhãn nút gửi |
| Skip | Skip | Nhãn nút bỏ qua |
| Tiêu đề và lời cảm ơn | Do host truyền | Props title và thanks |
SurveyRating
| String | i18n key | Where |
|---|---|---|
| Rate {{rating}} out of 5 | Rate {{rating}} out of 5 | aria- của mỗi nút |
Source
SurveyView
| File | Evidence |
|---|---|
| API và markup | |
| Kích thước, trạng thái, mobile mixin | |
| Type role |
SurveyRating
| File | Evidence |
|---|---|
| API và markup | |
| Kích thước, trạng thái |
Classic
SurveyView thật trong popup Classic; dữ liệu và callback chỉ ở mẫu.
Show code
import React, {useState} from 'react';
import {SurveyView} from '@avada/chatty-ui/primitives/SurveyView.jsx';
export function Survey() {
const [rating, setRating] = useState(0);
const [comment, setComment] = useState('');
const [submitted, setSubmitted] = useState(false);
const [skipped, setSkipped] = useState(false);
if (skipped) return <p role="status">Survey skipped locally.</p>;
return (
<SurveyView
title="How was your experience?"
thanks="Thank you for your feedback."
translate={(text, values) => text.replace('{{rating}}', values?.rating ?? '')}
ratings={[1, 2, 3, 4, 5].map(id => ({id}))}
rating={rating}
onRatingChange={setRating}
comment={comment}
onCommentChange={setComment}
onSubmit={() => setSubmitted(true)}
onSkip={() => {setSkipped(true); return true;}}
submitted={submitted}
announce
/>
);
}Import / element
SurveyView
| Component / element | Import / file | Scope root |
|---|---|---|
SurveyView |
@avada/ |
.Avada- |
SurveyRating
| Component / element | Import / file | Scope root |
|---|---|---|
SurveyRating |
@avada/ |
.Avada- |
Anatomy
SurveyView
| Part | Element |
|---|---|
| 1 | h3 tiêu đề; sau khi gửi thay bằng khối cảm ơn. |
| 2 | p gợi ý Choose stars to send, ẩn khi đã gửi hoặc readOnly. |
| 3 | SurveyRating một hàng sao hoặc emoji. |
| 4 | label + textarea góp ý, chỉ hiện khi đã chọn rating. |
| 5 | Khối lỗi có role="alert". |
| 6 | Hai button: Submit và Skip. |
SurveyRating
| Part | Element |
|---|---|
| 1 | Container radiogroup; ở chế độ readOnly là img có aria-. |
| 2 | buttonrole="radio" cho mỗi rating. |
| 3 | span trang trí aria-: svg ngôi sao hoặc emoji. |
Placement / order
SurveyView
| Context | Order |
|---|---|
| Chưa gửi | Tiêu đề, gợi ý, rating, góp ý (khi có rating), lỗi (khi error), rồi Submit và Skip. |
| Đã gửi | Khối cảm ơn thay tiêu đề; gợi ý, góp ý và hai nút không render. |
SurveyRating
| Context | Order |
|---|---|
| Trong SurveyView | Đứng giữa gợi ý và ô góp ý, nhận labelledBy và describedBy từ tiêu đề và gợi ý. |
Props
SurveyView
| Prop | Type | Values | Default | Notes |
|---|---|---|---|---|
rating |
number | Rating đang chọn | Caller | Truyền xuống SurveyRating làm value. |
onSubmit |
Function | Callback của host | Caller | Host sở hữu persistence và chuyển trạng thái sau khi nhận. |
onSkip |
Function | Trả về truthy khi host nhận Skip | Caller | Chỉ khi truthy mới đưa focus về ô nhập của composer. |
busyAction |
string | submit hoặc skip | Không có | Khoá toàn bộ control; chỉ nút vừa bấm có aria- true. |
error |
boolean | true hoặc false | Không có | Hiện khối lỗi role="alert" phía trên hai nút. |
submitted |
boolean | true hoặc false | Không có | Chuyển sang khối cảm ơn. |
announce |
boolean | true hoặc false | Không có | Chỉ khi submitted và announce mới đặt role status. |
readOnly |
boolean | true hoặc false | Không có | Khoá control và ẩn hint, góp ý, hai nút. |
emoji |
boolean | true hoặc false | Không có | Chọn emoji thay sao; cần ratings và renderEmoji. |
SurveyRating
| Prop | Type | Values | Default | Notes |
|---|---|---|---|---|
ratings |
Object[] | Mỗi phần tử có id |
Bắt buộc | Số phần tử quyết định số sao hoặc emoji. |
value |
number | id đang chọn | 0 | Sao có id nhỏ hơn hoặc bằng giá trị được tô. |
onChange |
Function | Nhận id mới | Bắt buộc | Gọi khi click hoặc phím. |
readOnly |
boolean | true hoặc false | Không có | Render img và span thay cho nút. |
disabled |
boolean | true hoặc false | Không có | Khoá phím, hover preview và nút. |
Sizes
SurveyView
| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
|---|---|---|---|---|---|---|---|
| Card | Theo nội dung | 16px | 0 | 20px | Tiêu đề heading- |
Không tương tác | width 100%, max- |
| Action button | -: 40px desktop → 44px mobile |
0 12px; Submit thêm padding- |
6px trong nút; 8px giữa hai nút | 999px | button- |
40px desktop → 44px mobile | Mobile mixin khi có class mobile của surface hoặc max- |
| Comment textarea | -: 88px desktop → 96px mobile |
12px | 4px giữa nhãn và ô | 10px | input- |
Theo textarea | Mobile mixin như trên |
SurveyRating
| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
|---|---|---|---|---|---|---|---|
| Rating button | -: 40px desktop → 44px mobile |
0 | 4px giữa các nút | 8px | Không có chữ | 40px desktop → 44px mobile | Mobile mixin khi có class mobile của surface hoặc max- |
| Star art | 24px × 24px | Không có | Không có | Không có | Không có chữ | Nằm trong nút | Cùng kích thước ở mọi breakpoint |
Tokens
SurveyView
| Part | Token | Light | Dark |
|---|---|---|---|
| Card border | - |
#e3e3e3 | #ffffff17 |
| Card surface | - |
#fff | #1a1a1a |
| Text | - |
#303030 | #eee |
| Hint | - |
#616161 | #aaa |
| Submit fill | - |
-, fallback - (#303030) |
Fallback #eee |
| Submit text | - |
-, fallback - (#fff) |
Fallback #1a1a1a |
| Submit disabled | - |
#f7f7f7 | #282828 |
| Error | - |
#c5280c | #ff9a8a |
SurveyRating
| Part | Token | Light | Dark |
|---|---|---|---|
| Star active | - |
#b77900 | #f5c542 |
| Star outline | - |
#8a8a8a | #aaa |
| Focus ring | - |
#303030 | #eee |
States
SurveyView
| State | Trigger | Visual change (values) | ARIA/attribute |
|---|---|---|---|
| Submit disabled | !rating hoặc đang busy |
Nền -, chữ - |
disabled |
| Submit busy | busyAction là submit |
Spinner 16px, viền 2px, 0.8s linear infinite | aria- true |
| Skip busy | busyAction là skip |
Spinner 16px cạnh nhãn Skip | aria- true |
| Skip hover / active | pointer | Nền color- |
Không thêm ARIA |
| Focus- |
keyboard | outline 2px solid -, offset 2px |
Native focus |
| Error | error true |
Chữ -, icon cạnh nội dung |
role="alert" |
| Submitted | submitted true |
Khối cảm ơn, rating chỉ đọc | role status khi announce |
| Reduced motion | prefers- |
Spinner animation: none |
Không thêm ARIA |
SurveyRating
| State | Trigger | Visual change (values) | ARIA/attribute |
|---|---|---|---|
| Hover | pointer, không disabled | Nền color- |
Không thêm ARIA |
| Active | pointer down | Nền color- |
Không thêm ARIA |
| Checked | rating.id === value |
Sao có id nhỏ hơn hoặc bằng giá trị đổi sang fill currentColor |
aria- |
| Disabled | disabled |
opacity: 1, con trỏ mặc định |
disabled |
| Focus- |
keyboard | outline 2px solid -, offset 2px |
Native focus |
Behaviour
SurveyView
| Interaction | Result |
|---|---|
| Skip | Gọi onSkip; nếu kết quả truthy, focus chuyển tới ô nhập của composer trong surface. |
| Góp ý | Textarea hiện sau khi có rating, giới hạn 250 ký tự. |
| Submit không có rating | Nút disabled và mô tả bởi gợi ý. |
| Host | Host sở hữu persistence và bước chuyển sau submit hoặc skip. |
SurveyRating
| Interaction | Result |
|---|---|
| Phím mũi tên | Phải hoặc xuống chọn rating kế tiếp, trái hoặc lên chọn rating trước, vòng tròn ở hai đầu. |
| Space và Enter | Chọn rating của nút đang focus. |
| Tab stop | Một tab stop: nút đang chọn, hoặc nút đầu khi chưa chọn. |
| Hover | Chỉ xem trước; không đổi giá trị đã chọn. |
Copy
SurveyView
| String | i18n key | Where |
|---|---|---|
| Choose stars to send | Choose stars to send | Gợi ý dưới tiêu đề, qua translate |
| Rate your experience | Rate your experience | Nhãn tóm tắt khi chưa có rating |
| Feedback (optional) | Feedback (optional) | Nhãn textarea |
| Tell us about your experience | Tell us about your experience | Placeholder textarea |
| Something went wrong. Please try again. | Something went wrong. Please try again. | Khối lỗi |
| Submit | Submit | Nhãn nút gửi |
| Skip | Skip | Nhãn nút bỏ qua |
| Tiêu đề và lời cảm ơn | Do host truyền | Props title và thanks |
SurveyRating
| String | i18n key | Where |
|---|---|---|
| Rate {{rating}} out of 5 | Rate {{rating}} out of 5 | aria- của mỗi nút |
Source
SurveyView
| File | Evidence |
|---|---|
| API và markup | |
| Kích thước, trạng thái, mobile mixin | |
| Type role |
SurveyRating
| File | Evidence |
|---|---|
| API và markup | |
| Kích thước, trạng thái |
Do / Don't
Accessibility
| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
|---|---|---|---|---|
| AI Mode | radiogroup tên từ tiêu đề; mỗi sao là role="radio" có aria- Rate n out of 5 |
Một tab stop; mũi tên đổi lựa chọn; focus ring outline 2px solid, offset 2px; sau Skip focus về ô nhập composer | role status khi announce sau submit; lỗi dùng role="alert" |
Không đo: nền và chữ dùng rgba trong suốt |
| Classic | radiogroup tên từ tiêu đề; mỗi sao là role="radio" có aria- Rate n out of 5 |
Một tab stop; mũi tên đổi lựa chọn; focus ring outline 2px solid, offset 2px; sau Skip focus về ô nhập composer | role status khi announce sau submit; lỗi dùng role="alert" |
13.2:1Measured(#303030 / #ffffff = 13.2:1) light; 15:1Measured(#eeeeee / #1a1a1a = 15:1) dark |