On this page

chatty-button

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

Copy page as MarkdownRead Markdown ↗

Key rules

  • chatty-button khai báo 8 attribute, 0 property không có attribute, 1 event, 3 slot, 4 part và 10 CSS custom property.
  • Import 1 module @avada/chatty-ui/elements/button.js là define chatty-button; 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 form-associated action or link with an inherited semantic theme. Class ChattyButton.

Attributes

Name Property Type Default Description
variant variant 'primary' | 'secondary' | 'tertiary' | 'plain' 'secondary' Visual emphasis of the action.
tone tone 'neutral' | 'critical' | 'success' | 'caution' 'neutral' Semantic action tone.
size size 'sm' | 'md' | 'lg' 'md' Control size.
disabled disabled boolean false Blocks activation while keeping the control focusable.
loading loading boolean false Shows progress and blocks activation.
href href string '' Link destination; only http, https, mailto and tel are allowed.
label label string '' Accessible name; defaults to the slotted label.
type type 'button' | 'submit' | 'reset' 'button' Form activation behavior.

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 activation; detail is the native click count.

Slots

Name Description
default Button label.
start Leading content.
end Trailing content.

Parts

Name Description
base Native interactive control.
label Label content.
start Leading content wrapper.
end Trailing content wrapper.

CSS custom properties

Name Default Description
--chatty-button-radius – Corner radius.
--chatty-button-plain-bg-hover – Plain hover/pressed fill; inherits tertiary fill when unset.
--chatty-button-plain-decoration-hover – Plain interaction decoration; inherits base decoration when unset.
--chatty-button-plain-focus-radius – Plain focus radius; inherits the base radius when unset.
--chatty-button-background – Background scoped by variant and tone.
--chatty-button-color – Text colour scoped by variant and tone.
--chatty-button-border-color – Border colour scoped by variant and tone.
--chatty-button-height – Control height; Classic uses a fixed box.
--chatty-button-padding-inline – Inline padding.
--chatty-button-width auto Control width; 100% fills the container.

Usage

import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/button.js';
<chatty-button variant="primary">Send</chatty-button>

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-button.element.jsWrap code linesCopy
<chatty-button variant="primary">Send</chatty-button>
Standard
LightDarkDesktopMobile

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

Show code
chatty-button.element.jsWrap code linesCopy
<div
  class="button-variants"
  role="group"
  aria-label="Button variants and sizes"
  style="box-sizing:border-box;display:grid;gap:8px;width:100%;max-width:400px"
>
  <p style="margin:0">Button variants and sizes</p>
  <div style="display:flex;flex-wrap:wrap;gap:8px;align-items:center">
    <chatty-button variant="primary">Send</chatty-button>
    <chatty-button>Cancel</chatty-button>
    <chatty-button variant="tertiary">Skip</chatty-button>
    <chatty-button variant="plain">View order</chatty-button>
    <chatty-button variant="primary" size="sm">Small</chatty-button>
    <chatty-button variant="primary" size="lg">Large</chatty-button>
    <chatty-button variant="primary" tone="critical">Delete</chatty-button>
    <chatty-button variant="secondary" tone="success">Confirm</chatty-button>
  </div>
</div>
<style>
  :host([data-chatty-surface='ai-mode']) .button-variants {
    --chatty-button-primary-bg: #303030;
    --chatty-button-primary-hover: color-mix(in srgb, #303030 85%, black);
    --chatty-button-primary-active: var(--chatty-button-primary-hover);
  }
</style>
Standard
LightDarkDesktopMobile

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

Show code
chatty-button.element.jsWrap code linesCopy
<form
  aria-label="Email a transcript"
  style="box-sizing:border-box;display:grid;gap:8px;width:100%;max-width:400px"
>
  <div style="display:flex;flex-wrap:wrap;gap:8px;align-items:center">
    <chatty-button variant="primary" disabled>Disabled</chatty-button>
    <chatty-button variant="primary" loading>Sending</chatty-button>
    <chatty-button href="https://example.com/orders">Open link</chatty-button>
    <chatty-button label="Close chat">×</chatty-button>
  </div>
</form>
<style>
  :host([data-chatty-surface='ai-mode']) form {
    --chatty-button-primary-bg: #303030;
    --chatty-button-primary-hover: color-mix(in srgb, #303030 85%, black);
    --chatty-button-primary-active: var(--chatty-button-primary-hover);
  }
</style>

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-button.element.jsWrap code linesCopy
<chatty-button variant="primary">Send</chatty-button>
Part Element Source
1 CSS part base chatty-ui/custom-elements.json
2 CSS part label chatty-ui/custom-elements.json
3 CSS part start chatty-ui/custom-elements.json
4 CSS part end chatty-ui/custom-elements.json

Keyboard

Key Action
Enter / Space Activate the action or link.

Source

  • chatty-ui/custom-elements.json