On this page

Cart notice

Thông báo kết quả giỏ hàng khi không có dòng giá hoặc số lượng hợp lệ.

Copy page as MarkdownRead Markdown ↗

Key rules

  • Dùng kết quả từ caller; success có thể mở giỏ, failure hiển thị lý do.
  • Element chatty-cart-notice ở mục Standard là chuẩn chatty-ui port theo; các mục theo surface mô tả component React đang chạy.
On this page

Use when / Avoid

Dùng khi kết quả giỏ không đủ dữ liệu để dựng receipt chi tiết.

Use instead

Component Use when
CartNotice Kết quả thêm giỏ thành công hoặc thất bại.
CartConfirmation Receipt có dòng giỏ chi tiết.

Live preview

Standard
LightDarkDesktopMobile

Một receipt cho năm dòng thêm cùng lượt; storefront hiện ba dòng và summary.

Show code
chatty-cart-confirmation.element.jsWrap code linesCopy
<chatty-cart-confirmation grouped heading="Added 5 products to cart">
  <chatty-cart-confirmation slot="items" quantity="2" price="$48.00"
    ><img slot="media" src="/fixtures/tote.svg" alt="" />Canvas tote bag<span slot="detail"
      >Natural / Large</span
    ></chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$18.00"
    >Ceramic mug</chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$28.00"
    ><img slot="media" src="/fixtures/cap.svg" alt="" />Wool cap</chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$24.00"
    >Linen scarf</chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$18.00"
    >Leather wallet</chatty-cart-confirmation
  >
  <span slot="more">and 2 more products — view in cart</span>
  <chatty-button slot="action" variant="plain">View cart</chatty-button>
</chatty-cart-confirmation>

Standard

Grouped receipt: đặt grouped trên receipt cha, heading đã dịch, các receipt con trong slot items, summary đã dịch trong slot more và một action ở receipt cha. Trên storefront, hơn bốn dòng thì hiện ba dòng; show-all dành cho Admin history; Admin không có action View cart vì merchant không mở giỏ của shopper. API sinh ở chatty-cart-confirmation.

Standard
LightDarkDesktopMobile

Element chatty-cart-notice: đã thêm có View cart, và không thêm được có lý do.

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

export function Standard() {
  return html`
    <chatty-cart-notice>
      ${IconCheck({slot: 'icon'})} Cotton shirt
      <chatty-button slot="action" variant="plain">View cart</chatty-button>
    </chatty-cart-notice>
    <chatty-cart-notice tone="critical">
      ${IconAlertCircle({slot: 'icon'})} Cotton shirt
      <span slot="detail">Sold out</span>
    </chatty-cart-notice>
  `;
}

Prototype (cùng cart-notice.styles.js) là chuẩn: chatty-ui port 1:1, và chatty-ui/custom-elements.json sinh từ chính prototype. Icon, tên sản phẩm, lý do và nút View cart đi vào qua slot; vùng thông báo đặt tên bằng tiêu đề cộng tên sản phẩm. Chưa surface nào dùng element thật; các mục bên dưới mô tả React đang chạy.

Element

Element Module
chatty-cart-notice @avada/chatty-ui/elements/cart-notice.js

API

Kind Name Type Default Description
attribute tone success, critical 'success' success là đã thêm, critical là không thêm được; giá trị lạ quay về success.
attribute heading string '' Tiêu đề; rỗng thì dùng Added to cart hoặc Could not add to cart theo tone.
slot default – – Tên sản phẩm.
slot icon – – Icon trạng thái (check hoặc cảnh báo).
slot detail – – Lý do lỗi, ví dụ Sold out.
slot action – – Nút View cart; chỉ hiện khi tone success.
part base – – Khung thông báo (section).
part icon – – Vùng chứa icon.
part label – – Dòng tiêu đề.
css-property --chatty-cart-notice-radius – – Bo góc.
css-property --chatty-cart-notice-background – – Nền.

AI Mode

Standard
LightDarkDesktopMobile

Element chatty-cart-notice: đã thêm có View cart, và không thêm được có lý do.

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

export function Standard() {
  return html`
    <chatty-cart-notice>
      ${IconCheck({slot: 'icon'})} Cotton shirt
      <chatty-button slot="action" variant="plain">View cart</chatty-button>
    </chatty-cart-notice>
    <chatty-cart-notice tone="critical">
      ${IconAlertCircle({slot: 'icon'})} Cotton shirt
      <span slot="detail">Sold out</span>
    </chatty-cart-notice>
  `;
}
Current (React), being replaced
LightDarkDesktopMobile

