Key rules
chatty-buttonkhai 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.jslà definechatty-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 |
|---|---|---|
- |
– | Corner radius. |
- |
– | Plain hover/ |
- |
– | Plain interaction decoration; inherits base decoration when unset. |
- |
– | Plain focus radius; inherits the base radius when unset. |
- |
– | Background scoped by variant and tone. |
- |
– | Text colour scoped by variant and tone. |
- |
– | Border colour scoped by variant and tone. |
- |
– | Control height; Classic uses a fixed box. |
- |
– | Inline padding. |
- |
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ộ.
Default: trạng thái mặc định và nội dung mẫu của element.
Show code
<chatty-button variant="primary">Send</chatty-button>Các variant hoặc state chính đặt cạnh nhau trong cùng ví dụ.
Show code
<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>Các variant hoặc state chính đặt cạnh nhau trong cùng ví dụ.
Show code
<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ả.
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 variant="primary">Send</chatty-button>| Part | Element | Source |
|---|---|---|
| 1 | CSS part base |
chatty- |
| 2 | CSS part label |
chatty- |
| 3 | CSS part start |
chatty- |
| 4 | CSS part end |
chatty- |
Keyboard
| Key | Action |
|---|---|
| Enter / Space | Activate the action or link. |
Source
- chatty-ui/custom-elements.json