# chatty-checkbox

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

## 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.

## 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

```js
import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/checkbox.js';
```

```html
<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ộ.

Example (Standard) — Default: trạng thái mặc định và nội dung mẫu của element.

```html
<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>
```

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

```html
<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ả.

Example (Standard) — Anatomy: một instance mặc định riêng, có khoảng trống quanh các phần được đánh số.

```html
<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
