@ticatec/uniface-element 0.2.3 → 0.3.0
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/dist/accordion/README.md +169 -0
- package/dist/accordion/README_CN.md +176 -0
- package/dist/action-bar/README.md +275 -0
- package/dist/action-bar/README_CN.md +285 -0
- package/dist/app-layout/README.md +374 -0
- package/dist/app-layout/README_CN.md +381 -0
- package/dist/app-top-bar/README.md +357 -0
- package/dist/app-top-bar/README_CN.md +365 -0
- package/dist/attachment-files/AttachmentFilesField.svelte +67 -1
- package/dist/attachment-files/AttachmentFilesField.svelte.d.ts +8 -1
- package/dist/base-calendar/CalendarBase.svelte +0 -3
- package/dist/box/README.md +385 -0
- package/dist/box/README_CN.md +393 -0
- package/dist/breadcrumbs/README.md +442 -0
- package/dist/breadcrumbs/README_CN.md +442 -0
- package/dist/button/Button.svelte +27 -7
- package/dist/button/Button.svelte.d.ts +3 -1
- package/dist/button/IconButton.svelte +26 -6
- package/dist/button/IconButton.svelte.d.ts +3 -1
- package/dist/button/IconButton_README.md +513 -0
- package/dist/button/IconButton_README_CN.md +513 -0
- package/dist/button/README.md +428 -0
- package/dist/button/README_CN.md +428 -0
- package/dist/button/TextButton.svelte +26 -6
- package/dist/button/TextButton.svelte.d.ts +3 -1
- package/dist/button/TextButton_README.md +571 -0
- package/dist/button/TextButton_README_CN.md +571 -0
- package/dist/card/README.md +666 -0
- package/dist/card/README_CN.md +666 -0
- package/dist/cascade-options-select/CascadeOptionSelect.svelte +43 -7
- package/dist/cascade-options-select/CascadeOptionSelect.svelte.d.ts +3 -4
- package/dist/cascade-options-select/README.md +663 -2
- package/dist/cascade-options-select/README_CN.md +664 -0
- package/dist/checkbox/CheckBox.svelte +20 -6
- package/dist/checkbox/CheckBox.svelte.d.ts +4 -2
- package/dist/checkbox/README.md +562 -0
- package/dist/checkbox/README_CN.md +727 -0
- package/dist/common-editor/NumberInput.svelte +39 -26
- package/dist/common-editor/NumberInput.svelte.d.ts +5 -1
- package/dist/concise-data-table/ConciseListTable.svelte +133 -36
- package/dist/concise-data-table/ConciseListTable.svelte.d.ts +8 -1
- package/dist/concise-data-table/DataCell.svelte +5 -6
- package/dist/concise-data-table/DataRow.svelte +22 -2
- package/dist/concise-data-table/DataRow.svelte.d.ts +1 -0
- package/dist/concise-data-table/README.md +606 -0
- package/dist/concise-data-table/README_CN.md +611 -0
- package/dist/context-menu/ContextMenu.svelte +138 -21
- package/dist/context-menu/ContextMenu.svelte.d.ts +5 -0
- package/dist/context-menu/ContextMenuItem.d.ts +20 -4
- package/dist/context-menu/README.md +551 -0
- package/dist/context-menu/README_CN.md +551 -0
- package/dist/criteria-field/CriteriaField.svelte +3 -5
- package/dist/criteria-field/README.md +532 -0
- package/dist/criteria-field/README_CN.md +532 -0
- package/dist/data-table/README.md +712 -0
- package/dist/data-table/README_CN.md +712 -0
- package/dist/date-picker/DatePicker.svelte +44 -7
- package/dist/date-picker/DatePicker.svelte.d.ts +3 -4
- package/dist/date-picker/DateTimePicker.svelte +32 -8
- package/dist/date-picker/DateTimePicker.svelte.d.ts +3 -4
- package/dist/date-picker/README.md +326 -0
- package/dist/date-picker/README_CN.md +316 -0
- package/dist/date-picker/ScrollBar.svelte +18 -8
- package/dist/date-picker/ScrollBar.svelte.d.ts +1 -1
- package/dist/date-picker/TimePanel.svelte +5 -5
- package/dist/date-picker/TimePanel.svelte.d.ts +1 -1
- package/dist/date-range/README.md +374 -0
- package/dist/date-range/README_CN.md +374 -0
- package/dist/dialog/DialogBoard.svelte +1 -1
- package/dist/dialog/README.md +596 -0
- package/dist/dialog/README_CN.md +596 -0
- package/dist/drawer/README.md +679 -1
- package/dist/drawer/README_CN.md +679 -0
- package/dist/group-box/group-check-box/GroupCheckBox.svelte +62 -5
- package/dist/group-box/group-check-box/GroupCheckBox.svelte.d.ts +7 -2
- package/dist/group-box/group-check-box/README.md +749 -0
- package/dist/group-box/group-check-box/README_CN.md +750 -0
- package/dist/group-box/group-radio-box/GroupRadioBox.svelte +69 -4
- package/dist/group-box/group-radio-box/GroupRadioBox.svelte.d.ts +8 -2
- package/dist/group-box/group-radio-box/README.md +920 -0
- package/dist/group-box/group-radio-box/README_CN.md +920 -0
- package/dist/image-files/README.md +1346 -0
- package/dist/image-files/README_CN.md +1346 -0
- package/dist/input-options-select/InputOptionsSelect.svelte +161 -65
- package/dist/input-options-select/InputOptionsSelect.svelte.d.ts +4 -1
- package/dist/lib/forwardAllEvents.d.ts +3 -0
- package/dist/lib/forwardAllEvents.js +24 -0
- package/dist/list-box/README.md +579 -0
- package/dist/list-box/README_CN.md +682 -0
- package/dist/lookup-editor/LookupEditor.svelte +15 -3
- package/dist/lookup-editor/LookupEditor.svelte.d.ts +3 -4
- package/dist/lookup-editor/README.md +684 -0
- package/dist/lookup-editor/README_CN.md +684 -0
- package/dist/memo-editor/MemoEditor.svelte +77 -27
- package/dist/memo-editor/MemoEditor.svelte.d.ts +6 -3
- package/dist/memo-editor/README.md +819 -0
- package/dist/memo-editor/README_CN.md +819 -0
- package/dist/message-box/README.md +398 -0
- package/dist/message-box/README_CN.md +398 -0
- package/dist/number-editor/NumberEditor.svelte +2 -2
- package/dist/number-editor/NumberEditor.svelte.d.ts +1 -1
- package/dist/number-editor/README.md +353 -22
- package/dist/number-editor/README_CN.md +357 -0
- package/dist/number-range/README.md +443 -0
- package/dist/number-range/README_CN.md +443 -0
- package/dist/options-multi-select/OptionsMultiSelect.svelte +87 -12
- package/dist/options-multi-select/OptionsMultiSelect.svelte.d.ts +3 -1
- package/dist/options-multi-select/README.md +480 -0
- package/dist/options-multi-select/README_CN.md +480 -0
- package/dist/options-select/OptionsSelect.svelte +36 -5
- package/dist/options-select/OptionsSelect.svelte.d.ts +3 -4
- package/dist/options-select/README.md +632 -0
- package/dist/options-select/README_CN.md +632 -0
- package/dist/page/README.md +605 -0
- package/dist/page/README_CN.md +605 -0
- package/dist/pagination/README.md +946 -0
- package/dist/pagination/README_CN.md +946 -0
- package/dist/pagination-panel/README.md +1075 -0
- package/dist/pagination-panel/README_CN.md +1075 -0
- package/dist/popup-hint/README.md +841 -0
- package/dist/popup-hint/README_CN.md +840 -0
- package/dist/progress-bar/README.md +242 -0
- package/dist/progress-bar/README_CN.md +242 -0
- package/dist/progress-step-bar/README.md +316 -0
- package/dist/progress-step-bar/README_CN.md +316 -0
- package/dist/prompts-text-editor/PromptsTextEditor.svelte +6 -3
- package/dist/prompts-text-editor/PromptsTextEditor.svelte.d.ts +3 -1
- package/dist/prompts-text-editor/README.md +329 -0
- package/dist/prompts-text-editor/README_CN.md +329 -0
- package/dist/property-editor/README.md +969 -0
- package/dist/property-editor/README_CN.md +969 -0
- package/dist/radio-button/README.md +372 -0
- package/dist/radio-button/README_CN.md +372 -0
- package/dist/radio-button/RadioButton.svelte +32 -3
- package/dist/radio-button/RadioButton.svelte.d.ts +12 -1
- package/dist/search-box/README.md +425 -0
- package/dist/search-box/README_CN.md +424 -0
- package/dist/search-box/SearchBox.svelte +22 -6
- package/dist/search-box/SearchBox.svelte.d.ts +4 -1
- package/dist/tabs/README.md +919 -0
- package/dist/tabs/README_CN.md +920 -0
- package/dist/tag/README.md +922 -0
- package/dist/tag/README_CN.md +922 -0
- package/dist/text-editor/PasswordEditor.svelte +17 -2
- package/dist/text-editor/PasswordEditor.svelte.d.ts +3 -3
- package/dist/text-editor/PasswordEditor_README.md +551 -0
- package/dist/text-editor/PasswordEditor_README_CN.md +551 -0
- package/dist/text-editor/README.md +466 -0
- package/dist/text-editor/README_CN.md +466 -0
- package/dist/text-editor/TextEditor.svelte +51 -19
- package/dist/text-editor/TextEditor.svelte.d.ts +0 -1
- package/dist/ticatec-uniface-web.css +1 -0
- package/dist/time-editor/README.md +498 -24
- package/dist/time-editor/README_CN.md +498 -0
- package/dist/time-editor/TimeEditor.svelte +7 -3
- package/dist/time-editor/TimeEditor.svelte.d.ts +3 -1
- package/dist/toast/README.md +667 -0
- package/dist/toast/README_CN.md +667 -0
- package/dist/transfer/README.md +795 -0
- package/dist/transfer/Transfer.svelte +6 -4
- package/dist/transfer/Transfer.svelte.d.ts +3 -1
- package/dist/tree-view/README.md +761 -0
- package/dist/tree-view/README_CN.md +761 -0
- package/dist/tree-view/TreeView.svelte +5 -3
- package/dist/tree-view/TreeView.svelte.d.ts +3 -1
- package/dist/unit-number-editor/README.md +546 -20
- package/dist/unit-number-editor/README_CN.md +525 -0
- package/dist/unit-number-editor/UnitNumberEditor.svelte +62 -8
- package/dist/unit-number-editor/UnitNumberEditor.svelte.d.ts +5 -1
- package/docs/form-field/cn/README_CN.md +364 -0
- package/docs/form-field/en/README.md +364 -0
- package/docs/form-panel/flex-form/cn/README_CN.md +586 -0
- package/docs/form-panel/flex-form/en/README.md +586 -0
- package/docs/form-panel/flex-row-form/cn/README_CN.md +787 -0
- package/docs/form-panel/flex-row-form/en/README.md +787 -0
- package/docs/form-panel/grid-form/en/README.md +744 -0
- package/package.json +1 -1
- package/dist/drawer/README-CN.md +0 -1
|
@@ -20,8 +20,10 @@ declare const CheckBox: $$__sveltets_2_IsomorphicComponent<{
|
|
|
20
20
|
indeterminate?: boolean;
|
|
21
21
|
style?: string;
|
|
22
22
|
compact?: boolean;
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
onclick?: ((event: MouseEvent) => void) | null;
|
|
24
|
+
onchange?: OnChangeHandler<boolean>;
|
|
25
|
+
onfocus?: ((event: FocusEvent) => void) | null;
|
|
26
|
+
onblur?: ((event: FocusEvent) => void) | null;
|
|
25
27
|
autoFocus?: boolean;
|
|
26
28
|
setFocus?: () => void;
|
|
27
29
|
}, {
|
package/dist/checkbox/README.md
CHANGED
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
# CheckBox Component
|
|
2
|
+
|
|
3
|
+
A versatile checkbox component that supports various states including indeterminate, with comprehensive event handling and accessibility features. Perfect for single selections, toggle options, and form controls.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Multiple States**: Checked, unchecked, and indeterminate states
|
|
8
|
+
- **Event Handling**: Click, change, focus, and blur event support
|
|
9
|
+
- **Accessibility**: Proper ARIA attributes and keyboard navigation
|
|
10
|
+
- **Auto Focus**: Optional automatic focus capability
|
|
11
|
+
- **Custom Styling**: Flexible styling and compact mode
|
|
12
|
+
- **Read-only & Disabled**: Support for non-interactive states
|
|
13
|
+
- **Programmatic Control**: Focus management and value control
|
|
14
|
+
|
|
15
|
+
## Basic Usage
|
|
16
|
+
|
|
17
|
+
```svelte
|
|
18
|
+
<script>
|
|
19
|
+
import CheckBox from '@ticatec/uniface-element/CheckBox';
|
|
20
|
+
|
|
21
|
+
let isChecked = false;
|
|
22
|
+
|
|
23
|
+
const handleChange = (value) => {
|
|
24
|
+
console.log('Checkbox changed:', value);
|
|
25
|
+
isChecked = value;
|
|
26
|
+
};
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<CheckBox
|
|
30
|
+
label="Accept terms and conditions"
|
|
31
|
+
bind:value={isChecked}
|
|
32
|
+
onchange={handleChange}
|
|
33
|
+
/>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Props
|
|
37
|
+
|
|
38
|
+
| Prop | Type | Default | Description |
|
|
39
|
+
|------|------|---------|-------------|
|
|
40
|
+
| `label` | `string \| null` | `null` | Text label displayed next to checkbox |
|
|
41
|
+
| `readonly` | `boolean` | `false` | Whether the checkbox is read-only |
|
|
42
|
+
| `disabled` | `boolean` | `false` | Whether the checkbox is disabled |
|
|
43
|
+
| `value` | `boolean` | `false` | Checked state of the checkbox |
|
|
44
|
+
| `indeterminate` | `boolean` | `false` | Indeterminate state (partial selection) |
|
|
45
|
+
| `style` | `string` | `''` | Custom CSS styles |
|
|
46
|
+
| `compact` | `boolean` | `false` | Compact display mode |
|
|
47
|
+
| `onclick` | `((event: MouseEvent) => void) \| null` | `null` | Click event handler |
|
|
48
|
+
| `onchange` | `OnChangeHandler<boolean>` | - | Value change event handler |
|
|
49
|
+
| `onfocus` | `((event: FocusEvent) => void) \| null` | `null` | Focus event handler |
|
|
50
|
+
| `onblur` | `((event: FocusEvent) => void) \| null` | `null` | Blur event handler |
|
|
51
|
+
| `autoFocus` | `boolean` | `false` | Whether to auto-focus on mount |
|
|
52
|
+
|
|
53
|
+
## Methods
|
|
54
|
+
|
|
55
|
+
| Method | Description |
|
|
56
|
+
|--------|-------------|
|
|
57
|
+
| `setFocus()` | Programmatically focus the checkbox |
|
|
58
|
+
|
|
59
|
+
## Basic Examples
|
|
60
|
+
|
|
61
|
+
### Simple Checkbox
|
|
62
|
+
|
|
63
|
+
```svelte
|
|
64
|
+
<script>
|
|
65
|
+
let agreed = false;
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<CheckBox
|
|
69
|
+
label="I agree to the terms"
|
|
70
|
+
bind:value={agreed}
|
|
71
|
+
/>
|
|
72
|
+
|
|
73
|
+
<p>Status: {agreed ? 'Agreed' : 'Not agreed'}</p>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### With Change Handler
|
|
77
|
+
|
|
78
|
+
```svelte
|
|
79
|
+
<script>
|
|
80
|
+
let notifications = true;
|
|
81
|
+
|
|
82
|
+
const handleNotificationChange = (value) => {
|
|
83
|
+
console.log('Notifications:', value ? 'enabled' : 'disabled');
|
|
84
|
+
notifications = value;
|
|
85
|
+
};
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<CheckBox
|
|
89
|
+
label="Enable notifications"
|
|
90
|
+
value={notifications}
|
|
91
|
+
onChange={handleNotificationChange}
|
|
92
|
+
/>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Indeterminate State
|
|
96
|
+
|
|
97
|
+
```svelte
|
|
98
|
+
<script>
|
|
99
|
+
let parentChecked = false;
|
|
100
|
+
let childItems = [
|
|
101
|
+
{ id: 1, name: 'Item 1', checked: true },
|
|
102
|
+
{ id: 2, name: 'Item 2', checked: false },
|
|
103
|
+
{ id: 3, name: 'Item 3', checked: true }
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
$: {
|
|
107
|
+
const checkedCount = childItems.filter(item => item.checked).length;
|
|
108
|
+
parentChecked = checkedCount === childItems.length;
|
|
109
|
+
parentIndeterminate = checkedCount > 0 && checkedCount < childItems.length;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const handleParentChange = (value) => {
|
|
113
|
+
childItems = childItems.map(item => ({ ...item, checked: value }));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const handleChildChange = (id) => (value) => {
|
|
117
|
+
childItems = childItems.map(item =>
|
|
118
|
+
item.id === id ? { ...item, checked: value } : item
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
</script>
|
|
122
|
+
|
|
123
|
+
<CheckBox
|
|
124
|
+
label="Select All"
|
|
125
|
+
value={parentChecked}
|
|
126
|
+
indeterminate={parentIndeterminate}
|
|
127
|
+
onChange={handleParentChange}
|
|
128
|
+
/>
|
|
129
|
+
|
|
130
|
+
{#each childItems as item}
|
|
131
|
+
<div style="margin-left: 20px;">
|
|
132
|
+
<CheckBox
|
|
133
|
+
label={item.name}
|
|
134
|
+
value={item.checked}
|
|
135
|
+
onChange={handleChildChange(item.id)}
|
|
136
|
+
/>
|
|
137
|
+
</div>
|
|
138
|
+
{/each}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Event Handling
|
|
142
|
+
|
|
143
|
+
```svelte
|
|
144
|
+
<script>
|
|
145
|
+
let value = false;
|
|
146
|
+
let focusCount = 0;
|
|
147
|
+
let clickCount = 0;
|
|
148
|
+
|
|
149
|
+
const handleChange = (newValue) => {
|
|
150
|
+
console.log('Value changed to:', newValue);
|
|
151
|
+
value = newValue;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const handleClick = (event) => {
|
|
155
|
+
clickCount++;
|
|
156
|
+
console.log('Checkbox clicked', clickCount, 'times');
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const handleFocus = (event) => {
|
|
160
|
+
focusCount++;
|
|
161
|
+
console.log('Checkbox focused');
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const handleBlur = (event) => {
|
|
165
|
+
console.log('Checkbox blurred');
|
|
166
|
+
};
|
|
167
|
+
</script>
|
|
168
|
+
|
|
169
|
+
<CheckBox
|
|
170
|
+
label="Interactive checkbox"
|
|
171
|
+
{value}
|
|
172
|
+
onchange={handleChange}
|
|
173
|
+
onclick={handleClick}
|
|
174
|
+
onfocus={handleFocus}
|
|
175
|
+
onblur={handleBlur}
|
|
176
|
+
/>
|
|
177
|
+
|
|
178
|
+
<div>
|
|
179
|
+
<p>Current value: {value}</p>
|
|
180
|
+
<p>Focus count: {focusCount}</p>
|
|
181
|
+
<p>Click count: {clickCount}</p>
|
|
182
|
+
</div>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## States and Modes
|
|
186
|
+
|
|
187
|
+
### Disabled State
|
|
188
|
+
|
|
189
|
+
```svelte
|
|
190
|
+
<CheckBox
|
|
191
|
+
label="Disabled unchecked"
|
|
192
|
+
value={false}
|
|
193
|
+
disabled={true}
|
|
194
|
+
/>
|
|
195
|
+
|
|
196
|
+
<CheckBox
|
|
197
|
+
label="Disabled checked"
|
|
198
|
+
value={true}
|
|
199
|
+
disabled={true}
|
|
200
|
+
/>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Read-only State
|
|
204
|
+
|
|
205
|
+
```svelte
|
|
206
|
+
<CheckBox
|
|
207
|
+
label="Read-only unchecked"
|
|
208
|
+
value={false}
|
|
209
|
+
readonly={true}
|
|
210
|
+
/>
|
|
211
|
+
|
|
212
|
+
<CheckBox
|
|
213
|
+
label="Read-only checked"
|
|
214
|
+
value={true}
|
|
215
|
+
readonly={true}
|
|
216
|
+
/>
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Compact Mode
|
|
220
|
+
|
|
221
|
+
```svelte
|
|
222
|
+
<div style="display: flex; gap: 16px; align-items: center;">
|
|
223
|
+
<CheckBox label="Normal" value={true} />
|
|
224
|
+
<CheckBox label="Compact" value={true} compact={true} />
|
|
225
|
+
</div>
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Auto Focus
|
|
229
|
+
|
|
230
|
+
```svelte
|
|
231
|
+
<CheckBox
|
|
232
|
+
label="Auto-focused checkbox"
|
|
233
|
+
autoFocus={true}
|
|
234
|
+
/>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Advanced Examples
|
|
238
|
+
|
|
239
|
+
### Form Integration
|
|
240
|
+
|
|
241
|
+
```svelte
|
|
242
|
+
<script>
|
|
243
|
+
let formData = {
|
|
244
|
+
newsletter: false,
|
|
245
|
+
terms: false,
|
|
246
|
+
privacy: false
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
$: canSubmit = formData.terms && formData.privacy;
|
|
250
|
+
|
|
251
|
+
const handleSubmit = () => {
|
|
252
|
+
if (canSubmit) {
|
|
253
|
+
console.log('Form submitted:', formData);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const updateField = (field) => (value) => {
|
|
258
|
+
formData = { ...formData, [field]: value };
|
|
259
|
+
};
|
|
260
|
+
</script>
|
|
261
|
+
|
|
262
|
+
<form on:submit|preventDefault={handleSubmit}>
|
|
263
|
+
<div class="form-section">
|
|
264
|
+
<CheckBox
|
|
265
|
+
label="Subscribe to newsletter (optional)"
|
|
266
|
+
value={formData.newsletter}
|
|
267
|
+
onChange={updateField('newsletter')}
|
|
268
|
+
/>
|
|
269
|
+
</div>
|
|
270
|
+
|
|
271
|
+
<div class="form-section">
|
|
272
|
+
<CheckBox
|
|
273
|
+
label="I accept the terms of service *"
|
|
274
|
+
value={formData.terms}
|
|
275
|
+
onChange={updateField('terms')}
|
|
276
|
+
/>
|
|
277
|
+
</div>
|
|
278
|
+
|
|
279
|
+
<div class="form-section">
|
|
280
|
+
<CheckBox
|
|
281
|
+
label="I accept the privacy policy *"
|
|
282
|
+
value={formData.privacy}
|
|
283
|
+
onChange={updateField('privacy')}
|
|
284
|
+
/>
|
|
285
|
+
</div>
|
|
286
|
+
|
|
287
|
+
<button type="submit" disabled={!canSubmit}>
|
|
288
|
+
Submit
|
|
289
|
+
</button>
|
|
290
|
+
</form>
|
|
291
|
+
|
|
292
|
+
<style>
|
|
293
|
+
.form-section {
|
|
294
|
+
margin: 16px 0;
|
|
295
|
+
}
|
|
296
|
+
</style>
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Settings Panel
|
|
300
|
+
|
|
301
|
+
```svelte
|
|
302
|
+
<script>
|
|
303
|
+
let settings = {
|
|
304
|
+
darkMode: false,
|
|
305
|
+
notifications: true,
|
|
306
|
+
autoSave: true,
|
|
307
|
+
soundEffects: false
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const updateSetting = (key) => (value) => {
|
|
311
|
+
settings = { ...settings, [key]: value };
|
|
312
|
+
localStorage.setItem('app-settings', JSON.stringify(settings));
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
// Load settings on mount
|
|
316
|
+
import { onMount } from 'svelte';
|
|
317
|
+
|
|
318
|
+
onMount(() => {
|
|
319
|
+
const saved = localStorage.getItem('app-settings');
|
|
320
|
+
if (saved) {
|
|
321
|
+
settings = { ...settings, ...JSON.parse(saved) };
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
</script>
|
|
325
|
+
|
|
326
|
+
<div class="settings-panel">
|
|
327
|
+
<h3>Application Settings</h3>
|
|
328
|
+
|
|
329
|
+
<div class="setting-group">
|
|
330
|
+
<h4>Appearance</h4>
|
|
331
|
+
<CheckBox
|
|
332
|
+
label="Dark mode"
|
|
333
|
+
value={settings.darkMode}
|
|
334
|
+
onChange={updateSetting('darkMode')}
|
|
335
|
+
/>
|
|
336
|
+
</div>
|
|
337
|
+
|
|
338
|
+
<div class="setting-group">
|
|
339
|
+
<h4>Notifications</h4>
|
|
340
|
+
<CheckBox
|
|
341
|
+
label="Enable notifications"
|
|
342
|
+
value={settings.notifications}
|
|
343
|
+
onChange={updateSetting('notifications')}
|
|
344
|
+
/>
|
|
345
|
+
</div>
|
|
346
|
+
|
|
347
|
+
<div class="setting-group">
|
|
348
|
+
<h4>Editor</h4>
|
|
349
|
+
<CheckBox
|
|
350
|
+
label="Auto-save documents"
|
|
351
|
+
value={settings.autoSave}
|
|
352
|
+
onChange={updateSetting('autoSave')}
|
|
353
|
+
/>
|
|
354
|
+
</div>
|
|
355
|
+
|
|
356
|
+
<div class="setting-group">
|
|
357
|
+
<h4>Audio</h4>
|
|
358
|
+
<CheckBox
|
|
359
|
+
label="Sound effects"
|
|
360
|
+
value={settings.soundEffects}
|
|
361
|
+
onChange={updateSetting('soundEffects')}
|
|
362
|
+
/>
|
|
363
|
+
</div>
|
|
364
|
+
</div>
|
|
365
|
+
|
|
366
|
+
<style>
|
|
367
|
+
.settings-panel {
|
|
368
|
+
max-width: 400px;
|
|
369
|
+
padding: 20px;
|
|
370
|
+
border: 1px solid #ddd;
|
|
371
|
+
border-radius: 8px;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
.setting-group {
|
|
375
|
+
margin: 20px 0;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
.setting-group h4 {
|
|
379
|
+
margin: 0 0 12px 0;
|
|
380
|
+
color: #666;
|
|
381
|
+
font-size: 14px;
|
|
382
|
+
text-transform: uppercase;
|
|
383
|
+
}
|
|
384
|
+
</style>
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### Todo List with Select All
|
|
388
|
+
|
|
389
|
+
```svelte
|
|
390
|
+
<script>
|
|
391
|
+
let todos = [
|
|
392
|
+
{ id: 1, text: 'Buy groceries', completed: false },
|
|
393
|
+
{ id: 2, text: 'Walk the dog', completed: true },
|
|
394
|
+
{ id: 3, text: 'Read a book', completed: false },
|
|
395
|
+
{ id: 4, text: 'Call mom', completed: true }
|
|
396
|
+
];
|
|
397
|
+
|
|
398
|
+
$: completedCount = todos.filter(todo => todo.completed).length;
|
|
399
|
+
$: allCompleted = completedCount === todos.length;
|
|
400
|
+
$: someCompleted = completedCount > 0 && completedCount < todos.length;
|
|
401
|
+
|
|
402
|
+
const toggleAll = (value) => {
|
|
403
|
+
todos = todos.map(todo => ({ ...todo, completed: value }));
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const toggleTodo = (id) => (completed) => {
|
|
407
|
+
todos = todos.map(todo =>
|
|
408
|
+
todo.id === id ? { ...todo, completed } : todo
|
|
409
|
+
);
|
|
410
|
+
};
|
|
411
|
+
</script>
|
|
412
|
+
|
|
413
|
+
<div class="todo-list">
|
|
414
|
+
<h3>Todo List</h3>
|
|
415
|
+
|
|
416
|
+
<CheckBox
|
|
417
|
+
label={`Select All (${completedCount}/${todos.length})`}
|
|
418
|
+
value={allCompleted}
|
|
419
|
+
indeterminate={someCompleted}
|
|
420
|
+
onChange={toggleAll}
|
|
421
|
+
style="border-bottom: 1px solid #ddd; padding-bottom: 12px; margin-bottom: 12px;"
|
|
422
|
+
/>
|
|
423
|
+
|
|
424
|
+
{#each todos as todo}
|
|
425
|
+
<div class="todo-item" class:completed={todo.completed}>
|
|
426
|
+
<CheckBox
|
|
427
|
+
label={todo.text}
|
|
428
|
+
value={todo.completed}
|
|
429
|
+
onChange={toggleTodo(todo.id)}
|
|
430
|
+
/>
|
|
431
|
+
</div>
|
|
432
|
+
{/each}
|
|
433
|
+
|
|
434
|
+
<div class="todo-summary">
|
|
435
|
+
{completedCount} of {todos.length} completed
|
|
436
|
+
</div>
|
|
437
|
+
</div>
|
|
438
|
+
|
|
439
|
+
<style>
|
|
440
|
+
.todo-list {
|
|
441
|
+
max-width: 400px;
|
|
442
|
+
border: 1px solid #ddd;
|
|
443
|
+
border-radius: 8px;
|
|
444
|
+
padding: 16px;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.todo-item {
|
|
448
|
+
margin: 8px 0;
|
|
449
|
+
transition: opacity 0.2s;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
.todo-item.completed {
|
|
453
|
+
opacity: 0.6;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
.todo-summary {
|
|
457
|
+
margin-top: 16px;
|
|
458
|
+
padding-top: 12px;
|
|
459
|
+
border-top: 1px solid #ddd;
|
|
460
|
+
font-size: 14px;
|
|
461
|
+
color: #666;
|
|
462
|
+
text-align: center;
|
|
463
|
+
}
|
|
464
|
+
</style>
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
## Programmatic Control
|
|
468
|
+
|
|
469
|
+
```svelte
|
|
470
|
+
<script>
|
|
471
|
+
let checkbox;
|
|
472
|
+
let value = false;
|
|
473
|
+
|
|
474
|
+
const focusCheckbox = () => {
|
|
475
|
+
checkbox?.setFocus();
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
const toggleValue = () => {
|
|
479
|
+
value = !value;
|
|
480
|
+
};
|
|
481
|
+
</script>
|
|
482
|
+
|
|
483
|
+
<div class="controls">
|
|
484
|
+
<button on:click={focusCheckbox}>Focus Checkbox</button>
|
|
485
|
+
<button on:click={toggleValue}>Toggle Value</button>
|
|
486
|
+
</div>
|
|
487
|
+
|
|
488
|
+
<CheckBox
|
|
489
|
+
bind:this={checkbox}
|
|
490
|
+
label="Programmatically controlled"
|
|
491
|
+
{value}
|
|
492
|
+
onChange={(v) => value = v}
|
|
493
|
+
/>
|
|
494
|
+
|
|
495
|
+
<style>
|
|
496
|
+
.controls {
|
|
497
|
+
margin-bottom: 16px;
|
|
498
|
+
display: flex;
|
|
499
|
+
gap: 8px;
|
|
500
|
+
}
|
|
501
|
+
</style>
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
## Custom Styling
|
|
505
|
+
|
|
506
|
+
```svelte
|
|
507
|
+
<CheckBox
|
|
508
|
+
label="Custom styled checkbox"
|
|
509
|
+
value={true}
|
|
510
|
+
style="
|
|
511
|
+
padding: 12px;
|
|
512
|
+
background: #f0f8ff;
|
|
513
|
+
border: 2px solid #007acc;
|
|
514
|
+
border-radius: 8px;
|
|
515
|
+
font-weight: 500;
|
|
516
|
+
"
|
|
517
|
+
/>
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
## Accessibility
|
|
521
|
+
|
|
522
|
+
The CheckBox component includes:
|
|
523
|
+
|
|
524
|
+
- Proper semantic `input[type="checkbox"]` element
|
|
525
|
+
- Associated label for screen readers
|
|
526
|
+
- Keyboard navigation support (Tab, Space)
|
|
527
|
+
- Focus and blur event handling
|
|
528
|
+
- Disabled state management
|
|
529
|
+
- ARIA attributes for indeterminate state
|
|
530
|
+
|
|
531
|
+
### Best Practices
|
|
532
|
+
|
|
533
|
+
```svelte
|
|
534
|
+
<!-- Good: Clear, descriptive labels -->
|
|
535
|
+
<CheckBox label="Enable two-factor authentication" />
|
|
536
|
+
|
|
537
|
+
<!-- Good: Group related checkboxes -->
|
|
538
|
+
<fieldset>
|
|
539
|
+
<legend>Notification Preferences</legend>
|
|
540
|
+
<CheckBox label="Email notifications" />
|
|
541
|
+
<CheckBox label="SMS notifications" />
|
|
542
|
+
<CheckBox label="Push notifications" />
|
|
543
|
+
</fieldset>
|
|
544
|
+
|
|
545
|
+
<!-- Good: Indicate required fields -->
|
|
546
|
+
<CheckBox label="I agree to the terms of service *" />
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
## Browser Support
|
|
550
|
+
|
|
551
|
+
Works in all modern browsers that support:
|
|
552
|
+
- ES6+ JavaScript
|
|
553
|
+
- Modern DOM APIs
|
|
554
|
+
- CSS custom properties
|
|
555
|
+
- HTML5 form elements
|
|
556
|
+
|
|
557
|
+
## Performance Considerations
|
|
558
|
+
|
|
559
|
+
- Efficient event handling with proper cleanup
|
|
560
|
+
- Minimal re-renders with reactive updates
|
|
561
|
+
- Lightweight DOM structure
|
|
562
|
+
- Optimized focus management
|