Kết quả thêm giỏ và lỗi với dữ liệu cục bộ.

Show code
cart-notice.jsxWrap code linesCopy
import React from 'react';
import {CartNotice} from '@avada/chatty-ui/primitives/CartNotice.jsx';

export function Catalogue({surface}) {
  return <div>
    <CartNotice notice={{kind: 'added', title: 'Cotton shirt'}} translate={text => text} onViewCart={surface === 'admin' ? undefined : () => {}} />
    <CartNotice notice={{kind: 'failure', title: 'Cotton shirt', reason: 'Sold out'}} translate={text => text} />
  </div>;
}

Import / element

Component / element Import / file Scope root
CartNotice @avada/chatty-ui/primitives/CartNotice.jsx .chatty-ai-mode

Anatomy

Part Element
1 Section chứa icon, nhãn và nội dung.
2 Nút View cart tùy chọn ở kết quả thành công.

Placement / order

Context Order
Notice Icon trước body; nhãn, title, reason rồi action.

Props

Prop Type Values Default Notes
notice object Kết quả giỏ Caller Dữ liệu không hợp lệ trả null.
translate function Hàm dịch Caller Dịch nhãn và action.
onViewCart function Handler undefined Chỉ dùng ở kết quả thành công.

Sizes

Size Height Padding Gap Radius Font role (px/rem) Hit target Breakpoint / mechanism
Notice Theo nội dung 12px 16px 10px radius.$card body-medium Nút native Rộng tối đa 360px

Tokens

Part Token Light Dark
Text --chatty-color-text Fallback #303030 Theo scope
Failure --chatty-color-critical Fallback #c5280c Theo scope

States

State Trigger Visual change (values) ARIA/attribute
Success kind added Icon check, có thể hiện View cart. Native button
Failure kind failure Icon alert, nhãn lỗi và reason nếu có. Không thêm role

Behaviour

Interaction Result
View cart Gọi handler từ caller.
Invalid notice Trả null.

Copy

String i18n key Where
Added to cart Added to cart Nhãn success
Could not add to cart Could not add to cart Nhãn failure
View cart View cart Action success

Source

File Evidence
API và markup
Style

Classic

Standard
LightDarkDesktopMobile

Element chatty-cart-notice: đã thêm có View cart, và không thêm được có lý do.

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

export function Standard() {
  return html`
    <chatty-cart-notice>
      ${IconCheck({slot: 'icon'})} Cotton shirt
      <chatty-button slot="action" variant="plain">View cart</chatty-button>
    </chatty-cart-notice>
    <chatty-cart-notice tone="critical">
      ${IconAlertCircle({slot: 'icon'})} Cotton shirt
      <span slot="detail">Sold out</span>
    </chatty-cart-notice>
  `;
}
Current (React), being replaced
LightDarkDesktopMobile

Kết quả trong widget Classic.

Show code
cart-notice.jsxWrap code linesCopy
import React from 'react';
import {CartNotice} from '@avada/chatty-ui/primitives/CartNotice.jsx';

export function Catalogue({surface}) {
  return <div>
    <CartNotice notice={{kind: 'added', title: 'Cotton shirt'}} translate={text => text} onViewCart={surface === 'admin' ? undefined : () => {}} />
    <CartNotice notice={{kind: 'failure', title: 'Cotton shirt', reason: 'Sold out'}} translate={text => text} />
  </div>;
}

Import / element

Component / element Import / file Scope root
CartNotice @avada/chatty-ui/primitives/CartNotice.jsx .Avada-Faqs_Popup

Anatomy

Part Element
1 Section chứa icon, nhãn và nội dung.
2 Nút View cart tùy chọn ở kết quả thành công.

Placement / order

Context Order
Notice Icon trước body; nhãn, title, reason rồi action.

Props

Prop Type Values Default Notes
notice object Kết quả giỏ Caller Dữ liệu không hợp lệ trả null.
translate function Hàm dịch Caller Dịch nhãn và action.
onViewCart function Handler undefined Chỉ dùng ở kết quả thành công.

Sizes

Size Height Padding Gap Radius Font role (px/rem) Hit target Breakpoint / mechanism
Notice Theo nội dung 12px 16px 10px radius.$card body-medium Nút native Rộng tối đa 360px

Tokens

Part Token Light Dark
Text --chatty-color-text Fallback #303030 Theo scope
Failure --chatty-color-critical Fallback #c5280c Theo scope

States

State Trigger Visual change (values) ARIA/attribute
Success kind added Icon check, có thể hiện View cart. Native button
Failure kind failure Icon alert, nhãn lỗi và reason nếu có. Không thêm role

Behaviour

