On this page

chatty-survey

API chuẩn của element chatty-survey, sinh từ custom-elements.json của prototype trong guide.

Copy page as MarkdownRead Markdown ↗

Key rules

  • chatty-survey khai báo 6 attribute, 1 property không có attribute, 2 event, 4 slot, 5 part và 2 CSS custom property.
  • Import 1 module @avada/chatty-ui/elements/survey.js là define chatty-survey; chunk chỉ import element nó dùng. Prototype chuẩn: trong guide.
  • Đổi tên attribute, event, slot, part hay CSS custom property là đổi API: diff của custom-elements.json phải có trong 1 MR.
On this page

Overview

Satisfaction survey: star rating, optional comment, Submit and Skip. The host owns persistence; it sets busy while saving and submitted once accepted. Class ChattySurvey.

Attributes

Name Property Type Default Description
value value number 0 Chosen star rating; 0 means none, which keeps Submit disabled.
comment comment string '' Optional comment, up to 250 characters.
busy busy '' | 'submit' | 'skip' '' Which action is saving; blocks both actions and shows a spinner on that one.
error error boolean false Shows the generic error (role alert) above the actions.
submitted submitted boolean false Shows the thank-you line and the read-only rating.
readonly readonly boolean false Shows the rating read-only without the form (history).

Properties

Attributes also expose the properties listed in the Property column above.

Name Type Default Description
strings Partial<typeof STRINGS> {} translated labels; English by default.

Events

Name Detail type Description
chatty-submit CustomEvent<{rating: number, comment: string}> Submit with a rating.
chatty-skip CustomEvent<{}> Skip.

Slots

Name Description
heading Survey question.
thanks Thank-you line shown once submitted.
icon Icon beside the thank-you line.
error-icon Icon beside the error message.

Parts

Name Description
base Survey card.
heading Heading element.
rating The chatty-rating.
comment Comment textarea.
actions Submit and Skip row.

CSS custom properties

Name Default Description
--chatty-survey-radius – Card corner radius.
--chatty-survey-background – Card background.

Usage

import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/survey.js';
<chatty-survey>
  <span slot="heading">How was your chat?</span>
</chatty-survey>
<chatty-survey value="4" comment="Quick answer about sizes.">
  <span slot="heading">How was your chat?</span>
</chatty-survey>

Live preview

Component thật dùng cùng story với trang component; dữ liệu mẫu nằm trong frame cục bộ.

Standard
LightDarkDesktopMobile

Default: trạng thái mặc định và nội dung mẫu của element.

Show code
chatty-survey.element.jsWrap code linesCopy
<chatty-survey>
  <span slot="heading">How was your chat?</span>
</chatty-survey>
<chatty-survey value="4" comment="Quick answer about sizes.">
  <span slot="heading">How was your chat?</span>
</chatty-survey>
Standard
LightDarkDesktopMobile

Các variant hoặc state chính đặt cạnh nhau trong cùng ví dụ.

Show code
chatty-survey.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/tokens.css';
import {IconCheck, IconAlertCircle} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-survey prototype chatty-ui ports from (chatty-ui/src/elements/survey.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/survey.js';

export function States() {
  return html`
    <chatty-survey value="5" busy="submit">
      <span slot="heading">How was your chat?</span>
    </chatty-survey>
    <chatty-survey value="2" error>
      <span slot="heading">How was your chat?</span>
      ${IconAlertCircle({size: 16, slot: 'error-icon'})}
    </chatty-survey>
    <chatty-survey value="5" submitted>
      ${IconCheck({slot: 'icon'})}
      <span slot="thanks">Thanks for your feedback!</span>
    </chatty-survey>
  `;
}

Anatomy

Số trong hình khớp bảng bên dưới. Phần chỉ hiện ở state khác được ghi Not shown; ví dụ không thêm phần tử giả.

Standard
LightDarkDesktopMobile

Anatomy: một instance mặc định riêng, có khoảng trống quanh các phần được đánh số.

Show code
chatty-survey.element.jsWrap code linesCopy
<chatty-survey>
  <span slot="heading">How was your chat?</span>
</chatty-survey>
<chatty-survey value="4" comment="Quick answer about sizes.">
  <span slot="heading">How was your chat?</span>
</chatty-survey>
Part Element Source
1 CSS part base chatty-ui/custom-elements.json
2 CSS part heading chatty-ui/custom-elements.json
3 CSS part rating chatty-ui/custom-elements.json
4 CSS part comment chatty-ui/custom-elements.json
5 CSS part actions chatty-ui/custom-elements.json

Keyboard

Key Action
Tab / Shift+Tab Move through rating and comment controls.
Enter / Space Activate the focused rating or submit button.

Source

  • chatty-ui/custom-elements.json