On this page

chatty-toast

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

Copy page as MarkdownRead Markdown ↗

Key rules

  • chatty-toast khai báo 4 attribute, 0 property không có attribute, 2 event, 3 slot, 5 part và 2 CSS custom property.
  • Import 1 module @avada/chatty-ui/elements/toast.js là define chatty-toast; 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

A short-lived notice. The host is a live region (status, or alert for tone critical) so the message is announced; it hides itself after duration ms (0 keeps it), pausing while hovered or focused. The caller places it (a toast region); the element does not position itself. Class ChattyToast.

Attributes

Name Property Type Default Description
open open boolean false Shows the toast and starts the duration timer.
tone tone 'neutral' | 'critical' | 'success' | 'caution' 'neutral' Meaning of the notice: a leading icon, and role alert for critical.
duration duration number 6000 Milliseconds before it closes itself (reason timeout); 0 keeps it until closed.
close-label closeLabel string 'Close' Accessible name of the close button.

Properties

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

Not declared in the manifest.

Events

Name Detail type Description
click MouseEvent Native click of the close button; it bubbles out of the shadow root.
chatty-close CustomEvent<{reason: 'timeout' | 'close-button'}> A request to close; preventDefault keeps the toast.

Slots

Name Description
default Message.
action One optional action, such as Undo.
close-icon Icon of the close button; a cross by default.

Parts

Name Description
base Toast box.
icon Leading tone icon (critical, success, caution); neutral has none.
message Message wrapper.
action Action wrapper.
close Close button.

CSS custom properties

Name Default Description
--chatty-toast-background – Toast background.
--chatty-toast-color – Toast text colour.

Usage

import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/toast.js';
import '@avada/chatty-ui/elements/button.js';
<chatty-toast style="width: 100%" open duration="0">Message deleted<chatty-button slot="action" variant="plain" size="sm">Undo</chatty-button></chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="success">Added to cart</chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="critical">Couldn't send. Check your connection and try again.</chatty-toast>

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-toast.element.jsWrap code linesCopy
<chatty-toast style="width: 100%" open duration="0">Message deleted<chatty-button slot="action" variant="plain" size="sm">Undo</chatty-button></chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="success">Added to cart</chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="critical">Couldn't send. Check your connection and try again.</chatty-toast>

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-toast.element.jsWrap code linesCopy
<chatty-toast style="width: 100%" open duration="0">Message deleted<chatty-button slot="action" variant="plain" size="sm">Undo</chatty-button></chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="success">Added to cart</chatty-toast>
<chatty-toast style="width: 100%" open duration="0" tone="critical">Couldn't send. Check your connection and try again.</chatty-toast>
Part Element Source
1 CSS part base chatty-ui/custom-elements.json
2 CSS part icon chatty-ui/custom-elements.json
3 CSS part message chatty-ui/custom-elements.json
4 CSS part action chatty-ui/custom-elements.json
5 CSS part close chatty-ui/custom-elements.json

Keyboard

Key Action
Enter / Space Activate a slotted action or close control.

Source

  • chatty-ui/custom-elements.json