Interaction Result
View cart Gọi handler từ caller.
Invalid notice Trả null.

Copy

String i18n key Where
Added to cart Added to cart Nhãn success
Could not add to cart Could not add to cart Nhãn failure
View cart View cart Action success

Source

File Evidence
API và markup
Style

Admin

Standard
LightDarkDesktopMobile

Admin history dùng show-all để hiện hết năm dòng; không có action View cart.

Show code
chatty-cart-confirmation.element.jsWrap code linesCopy
<chatty-cart-confirmation grouped show-all heading="Added 5 products to cart">
  <chatty-cart-confirmation slot="items" quantity="2" price="$48.00"
    ><img slot="media" src="/fixtures/tote.svg" alt="" />Canvas tote bag<span slot="detail"
      >Natural / Large</span
    ></chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$18.00"
    >Ceramic mug</chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$28.00"
    ><img slot="media" src="/fixtures/cap.svg" alt="" />Wool cap</chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$24.00"
    >Linen scarf</chatty-cart-confirmation
  >
  <chatty-cart-confirmation slot="items" quantity="1" price="$18.00"
    >Leather wallet</chatty-cart-confirmation
  >
  <span slot="more">and 2 more products — view in cart</span>
</chatty-cart-confirmation>
Standard
LightDarkDesktopMobile

Element chatty-cart-notice: đã thêm có View cart, và không thêm được có lý do.

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

export function Standard() {
  return html`
    <chatty-cart-notice>
      ${IconCheck({slot: 'icon'})} Cotton shirt
      <chatty-button slot="action" variant="plain">View cart</chatty-button>
    </chatty-cart-notice>
    <chatty-cart-notice tone="critical">
      ${IconAlertCircle({slot: 'icon'})} Cotton shirt
      <span slot="detail">Sold out</span>
    </chatty-cart-notice>
  `;
}
Current (React), being replaced
LightDarkDesktopMobile

Kết quả chỉ đọc trong inbox.

Show code
cart-notice.jsxWrap code linesCopy
import React from 'react';
import {CartNotice} from '@avada/chatty-ui/primitives/CartNotice.jsx';

export function Catalogue({surface}) {
  return <div>
    <CartNotice notice={{kind: 'added', title: 'Cotton shirt'}} translate={text => text} onViewCart={surface === 'admin' ? undefined : () => {}} />
    <CartNotice notice={{kind: 'failure', title: 'Cotton shirt', reason: 'Sold out'}} translate={text => text} />
  </div>;
}

Import / element

Component / element Import / file Scope root
CartNotice @avada/chatty-ui/primitives/CartNotice.jsx .inbox-v2

Anatomy

Part Element
1 Section chứa icon, nhãn và nội dung.
2 Nút View cart tùy chọn ở kết quả thành công.

Placement / order

Context Order
Notice Icon trước body; nhãn, title, reason rồi action.

Props

Prop Type Values Default Notes
notice object Kết quả giỏ Caller Dữ liệu không hợp lệ trả null.
translate function Hàm dịch Caller Dịch nhãn và action.
onViewCart function Handler undefined Chỉ dùng ở kết quả thành công.

Sizes

Size Height Padding Gap Radius Font role (px/rem) Hit target Breakpoint / mechanism
Notice Theo nội dung 12px 16px 10px radius.$card body-medium Nút native Rộng tối đa 360px

Tokens

Part Token Light Dark
Text --chatty-color-text Fallback #303030 No Dark skin
Failure --chatty-color-critical Fallback #c5280c No Dark skin

States

State Trigger Visual change (values) ARIA/attribute
Success kind added Icon check, có thể hiện View cart. Native button
Failure kind failure Icon alert, nhãn lỗi và reason nếu có. Không thêm role

Behaviour

Interaction Result
View cart Gọi handler từ caller.
Invalid notice Trả null.

Copy

String i18n key Where
Added to cart Added to cart Nhãn success
Could not add to cart Could not add to cart Nhãn failure
View cart View cart Action success

Source

File Evidence
API và markup
Style

Do / Don't

Accessibility

Surface Role / name Keyboard / focus Live region Contrast pair / ratio
AI Mode Section và nút View cart native khi có action Tab tới nút, Enter hoặc Space kích hoạt Caller sở hữu thông báo Theo scope của caller
Classic Section và nút View cart native khi có action Tab tới nút, Enter hoặc Space kích hoạt Caller sở hữu thông báo Theo scope của caller
Admin Section và nút View cart native khi có action Tab tới nút, Enter hoặc Space kích hoạt Caller sở hữu thông báo Theo scope của caller

Target