On this page

chatty-checkbox

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

Copy page as MarkdownRead Markdown ↗

Key rules

  • chatty-checkbox khai báo 8 attribute, 0 property không có attribute, 1 event, 1 slot, 3 part và 2 CSS custom property.
  • Import 1 module @avada/chatty-ui/elements/checkbox.js là define chatty-checkbox; 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 checkbox with its own label; submits value while checked. Class ChattyCheckbox.

Attributes

Name Property Type Default Description
checked checked boolean false Checked state; the checked attribute is the default restored by form reset.
disabled disabled boolean false Disables the box; not submitted.
required required boolean false Must be checked for the form to be valid.
name name string '' Form field name.
value value string 'on' Submitted value while checked.
label label string '' Label text when the default slot is empty.
label-hidden labelHidden boolean false Hides the label visually; it stays the accessible name.
size size 'sm' | 'md' | 'lg' 'md' Box size: 16, 20 or 24px.

Properties

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

Not declared in the manifest.

Events

Name Detail type Description
change Event Checked state changed by the user, re-dispatched from the host.

Slots

Name Description
default Label content; falls back to the label attribute.

Parts

Name Description
base Label wrapper (box and text).
control Native checkbox input.
label Label text.

CSS custom properties

Name Default Description
--chatty-checkbox-size – Box size; overrides size.
--chatty-checkbox-checked-color – Box fill while checked; defaults to the accent.

Usage

import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/checkbox.js';
<chatty-checkbox size="sm" label="Small"></chatty-checkbox>
<chatty-checkbox label="Email me a transcript"></chatty-checkbox>
<chatty-checkbox size="lg" checked>Subscribe to updates</chatty-checkbox>
<chatty-checkbox label="Select conversation" label-hidden></chatty-checkbox>

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-checkbox.element.jsWrap code linesCopy
<chatty-checkbox size="sm" label="Small"></chatty-checkbox>
<chatty-checkbox label="Email me a transcript"></chatty-checkbox>
<chatty-checkbox size="lg" checked>Subscribe to updates</chatty-checkbox>
<chatty-checkbox label="Select conversation" label-hidden></chatty-checkbox>
Standard
LightDarkDesktopMobile

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

Show code
chatty-checkbox.element.jsWrap code linesCopy
<chatty-checkbox label="Checked" checked></chatty-checkbox>
<chatty-checkbox label="Disabled" disabled></chatty-checkbox>
<chatty-checkbox label="Disabled checked" checked disabled></chatty-checkbox>
<chatty-checkbox label="I agree to the terms" required></chatty-checkbox>

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-checkbox.element.jsWrap code linesCopy
<chatty-checkbox size="sm" label="Small"></chatty-checkbox>
<chatty-checkbox label="Email me a transcript"></chatty-checkbox>
<chatty-checkbox size="lg" checked>Subscribe to updates</chatty-checkbox>
<chatty-checkbox label="Select conversation" label-hidden></chatty-checkbox>
Part Element Source
1 CSS part base chatty-ui/custom-elements.json
2 CSS part control chatty-ui/custom-elements.json
3 CSS part label chatty-ui/custom-elements.json

Keyboard

Key Action
Space Toggle the checkbox.

Source

  • chatty-ui/custom-elements.json