1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
use ;
use ;
use component_doc;
use inject_style;
use checkbox_styles;
use crateIcon;
/// Checkbox captures an independent yes/no choice — consent flags, multi-select lists,
/// and form options that stay checked until cleared.
///
/// Bind `checked` to a boolean signal, provide a `label` for accessible naming, and reach
/// for [`Switch`](crate::Switch) instead when the setting applies immediately on toggle.
///
/// # When to use
///
/// - Consent and terms acceptance before form submit
/// - Multi-select lists where each option is independent
/// - Boolean form fields that persist until the user clears them
///
/// # Usage
///
/// 1. Create a boolean signal and pass it as `checked` for two-way binding.
/// 2. Set `label` for an adjacent clickable caption.
/// 3. Pass `value` when the checkbox participates in a named group.
/// 4. Wrap in [`Field`](crate::Field) when the control needs a field label or validation messaging.
///
/// # Boolean choice controls
///
/// When `Checkbox` is not the right fit:
///
/// - **Independent yes/no, submit with form** — `Checkbox` (this component).
/// - **Immediate on/off setting** — [`Switch`](crate::Switch) (dark mode, notifications).
/// - **Exactly one of several options** — [`Radio`](crate::Radio) inside [`RadioGroup`](crate::RadioGroup).
///
/// # Best Practices
///
/// ## Do's
///
/// * Bind `checked` with a signal or [`FormBind`](crate::FormBind) for two-way sync
/// * Provide a visible `label` or wrap in [`Field`](crate::Field) for accessible naming
/// * Use `size` to match surrounding text density
///
/// ## Don'ts
///
/// * Do not use for on/off settings that take effect immediately — prefer [`Switch`](crate::Switch)
/// * Do not use when exactly one of several options must be chosen — use [`Radio`](crate::Radio) inside [`RadioGroup`](crate::RadioGroup)
/// * Do not put `data-testid` on the component — wrap with a native element
///
/// # Examples
///
/// ## Checked
/// Checked state with an adjacent label; bind `checked` to a boolean signal for two-way sync.
/// <!-- preview -->
/// ```rust
/// let on = RwSignal::new(true);
/// view! {
/// <div data-testid="checkbox-preview">
/// <Checkbox checked=on label="Enable notifications" />
/// </div>
/// }
/// ```
///
/// ## Unchecked
/// Default off state before the user opts in; the indicator stays empty until `checked` becomes true.
/// <!-- preview -->
/// ```rust
/// let off = RwSignal::new(false);
/// view! {
/// <div data-testid="checkbox-unchecked">
/// <Checkbox checked=off label="Subscribe" />
/// </div>
/// }
/// ```
///
/// ## Disabled
/// Disabled checkboxes inside a disabled fieldset cannot be toggled.
/// <!-- preview -->
/// ```rust
/// let on = RwSignal::new(true);
/// view! {
/// <div data-testid="checkbox-disabled">
/// <fieldset disabled>
/// <Checkbox checked=on label="Disabled option" />
/// </fieldset>
/// </div>
/// }
/// ```
///
/// ## Size matrix
/// Medium and large indicator sizes for dense or prominent layouts.
/// <!-- preview -->
/// ```rust
/// use crate::{Checkbox, CheckboxSize, Flex};
/// let medium = RwSignal::new(true);
/// let large = RwSignal::new(false);
/// view! {
/// <div data-testid="checkbox-size-matrix">
/// <Flex vertical=true>
/// <div data-testid="checkbox-size-medium">
/// <Checkbox checked=medium label="Medium" />
/// </div>
/// <div data-testid="checkbox-size-large">
/// <Checkbox checked=large label="Large" size=CheckboxSize::Large />
/// </div>
/// </Flex>
/// </div>
/// }
/// ```
///
/// ## Field wrapper
/// Field supplies the form label; the checkbox keeps its own inline caption.
/// <!-- preview -->
/// ```rust
/// use crate::{Checkbox, Field};
/// let agree = RwSignal::new(false);
/// view! {
/// <div data-testid="checkbox-field">
/// <Field label="Terms" name="terms">
/// <Checkbox checked=agree label="I accept the license" />
/// </Field>
/// </div>
/// }
/// ```
]
disabled: ,
/// Called after the checked state changes with the new value.
on_change: ,
)