@kubex/zinc 1.0.25 → 1.0.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/project.md +556 -0
- package/.github/workflows/js_build_and_deploy.yaml +9 -10
- package/dist/custom-elements.json +13431 -8728
- package/dist/vscode.html-custom-data.json +571 -37
- package/dist/web-types.json +1439 -181
- package/dist/zn.d.ts +1642 -661
- package/dist/zn.min.css +1 -1
- package/dist/zn.min.js +1406 -891
- package/docs/_utilities/code-previews.cjs +10 -1
- package/docs/assets/scripts/docs.js +42 -18
- package/docs/data/data-table.json +229 -66
- package/docs/data/empty.json +6 -0
- package/docs/data/products-table.json +41 -193
- package/docs/pages/components/action-bar.md +121 -6
- package/docs/pages/components/alert.md +118 -15
- package/docs/pages/components/animated-button.md +299 -0
- package/docs/pages/components/audio-select.md +534 -0
- package/docs/pages/components/bulk-actions.md +79 -5
- package/docs/pages/components/button-group.md +235 -27
- package/docs/pages/components/button.md +139 -1
- package/docs/pages/components/chart.md +365 -9
- package/docs/pages/components/checkbox.md +387 -58
- package/docs/pages/components/chip.md +253 -33
- package/docs/pages/components/collapsible.md +393 -46
- package/docs/pages/components/cols.md +152 -30
- package/docs/pages/components/confirm.md +182 -16
- package/docs/pages/components/copy-button.md +169 -6
- package/docs/pages/components/data-select.md +194 -15
- package/docs/pages/components/data-table-filter.md +96 -5
- package/docs/pages/components/data-table-search.md +451 -0
- package/docs/pages/components/data-table-sort.md +66 -5
- package/docs/pages/components/data-table.md +727 -66
- package/docs/pages/components/datepicker.md +402 -7
- package/docs/pages/components/defined-label.md +120 -5
- package/docs/pages/components/dialog.md +339 -59
- package/docs/pages/components/dropdown.md +366 -11
- package/docs/pages/components/editor.md +604 -7
- package/docs/pages/components/empty-state.md +315 -16
- package/docs/pages/components/expanding-action.md +212 -28
- package/docs/pages/components/file.md +421 -12
- package/docs/pages/components/filter-container.md +158 -5
- package/docs/pages/components/filter-wrapper.md +167 -6
- package/docs/pages/components/form-group.md +383 -6
- package/docs/pages/components/hover-container.md +237 -6
- package/docs/pages/components/icon-picker.md +121 -0
- package/docs/pages/components/icon.md +454 -48
- package/docs/pages/components/inline-edit.md +787 -19
- package/docs/pages/components/input-group.md +207 -13
- package/docs/pages/components/input.md +194 -0
- package/docs/pages/components/key-container.md +115 -0
- package/docs/pages/components/key.md +101 -0
- package/docs/pages/components/menu.md +512 -6
- package/docs/pages/components/note.md +239 -36
- package/docs/pages/components/opt-group.md +107 -0
- package/docs/pages/components/pagination.md +332 -6
- package/docs/pages/components/pane.md +222 -6
- package/docs/pages/components/panel.md +213 -26
- package/docs/pages/components/popup.md +1354 -6
- package/docs/pages/components/priority-list.md +233 -0
- package/docs/pages/components/progress-bar.md +387 -6
- package/docs/pages/components/radio-group.md +242 -5
- package/docs/pages/components/radio.md +474 -6
- package/docs/pages/components/rating.md +331 -7
- package/docs/pages/components/reveal.md +524 -6
- package/docs/pages/components/scroll-container.md +552 -6
- package/docs/pages/components/select.md +762 -160
- package/docs/pages/components/skeleton.md +473 -30
- package/docs/pages/components/slideout.md +261 -5
- package/docs/pages/components/sp.md +99 -41
- package/docs/pages/components/split-button.md +347 -9
- package/docs/pages/components/split-pane.md +445 -6
- package/docs/pages/components/stat.md +549 -9
- package/docs/pages/components/status-indicator.md +230 -1
- package/docs/pages/components/stepper.md +563 -6
- package/docs/pages/components/tabs.md +439 -13
- package/docs/pages/components/textarea.md +415 -17
- package/docs/pages/components/tile.md +385 -26
- package/docs/pages/components/toggle.md +424 -6
- package/docs/pages/components/tooltip.md +367 -0
- package/docs/pages/components/translation-group.md +210 -0
- package/docs/pages/components/translations.md +319 -19
- package/docs/pages/components/vertical-stepper.md +401 -8
- package/docs/pages/components/well.md +300 -3
- package/docs/pages/getting-started/form-controls.md +162 -0
- package/docs/pages/index.md +116 -15
- package/package.json +5 -6
- package/scss/_global-spacing.scss +4 -0
- package/scss/_root.scss +2 -2
- package/scss/boot.scss +19 -0
- package/scss/shared/layout.scss +5 -0
- package/scss/themes/_light.scss +3 -3
- package/src/components/alert/alert.scss +1 -0
- package/src/components/animated-button/README.md +306 -0
- package/src/components/animated-button/animated-button.component.ts +229 -0
- package/src/components/animated-button/animated-button.scss +228 -0
- package/src/components/animated-button/animated-button.test.ts +143 -0
- package/src/components/animated-button/index.ts +12 -0
- package/src/components/button/button.component.ts +5 -0
- package/src/components/button-group/button-group.component.ts +25 -13
- package/src/components/button-group/button-group.scss +6 -0
- package/src/components/checkbox/checkbox.component.ts +4 -0
- package/src/components/checkbox/checkbox.scss +7 -4
- package/src/components/checkbox-group/checkbox-group.scss +7 -0
- package/src/components/chip/chip.component.ts +7 -2
- package/src/components/chip/chip.scss +16 -2
- package/src/components/collapsible/collapsible.component.ts +27 -20
- package/src/components/cols/cols.component.ts +14 -2
- package/src/components/cols/cols.scss +6 -12
- package/src/components/confirm/confirm.component.ts +7 -0
- package/src/components/copy-button/copy-button.component.ts +12 -11
- package/src/components/data-select/data-select.component.ts +215 -44
- package/src/components/data-select/data-select.scss +66 -6
- package/src/components/data-select/providers/currency-data-provider.ts +20 -6
- package/src/components/data-select/providers/provider.ts +1 -0
- package/src/components/data-select/providers/us-state-data-provider.ts +68 -0
- package/src/components/data-table/data-table.component.ts +81 -22
- package/src/components/data-table-search/data-table-search.component.ts +184 -0
- package/src/components/data-table-search/data-table-search.scss +17 -0
- package/src/components/data-table-search/data-table-search.test.ts +11 -0
- package/src/components/data-table-search/index.ts +12 -0
- package/src/components/datepicker/datepicker.component.ts +347 -13
- package/src/components/dialog/dialog.component.ts +1 -1
- package/src/components/empty-state/empty-state.scss +6 -1
- package/src/components/header/header.scss +3 -3
- package/src/components/icon/icon.component.ts +23 -1
- package/src/components/icon/icon.scss +23 -0
- package/src/components/icon-picker/brand-icons.ts +24 -0
- package/src/components/icon-picker/icon-picker.component.ts +407 -0
- package/src/components/icon-picker/icon-picker.scss +205 -0
- package/src/components/icon-picker/index.ts +12 -0
- package/src/components/icon-picker/line-icons.ts +612 -0
- package/src/components/icon-picker/material-icons.ts +14543 -0
- package/src/components/inline-edit/inline-edit.component.ts +190 -46
- package/src/components/inline-edit/inline-edit.scss +29 -0
- package/src/components/inline-edit/inline-edit.test.ts +314 -1
- package/src/components/input/input.component.ts +324 -5
- package/src/components/input/input.scss +87 -0
- package/src/components/input-group/input-group.component.ts +28 -7
- package/src/components/input-group/input-group.scss +48 -10
- package/src/components/item/item.component.ts +11 -2
- package/src/components/item/item.scss +7 -0
- package/src/components/key/index.ts +12 -0
- package/src/components/key/key.component.ts +47 -0
- package/src/components/key/key.scss +38 -0
- package/src/components/key-container/index.ts +12 -0
- package/src/components/key-container/key-container.component.ts +142 -0
- package/src/components/key-container/key-container.scss +33 -0
- package/src/components/menu-item/menu-item.component.ts +20 -0
- package/src/components/menu-item/menu-item.scss +69 -2
- package/src/components/navbar/navbar.component.ts +103 -11
- package/src/components/navbar/navbar.scss +6 -1
- package/src/components/opt-group/index.ts +12 -0
- package/src/components/opt-group/opt-group.component.ts +74 -0
- package/src/components/opt-group/opt-group.scss +37 -0
- package/src/components/opt-group/opt-group.test.ts +27 -0
- package/src/components/option/option.component.ts +1 -16
- package/src/components/option/option.scss +4 -0
- package/src/components/panel/panel.component.ts +10 -8
- package/src/components/panel/panel.scss +20 -0
- package/src/components/priority-list/index.ts +12 -0
- package/src/components/priority-list/priority-list.component.ts +611 -0
- package/src/components/priority-list/priority-list.scss +185 -0
- package/src/components/priority-list/priority-list.test.ts +139 -0
- package/src/components/progress-bar/progress-bar.component.ts +22 -16
- package/src/components/radio/radio.scss +10 -3
- package/src/components/select/select.component.ts +812 -72
- package/src/components/select/select.scss +108 -2
- package/src/components/select/select.test.ts +147 -2
- package/src/components/settings-container/settings-container.component.ts +44 -19
- package/src/components/settings-container/settings-container.scss +1 -1
- package/src/components/skeleton/skeleton.component.ts +6 -1
- package/src/components/slideout/slideout.scss +8 -3
- package/src/components/sp/sp.component.ts +3 -1
- package/src/components/sp/sp.scss +19 -0
- package/src/components/stepper/stepper.component.ts +16 -10
- package/src/components/textarea/textarea.scss +0 -4
- package/src/components/tile/tile.component.ts +12 -3
- package/src/components/tile/tile.scss +1 -1
- package/src/components/timer/timer.component.ts +15 -2
- package/src/components/toggle/toggle.component.ts +29 -26
- package/src/components/toggle/toggle.scss +13 -1
- package/src/components/translation-group/index.ts +12 -0
- package/src/components/translation-group/translation-group.component.ts +207 -0
- package/src/components/translation-group/translation-group.scss +8 -0
- package/src/components/translations/translations.component.ts +90 -44
- package/src/components/translations/translations.scss +4 -0
- package/src/components/vertical-stepper/vertical-stepper.component.ts +14 -9
- package/src/events/events.ts +12 -7
- package/src/events/zn-language-change.ts +7 -0
- package/src/events/zn-purchase.ts +11 -0
- package/src/events/zn-redirect.ts +7 -0
- package/src/events/zn-reorder.ts +7 -0
- package/src/events/zn-search-change.ts +11 -0
- package/src/events/zn-submit.ts +1 -1
- package/src/form-control.scss +4 -0
- package/src/internal/form-navigation.ts +510 -0
- package/src/internal/form.ts +6 -0
- package/src/zinc.ts +91 -83
|
@@ -3,155 +3,484 @@ meta:
|
|
|
3
3
|
title: Checkbox
|
|
4
4
|
description: Checkboxes allow the user to toggle an option on or off.
|
|
5
5
|
layout: component
|
|
6
|
-
unusedProperties: |
|
|
7
|
-
- Boolean `indeterminate
|
|
8
6
|
---
|
|
9
7
|
|
|
8
|
+
```html:preview
|
|
9
|
+
<zn-checkbox>Accept terms and conditions</zn-checkbox>
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
:::tip
|
|
13
|
+
This component works with standard `<form>` elements. Please refer to the section
|
|
14
|
+
on [form controls](/getting-started/form-controls) to learn more about form submission and client-side validation.
|
|
15
|
+
:::
|
|
16
|
+
|
|
10
17
|
## Examples
|
|
11
18
|
|
|
12
19
|
### Basic Checkbox
|
|
13
20
|
|
|
21
|
+
A basic checkbox with a label.
|
|
22
|
+
|
|
14
23
|
```html:preview
|
|
15
24
|
<zn-checkbox>Financial products access</zn-checkbox>
|
|
16
25
|
```
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
### Checked
|
|
28
|
+
|
|
29
|
+
Use the `checked` attribute to activate the checkbox by default.
|
|
30
|
+
|
|
31
|
+
```html:preview
|
|
32
|
+
<zn-checkbox checked>I agree to the terms</zn-checkbox>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Indeterminate
|
|
36
|
+
|
|
37
|
+
Use the `indeterminate` attribute to show an indeterminate state. This is typically used to represent a "select all" checkbox when some but not all items are selected.
|
|
38
|
+
|
|
39
|
+
```html:preview
|
|
40
|
+
<zn-checkbox indeterminate>Select all items</zn-checkbox>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```html:preview
|
|
44
|
+
<div id="indeterminate-example">
|
|
45
|
+
<zn-checkbox id="select-all">Select all</zn-checkbox>
|
|
46
|
+
<br /><br />
|
|
47
|
+
<zn-checkbox class="item">Item 1</zn-checkbox>
|
|
48
|
+
<br />
|
|
49
|
+
<zn-checkbox class="item">Item 2</zn-checkbox>
|
|
50
|
+
<br />
|
|
51
|
+
<zn-checkbox class="item">Item 3</zn-checkbox>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<script type="module">
|
|
55
|
+
const container = document.querySelector('#indeterminate-example');
|
|
56
|
+
const selectAll = container.querySelector('#select-all');
|
|
57
|
+
const items = container.querySelectorAll('.item');
|
|
58
|
+
|
|
59
|
+
function updateSelectAll() {
|
|
60
|
+
const checkedCount = Array.from(items).filter(item => item.checked).length;
|
|
61
|
+
|
|
62
|
+
if (checkedCount === 0) {
|
|
63
|
+
selectAll.checked = false;
|
|
64
|
+
selectAll.indeterminate = false;
|
|
65
|
+
} else if (checkedCount === items.length) {
|
|
66
|
+
selectAll.checked = true;
|
|
67
|
+
selectAll.indeterminate = false;
|
|
68
|
+
} else {
|
|
69
|
+
selectAll.checked = false;
|
|
70
|
+
selectAll.indeterminate = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
selectAll.addEventListener('zn-change', () => {
|
|
75
|
+
items.forEach(item => {
|
|
76
|
+
item.checked = selectAll.checked;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
items.forEach(item => {
|
|
81
|
+
item.addEventListener('zn-change', updateSelectAll);
|
|
82
|
+
});
|
|
83
|
+
</script>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Disabled
|
|
87
|
+
|
|
88
|
+
Use the `disabled` attribute to disable the checkbox.
|
|
89
|
+
|
|
90
|
+
```html:preview
|
|
91
|
+
<zn-checkbox disabled>Disabled checkbox</zn-checkbox>
|
|
92
|
+
<br />
|
|
93
|
+
<zn-checkbox disabled checked>Disabled and checked</zn-checkbox>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Sizes
|
|
97
|
+
|
|
98
|
+
Use the `size` attribute to change the checkbox size. Available sizes are `small`, `medium` (default), and `large`.
|
|
99
|
+
|
|
100
|
+
```html:preview
|
|
101
|
+
<zn-checkbox size="small">Small</zn-checkbox>
|
|
102
|
+
<br />
|
|
103
|
+
<zn-checkbox size="medium">Medium</zn-checkbox>
|
|
104
|
+
<br />
|
|
105
|
+
<zn-checkbox size="large">Large</zn-checkbox>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Colors
|
|
109
|
+
|
|
110
|
+
Use the `color` attribute to apply semantic colors to the checkbox. When checked or indeterminate, the checkbox will use the specified color.
|
|
111
|
+
|
|
112
|
+
```html:preview
|
|
113
|
+
<zn-checkbox color="default" checked>Default</zn-checkbox>
|
|
114
|
+
<br />
|
|
115
|
+
<zn-checkbox color="primary" checked>Primary</zn-checkbox>
|
|
116
|
+
<br />
|
|
117
|
+
<zn-checkbox color="secondary" checked>Secondary</zn-checkbox>
|
|
118
|
+
<br />
|
|
119
|
+
<zn-checkbox color="info" checked>Info</zn-checkbox>
|
|
120
|
+
<br />
|
|
121
|
+
<zn-checkbox color="success" checked>Success</zn-checkbox>
|
|
122
|
+
<br />
|
|
123
|
+
<zn-checkbox color="warning" checked>Warning</zn-checkbox>
|
|
124
|
+
<br />
|
|
125
|
+
<zn-checkbox color="error" checked>Error</zn-checkbox>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Checked and Unchecked Colors
|
|
129
|
+
|
|
130
|
+
Use the `checked-color` and `unchecked-color` attributes to apply different colors based on the checkbox state.
|
|
131
|
+
|
|
132
|
+
```html:preview
|
|
133
|
+
<zn-checkbox checked-color="success" unchecked-color="error" checked>Checked color (success)</zn-checkbox>
|
|
134
|
+
<br />
|
|
135
|
+
<zn-checkbox checked-color="success" unchecked-color="error">Unchecked color (error)</zn-checkbox>
|
|
136
|
+
```
|
|
22
137
|
|
|
23
138
|
### Description
|
|
24
139
|
|
|
25
|
-
Add descriptive help text to
|
|
26
|
-
|
|
140
|
+
Add descriptive help text to checkboxes with the `description` attribute. For descriptions that contain HTML, use the `description` slot instead.
|
|
141
|
+
|
|
142
|
+
```html:preview
|
|
143
|
+
<zn-checkbox description="Grants access to cash account and charge card features">Financial products access</zn-checkbox>
|
|
144
|
+
<br /><br />
|
|
145
|
+
<zn-checkbox>
|
|
146
|
+
Advanced settings
|
|
147
|
+
<div slot="description">
|
|
148
|
+
This option enables <strong>advanced features</strong> that require additional permissions.
|
|
149
|
+
</div>
|
|
150
|
+
</zn-checkbox>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Label and Label Tooltip
|
|
154
|
+
|
|
155
|
+
Use the `label` attribute to add a form control label above the checkbox. Use `label-tooltip` to provide additional context.
|
|
27
156
|
|
|
28
157
|
```html:preview
|
|
29
|
-
<zn-checkbox label="
|
|
158
|
+
<zn-checkbox label="User Preferences" label-tooltip="Configure your account settings">
|
|
159
|
+
Enable notifications
|
|
160
|
+
</zn-checkbox>
|
|
30
161
|
```
|
|
31
162
|
|
|
32
|
-
###
|
|
163
|
+
### Custom Icons
|
|
33
164
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
165
|
+
Use the `checked-icon` and `unchecked-icon` attributes to display custom icons for different states.
|
|
166
|
+
|
|
167
|
+
```html:preview
|
|
168
|
+
<zn-checkbox checked-icon="favorite" color="error" checked>Add to favorites</zn-checkbox>
|
|
169
|
+
<br />
|
|
170
|
+
<zn-checkbox checked-icon="thumb_up" unchecked-icon="thumb_down" color="success">Like this</zn-checkbox>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Contained Style
|
|
174
|
+
|
|
175
|
+
Add the `contained` attribute to draw a card-like container around a checkbox. This style is useful for giving more emphasis to a checkbox or list of checkboxes.
|
|
37
176
|
|
|
38
177
|
```html:preview
|
|
39
178
|
<zn-checkbox description="Grants access to cash account and charge card features" contained>Financial products access</zn-checkbox>
|
|
40
|
-
<br/>
|
|
41
|
-
<br/>
|
|
179
|
+
<br/><br/>
|
|
42
180
|
<zn-checkbox-group label="Financial products permissions" contained>
|
|
43
181
|
<zn-checkbox description="Requires separate initiators and approvers">Initiate outbound transfers</zn-checkbox>
|
|
44
|
-
<zn-checkbox description="Requires separate initiators and approvers">Approve outbound transfers
|
|
182
|
+
<zn-checkbox description="Requires separate initiators and approvers">Approve outbound transfers</zn-checkbox>
|
|
45
183
|
<zn-checkbox description="Applies to both cash account and charge card" disabled>Export transactions</zn-checkbox>
|
|
46
184
|
</zn-checkbox-group>
|
|
47
185
|
```
|
|
48
186
|
|
|
49
187
|
:::tip
|
|
50
|
-
When checkboxes are wrapped with [Checkbox Group](/components/checkbox-group), adding the `contained` attribute to the
|
|
51
|
-
parent Checkbox Group or to _any_ checkbox in the group will create `contained` checkboxes for the entire group.
|
|
188
|
+
When checkboxes are wrapped with [Checkbox Group](/components/checkbox-group), adding the `contained` attribute to the parent Checkbox Group or to _any_ checkbox in the group will create `contained` checkboxes for the entire group.
|
|
52
189
|
:::
|
|
53
190
|
|
|
191
|
+
### Borderless
|
|
192
|
+
|
|
193
|
+
Use the `borderless` attribute to remove borders from the checkbox.
|
|
194
|
+
|
|
195
|
+
```html:preview
|
|
196
|
+
<zn-checkbox borderless>Borderless checkbox</zn-checkbox>
|
|
197
|
+
<br />
|
|
198
|
+
<zn-checkbox borderless checked>Borderless checked</zn-checkbox>
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Horizontal Layout
|
|
202
|
+
|
|
203
|
+
Use the `horizontal` attribute to apply styles relevant to checkboxes in a horizontal layout. This is typically used with checkbox groups.
|
|
204
|
+
|
|
205
|
+
```html:preview
|
|
206
|
+
<div style="display: flex; gap: 1rem;">
|
|
207
|
+
<zn-checkbox horizontal>Option 1</zn-checkbox>
|
|
208
|
+
<zn-checkbox horizontal>Option 2</zn-checkbox>
|
|
209
|
+
<zn-checkbox horizontal>Option 3</zn-checkbox>
|
|
210
|
+
</div>
|
|
211
|
+
```
|
|
212
|
+
|
|
54
213
|
### Selected Content
|
|
55
214
|
|
|
56
|
-
Use the `selected-content` slot to display additional content (such as an input field) inside a `contained` checkbox
|
|
57
|
-
when it is checked. The slot is unstyled by default. Use `::part(selected-content)` to style the content as needed.
|
|
215
|
+
Use the `selected-content` slot to display additional content (such as an input field) inside a `contained` checkbox when it is checked. The slot is unstyled by default. Use `::part(selected-content)` to style the content as needed.
|
|
58
216
|
|
|
59
217
|
:::warning
|
|
60
|
-
**Note:** `ts_form_for` doesn't support slots. The `selected-content` slot cannot be used for checkboxes rendered with
|
|
61
|
-
`ts_form_for`.
|
|
218
|
+
**Note:** `ts_form_for` doesn't support slots. The `selected-content` slot cannot be used for checkboxes rendered with `ts_form_for`.
|
|
62
219
|
:::
|
|
63
220
|
|
|
64
221
|
```html:preview
|
|
65
222
|
<zn-checkbox style="width:100%" contained>Grant financial products access
|
|
66
223
|
<div slot="selected-content">
|
|
67
224
|
<p>A mobile number is required to grant this user access to financial products. The number will be used for login verification.</p>
|
|
68
|
-
<zn-input style="width: 280px;" label="Mobile number" type="tel" required optional-icon></
|
|
225
|
+
<zn-input style="width: 280px;" label="Mobile number" type="tel" required optional-icon></zn-input>
|
|
226
|
+
</div>
|
|
69
227
|
</zn-checkbox>
|
|
70
228
|
<style>
|
|
71
|
-
|
|
229
|
+
zn-checkbox::part(selected-content) {
|
|
72
230
|
font-size: 14px;
|
|
73
231
|
font-weight: normal;
|
|
74
232
|
color: #6D7176;
|
|
233
|
+
margin-top: 1rem;
|
|
75
234
|
}
|
|
76
235
|
</style>
|
|
77
236
|
```
|
|
78
237
|
|
|
79
|
-
###
|
|
238
|
+
### Form Integration
|
|
80
239
|
|
|
81
|
-
|
|
240
|
+
Checkboxes work seamlessly with forms and will be submitted with form data.
|
|
82
241
|
|
|
83
242
|
```html:preview
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
243
|
+
<form id="checkbox-form">
|
|
244
|
+
<zn-checkbox name="newsletter" value="yes">Subscribe to newsletter</zn-checkbox>
|
|
245
|
+
<br />
|
|
246
|
+
<zn-checkbox name="terms" value="accepted" required>I accept the terms and conditions</zn-checkbox>
|
|
247
|
+
<br /><br />
|
|
248
|
+
<zn-button type="submit" color="primary">Submit</zn-button>
|
|
249
|
+
<zn-button type="reset" color="secondary">Reset</zn-button>
|
|
250
|
+
</form>
|
|
90
251
|
|
|
91
|
-
|
|
92
|
-
|
|
252
|
+
<script type="module">
|
|
253
|
+
const form = document.querySelector('#checkbox-form');
|
|
254
|
+
form.addEventListener('submit', (event) => {
|
|
255
|
+
event.preventDefault();
|
|
256
|
+
const formData = new FormData(form);
|
|
257
|
+
const data = Object.fromEntries(formData.entries());
|
|
258
|
+
alert('Form submitted: ' + JSON.stringify(data, null, 2));
|
|
259
|
+
});
|
|
260
|
+
</script>
|
|
93
261
|
```
|
|
94
262
|
|
|
95
|
-
###
|
|
263
|
+
### Unchecked Value
|
|
96
264
|
|
|
97
|
-
Use the `
|
|
265
|
+
Use the `unchecked-value` attribute to submit a specific value when the checkbox is unchecked.
|
|
98
266
|
|
|
99
267
|
```html:preview
|
|
100
|
-
<
|
|
268
|
+
<form id="unchecked-value-form">
|
|
269
|
+
<zn-checkbox name="receive-emails" value="yes" unchecked-value="no" checked>
|
|
270
|
+
Receive email updates
|
|
271
|
+
</zn-checkbox>
|
|
272
|
+
<br /><br />
|
|
273
|
+
<zn-button type="submit" color="primary">Submit</zn-button>
|
|
274
|
+
</form>
|
|
275
|
+
|
|
276
|
+
<script type="module">
|
|
277
|
+
const form = document.querySelector('#unchecked-value-form');
|
|
278
|
+
form.addEventListener('submit', (event) => {
|
|
279
|
+
event.preventDefault();
|
|
280
|
+
const formData = new FormData(form);
|
|
281
|
+
alert('Value: ' + formData.get('receive-emails'));
|
|
282
|
+
});
|
|
283
|
+
</script>
|
|
101
284
|
```
|
|
102
285
|
|
|
103
|
-
###
|
|
286
|
+
### Required Validation
|
|
104
287
|
|
|
105
|
-
Use the `
|
|
288
|
+
Use the `required` attribute to make the checkbox required. The form will not submit unless the checkbox is checked.
|
|
106
289
|
|
|
107
290
|
```html:preview
|
|
108
|
-
<
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
<
|
|
291
|
+
<form id="required-form">
|
|
292
|
+
<zn-checkbox name="agree" required>
|
|
293
|
+
I agree to the terms and conditions
|
|
294
|
+
</zn-checkbox>
|
|
295
|
+
<br /><br />
|
|
296
|
+
<zn-button type="submit" color="primary">Submit</zn-button>
|
|
297
|
+
</form>
|
|
298
|
+
|
|
299
|
+
<script type="module">
|
|
300
|
+
const form = document.querySelector('#required-form');
|
|
301
|
+
form.addEventListener('submit', (event) => {
|
|
302
|
+
event.preventDefault();
|
|
303
|
+
alert('Form is valid!');
|
|
304
|
+
});
|
|
305
|
+
</script>
|
|
113
306
|
```
|
|
114
307
|
|
|
115
308
|
### Custom Validity
|
|
116
309
|
|
|
117
|
-
Use the `setCustomValidity()` method to set a custom validation message. This will prevent the form from submitting and
|
|
118
|
-
make the browser display the error message you provide. To clear the error, call this function with an empty string.
|
|
310
|
+
Use the `setCustomValidity()` method to set a custom validation message. This will prevent the form from submitting and make the browser display the error message you provide. To clear the error, call this function with an empty string.
|
|
119
311
|
|
|
120
312
|
```html:preview
|
|
121
|
-
|
|
122
313
|
<form class="custom-validity">
|
|
123
|
-
<zn-checkbox>
|
|
314
|
+
<zn-checkbox>I understand the risks involved</zn-checkbox>
|
|
124
315
|
<br/>
|
|
125
|
-
<zn-button type="submit"
|
|
316
|
+
<zn-button type="submit" color="primary" style="margin-top: 1rem;">Submit</zn-button>
|
|
126
317
|
</form>
|
|
127
318
|
<script type="module">
|
|
128
319
|
const form = document.querySelector('.custom-validity');
|
|
129
320
|
const checkbox = form.querySelector('zn-checkbox');
|
|
130
|
-
const errorMessage = `
|
|
321
|
+
const errorMessage = `You must acknowledge the risks before proceeding`;
|
|
131
322
|
|
|
132
323
|
// Set initial validity as soon as the element is defined
|
|
133
|
-
customElements.whenDefined('zn-checkbox').then(async () =>
|
|
134
|
-
{
|
|
324
|
+
customElements.whenDefined('zn-checkbox').then(async () => {
|
|
135
325
|
await checkbox.updateComplete;
|
|
136
326
|
checkbox.setCustomValidity(errorMessage);
|
|
137
327
|
});
|
|
138
328
|
|
|
139
329
|
// Update validity on change
|
|
140
|
-
checkbox.addEventListener('zn-change', () =>
|
|
141
|
-
{
|
|
330
|
+
checkbox.addEventListener('zn-change', () => {
|
|
142
331
|
checkbox.setCustomValidity(checkbox.checked ? '' : errorMessage);
|
|
143
332
|
});
|
|
144
333
|
|
|
145
334
|
// Wait for controls to be defined before attaching form listeners
|
|
146
335
|
await Promise.all([
|
|
147
336
|
customElements.whenDefined('zn-checkbox')
|
|
148
|
-
]).then(() =>
|
|
149
|
-
|
|
150
|
-
form.addEventListener('submit', event =>
|
|
151
|
-
{
|
|
337
|
+
]).then(() => {
|
|
338
|
+
form.addEventListener('submit', event => {
|
|
152
339
|
event.preventDefault();
|
|
153
340
|
alert('All fields are valid!');
|
|
154
341
|
});
|
|
155
342
|
});
|
|
156
343
|
</script>
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Submit on Click
|
|
347
|
+
|
|
348
|
+
Use the `submit-on-click` attribute to automatically submit the containing form when the checkbox is clicked.
|
|
349
|
+
|
|
350
|
+
```html:preview
|
|
351
|
+
<form id="submit-on-click-form">
|
|
352
|
+
<zn-checkbox name="instant" submit-on-click>
|
|
353
|
+
Apply changes immediately
|
|
354
|
+
</zn-checkbox>
|
|
355
|
+
</form>
|
|
356
|
+
|
|
357
|
+
<script type="module">
|
|
358
|
+
const form = document.querySelector('#submit-on-click-form');
|
|
359
|
+
let submitCount = 0;
|
|
360
|
+
form.addEventListener('submit', (event) => {
|
|
361
|
+
event.preventDefault();
|
|
362
|
+
submitCount++;
|
|
363
|
+
alert('Form submitted ' + submitCount + ' time(s)');
|
|
364
|
+
});
|
|
365
|
+
</script>
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### External Form Association
|
|
369
|
+
|
|
370
|
+
Use the `form` attribute to associate the checkbox with a form element by ID, even if the checkbox is not a descendant of the form.
|
|
371
|
+
|
|
372
|
+
```html:preview
|
|
373
|
+
<form id="external-form">
|
|
374
|
+
<zn-button type="submit" color="primary">Submit External Form</zn-button>
|
|
375
|
+
</form>
|
|
376
|
+
|
|
377
|
+
<br /><br />
|
|
378
|
+
|
|
379
|
+
<zn-checkbox form="external-form" name="external-option" value="selected">
|
|
380
|
+
This checkbox is associated with the form above
|
|
381
|
+
</zn-checkbox>
|
|
382
|
+
|
|
383
|
+
<script type="module">
|
|
384
|
+
const form = document.querySelector('#external-form');
|
|
385
|
+
form.addEventListener('submit', (event) => {
|
|
386
|
+
event.preventDefault();
|
|
387
|
+
const formData = new FormData(form);
|
|
388
|
+
alert('External option: ' + (formData.get('external-option') || 'not selected'));
|
|
389
|
+
});
|
|
390
|
+
</script>
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Events
|
|
394
|
+
|
|
395
|
+
Checkboxes emit several events that you can listen to:
|
|
396
|
+
|
|
397
|
+
- `zn-change` - Emitted when the checked state changes
|
|
398
|
+
- `zn-input` - Emitted when the checkbox receives input
|
|
399
|
+
- `zn-focus` - Emitted when the checkbox gains focus
|
|
400
|
+
- `zn-blur` - Emitted when the checkbox loses focus
|
|
401
|
+
- `zn-invalid` - Emitted when form validation fails
|
|
402
|
+
|
|
403
|
+
```html:preview
|
|
404
|
+
<div>
|
|
405
|
+
<zn-checkbox id="event-checkbox">Toggle me</zn-checkbox>
|
|
406
|
+
<div id="event-output" style="margin-top: 1rem; padding: 1rem; background: #f5f5f5; border-radius: 4px;">
|
|
407
|
+
<strong>Events:</strong>
|
|
408
|
+
<ul id="event-list" style="margin: 0.5rem 0 0 0; padding-left: 1.5rem;"></ul>
|
|
409
|
+
</div>
|
|
410
|
+
</div>
|
|
411
|
+
|
|
412
|
+
<script type="module">
|
|
413
|
+
const checkbox = document.querySelector('#event-checkbox');
|
|
414
|
+
const eventList = document.querySelector('#event-list');
|
|
415
|
+
|
|
416
|
+
function logEvent(eventName, detail = '') {
|
|
417
|
+
const li = document.createElement('li');
|
|
418
|
+
li.textContent = `${eventName}${detail ? ': ' + detail : ''}`;
|
|
419
|
+
eventList.insertBefore(li, eventList.firstChild);
|
|
420
|
+
|
|
421
|
+
// Keep only last 5 events
|
|
422
|
+
while (eventList.children.length > 5) {
|
|
423
|
+
eventList.removeChild(eventList.lastChild);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
checkbox.addEventListener('zn-change', (e) => {
|
|
428
|
+
logEvent('zn-change', `checked = ${e.target.checked}`);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
checkbox.addEventListener('zn-input', () => {
|
|
432
|
+
logEvent('zn-input');
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
checkbox.addEventListener('zn-focus', () => {
|
|
436
|
+
logEvent('zn-focus');
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
checkbox.addEventListener('zn-blur', () => {
|
|
440
|
+
logEvent('zn-blur');
|
|
441
|
+
});
|
|
442
|
+
</script>
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Methods
|
|
446
|
+
|
|
447
|
+
Checkboxes provide several methods for programmatic control:
|
|
448
|
+
|
|
449
|
+
- `click()` - Simulates a click on the checkbox
|
|
450
|
+
- `focus()` - Sets focus on the checkbox
|
|
451
|
+
- `blur()` - Removes focus from the checkbox
|
|
452
|
+
- `checkValidity()` - Checks validity without showing a message
|
|
453
|
+
- `reportValidity()` - Checks validity and shows the browser's validation message
|
|
454
|
+
- `setCustomValidity(message)` - Sets a custom validation message
|
|
455
|
+
|
|
456
|
+
```html:preview
|
|
457
|
+
<div>
|
|
458
|
+
<zn-checkbox id="method-checkbox">Programmatic control</zn-checkbox>
|
|
459
|
+
<br /><br />
|
|
460
|
+
<zn-button id="click-btn" size="small">Click Checkbox</zn-button>
|
|
461
|
+
<zn-button id="focus-btn" size="small" color="info">Focus Checkbox</zn-button>
|
|
462
|
+
<zn-button id="blur-btn" size="small" color="secondary">Blur Checkbox</zn-button>
|
|
463
|
+
<zn-button id="validate-btn" size="small" color="warning">Check Validity</zn-button>
|
|
464
|
+
</div>
|
|
465
|
+
|
|
466
|
+
<script type="module">
|
|
467
|
+
const checkbox = document.querySelector('#method-checkbox');
|
|
468
|
+
|
|
469
|
+
document.querySelector('#click-btn').addEventListener('click', () => {
|
|
470
|
+
checkbox.click();
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
document.querySelector('#focus-btn').addEventListener('click', () => {
|
|
474
|
+
checkbox.focus();
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
document.querySelector('#blur-btn').addEventListener('click', () => {
|
|
478
|
+
checkbox.blur();
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
document.querySelector('#validate-btn').addEventListener('click', () => {
|
|
482
|
+
const isValid = checkbox.checkValidity();
|
|
483
|
+
alert('Checkbox is ' + (isValid ? 'valid' : 'invalid'));
|
|
484
|
+
});
|
|
485
|
+
</script>
|
|
157
486
|
```
|