On this page

Resting launcher

Nút mở panel AI Mode dùng chung markup cho cold và full app.

Copy page as MarkdownRead Markdown ↗

Key rules

  • Launcher gọi action do caller truyền.
  • Element chatty-launcher ở 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

Mở panel hoặc giỏ từ trạng thái resting.

Use instead

Component Use when
LauncherChrome Mở panel hoặc giỏ từ trạng thái resting.
RestingSearchBar Caller sở hữu tương tác liên quan.

Live preview

Standard

Standard
LightDarkDesktopMobile

Pill resting có chấm online, và pill có nút giỏ với badge số món.

Show code
chatty-launcher.element.jsWrap code linesCopy
<chatty-launcher label="Open Chatty" live>
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
</chatty-launcher>
<chatty-launcher label="Open Chatty" bag count="2">
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
  <svg
    slot="bag-icon"
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="1.8"
    aria-hidden="true"
  >
    <path d="M5 8h14l-1 12H6zM9 8a3 3 0 0 1 6 0" />
  </svg>
</chatty-launcher>

Prototype (cùng launcher.styles.js) là chuẩn: chatty-ui port 1:1, và chatty-ui/custom-elements.json sinh từ chính prototype. Trigger mở panel và nút giỏ là hai button anh em (React lồng button trong role button). Icon trợ lý, icon giỏ và câu mời đi qua slot. Chưa surface nào dùng element thật; mục AI Mode bên dưới mô tả React đang chạy.

Element

Element Module
chatty-launcher @avada/chatty-ui/elements/launcher.js

API

Kind Name Type Default Description
attribute label string '' Tên truy cập của trigger, ví dụ Open Chatty.
attribute bag boolean false Hiện nút giỏ; giỏ xác nhận rỗng thì bỏ.
attribute count number 0 Số món trong giỏ; badge hiện khi lớn hơn 0 và có trần hiển thị.
attribute bag-label string 'Shopping bag' Tên nút giỏ khi count bằng 0.
attribute count-label string '{count} items in cart' Tên nút giỏ khi count lớn hơn 0; {count} được thay.
attribute live boolean false Chấm online trên orb.
event chatty-open CustomEvent<{target: 'panel' , 'bag'}> – Trigger (target panel) hoặc nút giỏ (target bag) được kích hoạt.
event chatty-preload CustomEvent<{}> – Lần đầu rê chuột vào hoặc focus; host tải panel trước.
event click MouseEvent – Kích hoạt native của trigger hoặc nút giỏ.
slot default – – Câu mời, ví dụ Ask a question.
slot icon – – Icon trợ lý trong orb.
slot bag-icon – – Icon giỏ.
part base – – Khung pill.
part trigger – – Button mở panel; vùng bấm phủ cả pill trừ nút giỏ.
part orb – – Orb trợ lý.
part bag – – Nút giỏ.
part count – – Badge số món.
css-property --chatty-launcher-width – – Bề rộng pill.
css-property --chatty-launcher-background – – Nền pill.

AI Mode

Standard
LightDarkDesktopMobile

Pill resting có chấm online, và pill có nút giỏ với badge số món.

Show code
chatty-launcher.element.jsWrap code linesCopy
<chatty-launcher label="Open Chatty" live>
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
</chatty-launcher>
<chatty-launcher label="Open Chatty" bag count="2">
  <svg slot="icon" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
    <path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z" />
  </svg>
  Ask a question
  <svg
    slot="bag-icon"
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="1.8"
    aria-hidden="true"
  >
    <path d="M5 8h14l-1 12H6zM9 8a3 3 0 0 1 6 0" />
  </svg>
</chatty-launcher>
Current (React), being replaced
LightDarkDesktopMobile

Launcher thật với hành động cục bộ.

Show code
launcher.jsxWrap code linesCopy
import React from 'react';
import {LauncherChrome} from '@scripttag/v2/components/LauncherChrome.jsx';
import {ButtonIcon} from '@scripttag/v2/icons/buttonIcon.jsx';
import IconBag from '@scripttag/v2/icons/IconBag.jsx';
import {SearchPlaceholder} from '@scripttag/v2/components/SearchBar/SearchPlaceholder.jsx';
import '@scripttag/v2/styles/glass.scss';
import '@scripttag/v2/components/SearchBar/SearchBar.scss';

// The resting skin hangs off `.chatty-ai-mode.state-resting` (and the bag off `.has-bag`), which
// AIModeWidgetRoot sets on the widget root; the frame root has neither, so the story adds them.
const resting = node => node?.closest('[data-surface]')?.classList.add('state-resting', 'has-bag');

export function Resting() {
  return <div ref={resting}>
    <LauncherChrome assistantName="Chatty" invitePhrases={['Ask a question']} actions={{loadPanel: () => {}, openPanel: () => {}}} bagCount={0} Icon={ButtonIcon} BagIcon={IconBag} Placeholder={SearchPlaceholder} />
  </div>;
}

Import / element

Component / element Import / file Scope root
LauncherChrome @scripttag/v2/components/LauncherChrome.jsx .chatty-ai-mode

Anatomy

Part Element
1 Trigger, icon, placeholder và nút giỏ.

Placement / order

Context Order
Caller Theo thứ tự markup của component.

Props

Prop Type Values Default Notes
assistantName string Tên trợ lý Caller Dùng trong nhãn mở panel.
preview boolean true, false false Bản xem tĩnh cho preview preset ở admin: trigger không role, nhãn, handler; giỏ là span.

Sizes

Size Height Padding Gap Radius Font role (px/rem) Hit target Breakpoint / mechanism
Component Theo caller Theo caller Theo caller Theo caller Theo caller Nút native và trigger Style từ SearchBar

Tokens

Part Token Light Dark
Nền Theo scope Theo scope Theo scope

States

State Trigger Visual change (values) ARIA/attribute
Giỏ có hàng bagCount lớn hơn 0 Hiện badge số lượng. aria-label theo số lượng

Behaviour

Interaction Result
Mở panel Click trigger gọi action; click nút giỏ truyền bag.
Cold takeover Khi full app đã sẵn sàng, chuyển lại biến và focus cho panel tương ứng.
Cold icon Icon upload dùng ảnh; nếu không thì dùng Glyph do caller truyền.

Copy

String i18n key Where
Shopping bag Shopping bag Nhãn giỏ rỗng

Source

File Evidence
Public API
Markup
Caller

Do / Don't

Accessibility

Surface Role / name Keyboard / focus Live region Contrast pair / ratio
AI Mode Trigger role button có tên; nút giỏ có aria-label Caller xử lý phím cho trigger; giỏ là nút native, trừ bản preview Không có live region Theo scope

Target