@fluentui/react-checkbox 9.0.0-alpha.8 → 9.0.0-beta.10
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/CHANGELOG.json +1642 -1
- package/CHANGELOG.md +548 -2
- package/Spec.md +33 -127
- package/dist/react-checkbox.d.ts +87 -31
- package/lib/components/Checkbox/Checkbox.d.ts +5 -4
- package/lib/components/Checkbox/Checkbox.js +10 -8
- package/lib/components/Checkbox/Checkbox.js.map +1 -1
- package/lib/components/Checkbox/Checkbox.types.d.ts +75 -15
- package/lib/components/Checkbox/Checkbox.types.js.map +1 -1
- package/lib/components/Checkbox/renderCheckbox.d.ts +1 -4
- package/lib/components/Checkbox/renderCheckbox.js +12 -9
- package/lib/components/Checkbox/renderCheckbox.js.map +1 -1
- package/lib/components/Checkbox/useCheckbox.d.ts +5 -10
- package/lib/components/Checkbox/useCheckbox.js +103 -17
- package/lib/components/Checkbox/useCheckbox.js.map +1 -1
- package/lib/components/Checkbox/useCheckboxStyles.d.ts +2 -1
- package/lib/components/Checkbox/useCheckboxStyles.js +204 -14
- package/lib/components/Checkbox/useCheckboxStyles.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/lib-commonjs/Checkbox.js +7 -2
- package/lib-commonjs/Checkbox.js.map +1 -1
- package/lib-commonjs/components/Checkbox/Checkbox.d.ts +5 -4
- package/lib-commonjs/components/Checkbox/Checkbox.js +20 -10
- package/lib-commonjs/components/Checkbox/Checkbox.js.map +1 -1
- package/lib-commonjs/components/Checkbox/Checkbox.types.d.ts +75 -15
- package/lib-commonjs/components/Checkbox/Checkbox.types.js +4 -1
- package/lib-commonjs/components/Checkbox/Checkbox.types.js.map +1 -1
- package/lib-commonjs/components/Checkbox/index.js +11 -2
- package/lib-commonjs/components/Checkbox/index.js.map +1 -1
- package/lib-commonjs/components/Checkbox/renderCheckbox.d.ts +1 -4
- package/lib-commonjs/components/Checkbox/renderCheckbox.js +23 -13
- package/lib-commonjs/components/Checkbox/renderCheckbox.js.map +1 -1
- package/lib-commonjs/components/Checkbox/useCheckbox.d.ts +5 -10
- package/lib-commonjs/components/Checkbox/useCheckbox.js +115 -20
- package/lib-commonjs/components/Checkbox/useCheckbox.js.map +1 -1
- package/lib-commonjs/components/Checkbox/useCheckboxStyles.d.ts +2 -1
- package/lib-commonjs/components/Checkbox/useCheckboxStyles.js +215 -17
- package/lib-commonjs/components/Checkbox/useCheckboxStyles.js.map +1 -1
- package/lib-commonjs/index.js +7 -2
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +23 -11
- package/config/api-extractor.json +0 -3
- package/config/tests.js +0 -7
- package/etc/react-checkbox.api.md +0 -44
- package/just.config.ts +0 -3
- package/lib/common/isConformant.d.ts +0 -4
- package/lib/common/isConformant.js +0 -9
- package/lib/common/isConformant.js.map +0 -1
- package/lib-amd/Checkbox.d.ts +0 -1
- package/lib-amd/Checkbox.js +0 -6
- package/lib-amd/Checkbox.js.map +0 -1
- package/lib-amd/common/isConformant.d.ts +0 -4
- package/lib-amd/common/isConformant.js +0 -14
- package/lib-amd/common/isConformant.js.map +0 -1
- package/lib-amd/components/Checkbox/Checkbox.d.ts +0 -6
- package/lib-amd/components/Checkbox/Checkbox.js +0 -15
- package/lib-amd/components/Checkbox/Checkbox.js.map +0 -1
- package/lib-amd/components/Checkbox/Checkbox.types.d.ts +0 -24
- package/lib-amd/components/Checkbox/Checkbox.types.js +0 -5
- package/lib-amd/components/Checkbox/Checkbox.types.js.map +0 -1
- package/lib-amd/components/Checkbox/index.d.ts +0 -5
- package/lib-amd/components/Checkbox/index.js +0 -10
- package/lib-amd/components/Checkbox/index.js.map +0 -1
- package/lib-amd/components/Checkbox/renderCheckbox.d.ts +0 -5
- package/lib-amd/components/Checkbox/renderCheckbox.js +0 -14
- package/lib-amd/components/Checkbox/renderCheckbox.js.map +0 -1
- package/lib-amd/components/Checkbox/useCheckbox.d.ts +0 -17
- package/lib-amd/components/Checkbox/useCheckbox.js +0 -30
- package/lib-amd/components/Checkbox/useCheckbox.js.map +0 -1
- package/lib-amd/components/Checkbox/useCheckboxStyles.d.ts +0 -5
- package/lib-amd/components/Checkbox/useCheckboxStyles.js +0 -25
- package/lib-amd/components/Checkbox/useCheckboxStyles.js.map +0 -1
- package/lib-amd/index.d.ts +0 -1
- package/lib-amd/index.js +0 -6
- package/lib-amd/index.js.map +0 -1
- package/lib-commonjs/common/isConformant.d.ts +0 -4
- package/lib-commonjs/common/isConformant.js +0 -13
- package/lib-commonjs/common/isConformant.js.map +0 -1
- package/src/components/Checkbox/Checkbox.types.ts +0 -34
package/Spec.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
## Background
|
|
4
4
|
|
|
5
|
-
Checkboxes
|
|
5
|
+
Checkboxes give people a way to select one or more items from a group, or switch between
|
|
6
|
+
two mutually exclusive options (checked or unchecked).
|
|
6
7
|
|
|
7
8
|
## Prior Art
|
|
8
9
|
|
|
@@ -101,19 +102,17 @@ Component props:
|
|
|
101
102
|
## Sample Code
|
|
102
103
|
|
|
103
104
|
```tsx
|
|
104
|
-
<Checkbox
|
|
105
|
+
<Checkbox label="Example Checkbox" />
|
|
105
106
|
|
|
106
|
-
<Checkbox>
|
|
107
|
-
<>Example Checkbox with <a href="https://www.microsoft.com">link</a></>
|
|
108
|
-
</Checkbox>
|
|
107
|
+
<Checkbox label={<>Example Checkbox with <a href="https://www.microsoft.com">link</a></>} />
|
|
109
108
|
|
|
110
|
-
<Checkbox circular size="large"
|
|
109
|
+
<Checkbox label="Circular Checkbox" circular size="large" />
|
|
111
110
|
|
|
112
|
-
<Checkbox onChange={onChangeFunction}
|
|
111
|
+
<Checkbox label="Controlled Checkbox" onChange={onChangeFunction} />
|
|
113
112
|
|
|
114
|
-
<Checkbox checked="mixed"
|
|
113
|
+
<Checkbox label="Mixed Checkbox" checked="mixed" />
|
|
115
114
|
|
|
116
|
-
<Checkbox
|
|
115
|
+
<Checkbox label={{ children: 'Custom Label', style: { color: 'red' }, required: true }} />
|
|
117
116
|
```
|
|
118
117
|
|
|
119
118
|
## Variants
|
|
@@ -126,132 +125,45 @@ Component props:
|
|
|
126
125
|
|
|
127
126
|
### Checkbox Props
|
|
128
127
|
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Checkbox Props
|
|
132
|
-
*/
|
|
133
|
-
export interface CheckboxProps extends ComponentProps, React.HTMLAttributes<HTMLElement> {
|
|
134
|
-
/**
|
|
135
|
-
* Children to be rendered as a Label.
|
|
136
|
-
*/
|
|
137
|
-
children?: ShorthandProps<LabelProps>;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Icon to be displayed when the checkbox is in the checked state.
|
|
141
|
-
*/
|
|
142
|
-
checkmarkIcon?: React.ReactElement;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Icon to be displayed when the checkbox is in the mixed state.
|
|
146
|
-
*/
|
|
147
|
-
mixedIcon?: React.ReactElement;
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Disabled state of the checkbox.
|
|
151
|
-
*/
|
|
152
|
-
disabled?: boolean;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Required state of the checkbox.
|
|
156
|
-
*/
|
|
157
|
-
required?: boolean;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* A checkbox can be rendered with a circular shape.
|
|
161
|
-
*/
|
|
162
|
-
circular?: boolean;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* A checkbox's state can be controlled.
|
|
166
|
-
* @defaultvalue false
|
|
167
|
-
*/
|
|
168
|
-
checked?: 'mixed' | boolean;
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Whether the checkbox should be rendered as checked by default.
|
|
172
|
-
*/
|
|
173
|
-
defaultChecked?: 'mixed' | boolean;
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Checkbox supports two different checkbox sizes.
|
|
177
|
-
* @defaultvalue 'medium'
|
|
178
|
-
*/
|
|
179
|
-
size?: 'medium' | 'large';
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Determines whether the label should be positioned before (start) or after (end) the checkbox.
|
|
183
|
-
* @defaultvalue 'end'
|
|
184
|
-
*/
|
|
185
|
-
labelPosition?: 'start' | 'end';
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* ID of the root element that wraps the checkbox and label.
|
|
189
|
-
*/
|
|
190
|
-
rootId?: string;
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* ID of the native element that represents the checkbox.
|
|
194
|
-
*/
|
|
195
|
-
id?: string;
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Callback to be called when the checked state value changes.
|
|
199
|
-
*/
|
|
200
|
-
onChange?: (ev?: React.FormEvent<HTMLElement | HTMLInputElement>, data?: CheckboxOnChangeData) => void;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Data for the onChange event for checkbox.
|
|
205
|
-
*/
|
|
206
|
-
export interface CheckboxOnChangeData {
|
|
207
|
-
checked?: 'mixed' | boolean;
|
|
208
|
-
}
|
|
209
|
-
```
|
|
128
|
+
See [Checkbox.types.ts](https://github.com/microsoft/fluentui/blob/master/packages/react-checkbox/src/components/Checkbox/Checkbox.types.ts)
|
|
210
129
|
|
|
211
|
-
|
|
130
|
+
## Structure
|
|
212
131
|
|
|
213
|
-
|
|
214
|
-
- A `rootId` is needed since the input and label will share an id and `rootId` will be used for the root element.
|
|
215
|
-
- To initially make the checkbox simple, both mixed and checked icons will be a `ReactElement` instead of a slot.
|
|
216
|
-
- Based on feedback, `Checkbox` will now use children for the `Label`.
|
|
132
|
+
### Slots
|
|
217
133
|
|
|
218
|
-
|
|
134
|
+
- `root`: Outermost `<span>` that contains the rest of the slots
|
|
135
|
+
- `input`: The HTML `<input type="checkbox">`. This is the **primary** slot: it receives all of the native props passed to the
|
|
136
|
+
Checkbox component. It has opacity 0 and overlaps the entire `root` slot, for hit testing.
|
|
137
|
+
- `indicator`: A `<div>` that is the visual representation of the check "box". Its child is the checkmark icon.
|
|
138
|
+
- `label`: (optional) The `<label>` describing this checkbox.
|
|
219
139
|
|
|
220
140
|
### **Public**
|
|
221
141
|
|
|
222
|
-
```
|
|
223
|
-
<Checkbox
|
|
142
|
+
```jsx
|
|
143
|
+
<Checkbox label="Example Checkbox" />
|
|
224
144
|
```
|
|
225
145
|
|
|
226
146
|
### **Internal**
|
|
227
147
|
|
|
228
148
|
```tsx
|
|
229
149
|
<slots.root {...slotProps.root}>
|
|
230
|
-
{state.labelPosition === '
|
|
231
|
-
<
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
</div>
|
|
235
|
-
{state.labelPosition === 'end' && <slots.label {...slotProps.label} />}
|
|
150
|
+
{state.labelPosition === 'before' && <slots.label {...slotProps.label} />}
|
|
151
|
+
<slots.indicator {...slotProps.indicator} />
|
|
152
|
+
<slots.input {...slotProps.input} />
|
|
153
|
+
{state.labelPosition === 'after' && <slots.label {...slotProps.label} />}
|
|
236
154
|
</slots.root>
|
|
237
155
|
```
|
|
238
156
|
|
|
239
157
|
### **DOM**
|
|
240
158
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
<
|
|
245
|
-
<div {/* Checkbox */}>
|
|
246
|
-
<div {/* Icon */}>
|
|
247
|
-
...Icon
|
|
248
|
-
</div>
|
|
249
|
-
<input id="cbox-1" type="checkbox" aria-checked="..." aria-label="..." aria-labelledby="..." aria-disabled="..." aria-posinset="..." aria-setsize="..." />
|
|
159
|
+
```html
|
|
160
|
+
<span class="fui-Checkbox root">
|
|
161
|
+
<div aria-hidden="true" class="indicator">
|
|
162
|
+
<CheckmarkRegular />
|
|
250
163
|
</div>
|
|
251
|
-
<
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
</div>
|
|
164
|
+
<input type="checkbox" id="checkbox-1" class="input" />
|
|
165
|
+
<label for="checkbox-1" className="label">Example Checkbox</label>
|
|
166
|
+
</span>
|
|
255
167
|
```
|
|
256
168
|
|
|
257
169
|
## Migration
|
|
@@ -260,17 +172,11 @@ See [MIGRATION.md](MIGRATION.md)
|
|
|
260
172
|
|
|
261
173
|
## Behaviors
|
|
262
174
|
|
|
263
|
-
-
|
|
264
|
-
|
|
265
|
-
- Cursor
|
|
266
|
-
- When clicked the checkbox's state is toggled.
|
|
267
|
-
- Focus
|
|
268
|
-
- A checkbox can be focused to interact with it using `space`.
|
|
269
|
-
- In case of a label having a link or information button, items inside the label may be focused.
|
|
175
|
+
- Checkbox inherits all of its mouse and keyboard behaviors from the native `<input type="checkbox">`. It has no special handling of clicks or keypresses for toggling beyond the native control.
|
|
176
|
+
- In case of a label having a link or information button, items inside the label may be focused.
|
|
270
177
|
|
|
271
178
|
## Accessibility
|
|
272
179
|
|
|
273
180
|
- Aria design pattern: [Checkbox](https://www.w3.org/TR/wai-aria-practices-1.2/#checkbox).
|
|
274
|
-
-
|
|
275
|
-
-
|
|
276
|
-
- Elements inside the checkbox's label can be focused if there are elements such as links and info buttons.
|
|
181
|
+
- Checkbox uses a standard HTML `<input type="checkbox">` and does not require any additional aria attributes on the input element.
|
|
182
|
+
- The checkmark indicator has `aria-hidden="true"`, as it is purely a visual representation of the state of the underlying input.
|
package/dist/react-checkbox.d.ts
CHANGED
|
@@ -1,63 +1,119 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ComponentProps } from '@fluentui/react-utilities';
|
|
2
|
+
import { ComponentState } from '@fluentui/react-utilities';
|
|
3
|
+
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
|
4
|
+
import { Label } from '@fluentui/react-label';
|
|
3
5
|
import * as React_2 from 'react';
|
|
6
|
+
import { Slot } from '@fluentui/react-utilities';
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
|
-
*
|
|
9
|
+
* Checkboxes give people a way to select one or more items from a group,
|
|
10
|
+
* or switch between two mutually exclusive options (checked or unchecked).
|
|
7
11
|
*/
|
|
8
|
-
export declare const Checkbox:
|
|
12
|
+
export declare const Checkbox: ForwardRefComponent<CheckboxProps>;
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
* Names of CheckboxProps that have a default value in useCheckbox
|
|
12
|
-
*/
|
|
13
|
-
export declare type CheckboxDefaultedProps = never;
|
|
14
|
+
export declare const checkboxClassName = "fui-Checkbox";
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
declare interface CheckboxCommons {
|
|
17
|
+
/**
|
|
18
|
+
* The shape of the checkbox indicator.
|
|
19
|
+
*
|
|
20
|
+
* The `circular` variant is only recommended to be used in a tasks-style UI (checklist),
|
|
21
|
+
* since it otherwise could be confused for a `RadioItem`.
|
|
22
|
+
*
|
|
23
|
+
* @defaultvalue square
|
|
24
|
+
*/
|
|
25
|
+
shape: 'square' | 'circular';
|
|
26
|
+
/**
|
|
27
|
+
* The controlled value for the checkbox.
|
|
28
|
+
*
|
|
29
|
+
* @defaultvalue false
|
|
30
|
+
*/
|
|
31
|
+
checked: 'mixed' | boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The size of the checkbox indicator.
|
|
34
|
+
*
|
|
35
|
+
* @defaultvalue medium
|
|
36
|
+
*/
|
|
37
|
+
size: 'medium' | 'large';
|
|
38
|
+
/**
|
|
39
|
+
* The position of the label relative to the checkbox indicator.
|
|
40
|
+
*
|
|
41
|
+
* @defaultvalue after
|
|
42
|
+
*/
|
|
43
|
+
labelPosition: 'before' | 'after';
|
|
19
44
|
}
|
|
20
45
|
|
|
21
46
|
/**
|
|
22
|
-
*
|
|
47
|
+
* Data for the onChange event for checkbox.
|
|
23
48
|
*/
|
|
24
|
-
export declare
|
|
49
|
+
export declare interface CheckboxOnChangeData {
|
|
50
|
+
checked: 'mixed' | boolean;
|
|
51
|
+
}
|
|
25
52
|
|
|
26
53
|
/**
|
|
27
|
-
*
|
|
54
|
+
* Checkbox Props
|
|
28
55
|
*/
|
|
29
|
-
export declare
|
|
56
|
+
export declare type CheckboxProps = Omit<ComponentProps<Partial<CheckboxSlots>, 'input'>, 'size' | 'checked' | 'defaultChecked' | 'onChange'> & Partial<CheckboxCommons> & {
|
|
57
|
+
/**
|
|
58
|
+
* Checkboxes don't support children. To add a label, use the `label` prop.
|
|
59
|
+
*/
|
|
60
|
+
children?: never;
|
|
61
|
+
/**
|
|
62
|
+
* Callback to be called when the checked state value changes.
|
|
63
|
+
*/
|
|
64
|
+
onChange?: (ev: React_2.FormEvent<HTMLInputElement>, data: CheckboxOnChangeData) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Whether the checkbox should be rendered as checked by default.
|
|
67
|
+
*/
|
|
68
|
+
defaultChecked?: 'mixed' | boolean;
|
|
69
|
+
};
|
|
30
70
|
|
|
31
|
-
|
|
32
|
-
* State used in rendering Checkbox
|
|
33
|
-
*/
|
|
34
|
-
export declare interface CheckboxState extends ComponentStateCompat<CheckboxProps, CheckboxShorthandProps, CheckboxDefaultedProps> {
|
|
71
|
+
export declare type CheckboxSlots = {
|
|
35
72
|
/**
|
|
36
|
-
*
|
|
73
|
+
* The root element of the Checkbox.
|
|
74
|
+
*
|
|
75
|
+
* The root slot receives the `className` and `style` specified directly on the `<Checkbox>`.
|
|
76
|
+
* All other native props will be applied to the primary slot: `input`
|
|
37
77
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
78
|
+
root: NonNullable<Slot<'span'>>;
|
|
79
|
+
/**
|
|
80
|
+
* The Checkbox's label.
|
|
81
|
+
*/
|
|
82
|
+
label?: Slot<typeof Label>;
|
|
83
|
+
/**
|
|
84
|
+
* Hidden input that handles the checkbox's functionality.
|
|
85
|
+
*
|
|
86
|
+
* This is the PRIMARY slot: all native properties specified directly on `<Checkbox>` will be applied to this slot,
|
|
87
|
+
* except `className` and `style`, which remain on the root slot.
|
|
88
|
+
*/
|
|
89
|
+
input: NonNullable<Slot<'input'>>;
|
|
90
|
+
/**
|
|
91
|
+
* The checkbox, with the checkmark icon as its child when checked.
|
|
92
|
+
*/
|
|
93
|
+
indicator: Slot<'div'>;
|
|
94
|
+
};
|
|
40
95
|
|
|
41
96
|
/**
|
|
42
|
-
*
|
|
97
|
+
* State used in rendering Checkbox
|
|
43
98
|
*/
|
|
44
|
-
export declare
|
|
99
|
+
export declare type CheckboxState = ComponentState<CheckboxSlots> & CheckboxCommons;
|
|
100
|
+
|
|
101
|
+
export declare const renderCheckbox_unstable: (state: CheckboxState) => JSX.Element;
|
|
45
102
|
|
|
46
103
|
/**
|
|
47
104
|
* Create the state required to render Checkbox.
|
|
48
105
|
*
|
|
49
|
-
* The returned state can be modified with hooks such as
|
|
50
|
-
* before being passed to
|
|
106
|
+
* The returned state can be modified with hooks such as useCheckboxStyles_unstable,
|
|
107
|
+
* before being passed to renderCheckbox_unstable.
|
|
51
108
|
*
|
|
52
109
|
* @param props - props from this instance of Checkbox
|
|
53
|
-
* @param ref - reference to
|
|
54
|
-
* @param defaultProps - (optional) default prop values provided by the implementing type
|
|
110
|
+
* @param ref - reference to `<input>` element of Checkbox
|
|
55
111
|
*/
|
|
56
|
-
export declare const
|
|
112
|
+
export declare const useCheckbox_unstable: (props: CheckboxProps, ref: React_2.Ref<HTMLInputElement>) => CheckboxState;
|
|
57
113
|
|
|
58
114
|
/**
|
|
59
115
|
* Apply styling to the Checkbox slots based on the state
|
|
60
116
|
*/
|
|
61
|
-
export declare const
|
|
117
|
+
export declare const useCheckboxStyles_unstable: (state: CheckboxState) => CheckboxState;
|
|
62
118
|
|
|
63
119
|
export { }
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import type { CheckboxProps } from './Checkbox.types';
|
|
2
|
+
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Checkboxes give people a way to select one or more items from a group,
|
|
5
|
+
* or switch between two mutually exclusive options (checked or unchecked).
|
|
5
6
|
*/
|
|
6
|
-
export declare const Checkbox:
|
|
7
|
+
export declare const Checkbox: ForwardRefComponent<CheckboxProps>;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { useCheckbox_unstable } from './useCheckbox';
|
|
3
|
+
import { renderCheckbox_unstable } from './renderCheckbox';
|
|
4
|
+
import { useCheckboxStyles_unstable } from './useCheckboxStyles';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Checkboxes give people a way to select one or more items from a group,
|
|
7
|
+
* or switch between two mutually exclusive options (checked or unchecked).
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
|
|
10
|
+
export const Checkbox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
11
|
+
const state = useCheckbox_unstable(props, ref);
|
|
12
|
+
useCheckboxStyles_unstable(state);
|
|
13
|
+
return renderCheckbox_unstable(state);
|
|
12
14
|
});
|
|
13
15
|
Checkbox.displayName = 'Checkbox';
|
|
14
16
|
//# sourceMappingURL=Checkbox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["components/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,oBAAT,QAAqC,eAArC;AACA,SAAS,uBAAT,QAAwC,kBAAxC;AACA,SAAS,0BAAT,QAA2C,qBAA3C;AAIA;;;AAGG;;AACH,OAAO,MAAM,QAAQ,gBAAuC,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;AAC1F,QAAM,KAAK,GAAG,oBAAoB,CAAC,KAAD,EAAQ,GAAR,CAAlC;AAEA,EAAA,0BAA0B,CAAC,KAAD,CAA1B;AACA,SAAO,uBAAuB,CAAC,KAAD,CAA9B;AACD,CAL2D,CAArD;AAOP,QAAQ,CAAC,WAAT,GAAuB,UAAvB","sourcesContent":["import * as React from 'react';\nimport { useCheckbox_unstable } from './useCheckbox';\nimport { renderCheckbox_unstable } from './renderCheckbox';\nimport { useCheckboxStyles_unstable } from './useCheckboxStyles';\nimport type { CheckboxProps } from './Checkbox.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\n\n/**\n * Checkboxes give people a way to select one or more items from a group,\n * or switch between two mutually exclusive options (checked or unchecked).\n */\nexport const Checkbox: ForwardRefComponent<CheckboxProps> = React.forwardRef((props, ref) => {\n const state = useCheckbox_unstable(props, ref);\n\n useCheckboxStyles_unstable(state);\n return renderCheckbox_unstable(state);\n});\n\nCheckbox.displayName = 'Checkbox';\n"],"sourceRoot":"../src/"}
|
|
@@ -1,24 +1,84 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { Label } from '@fluentui/react-label';
|
|
3
|
+
import { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
|
|
4
|
+
interface CheckboxCommons {
|
|
5
|
+
/**
|
|
6
|
+
* The shape of the checkbox indicator.
|
|
7
|
+
*
|
|
8
|
+
* The `circular` variant is only recommended to be used in a tasks-style UI (checklist),
|
|
9
|
+
* since it otherwise could be confused for a `RadioItem`.
|
|
10
|
+
*
|
|
11
|
+
* @defaultvalue square
|
|
12
|
+
*/
|
|
13
|
+
shape: 'square' | 'circular';
|
|
14
|
+
/**
|
|
15
|
+
* The controlled value for the checkbox.
|
|
16
|
+
*
|
|
17
|
+
* @defaultvalue false
|
|
18
|
+
*/
|
|
19
|
+
checked: 'mixed' | boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The size of the checkbox indicator.
|
|
22
|
+
*
|
|
23
|
+
* @defaultvalue medium
|
|
24
|
+
*/
|
|
25
|
+
size: 'medium' | 'large';
|
|
26
|
+
/**
|
|
27
|
+
* The position of the label relative to the checkbox indicator.
|
|
28
|
+
*
|
|
29
|
+
* @defaultvalue after
|
|
30
|
+
*/
|
|
31
|
+
labelPosition: 'before' | 'after';
|
|
7
32
|
}
|
|
8
33
|
/**
|
|
9
|
-
*
|
|
34
|
+
* Data for the onChange event for checkbox.
|
|
10
35
|
*/
|
|
11
|
-
export
|
|
36
|
+
export interface CheckboxOnChangeData {
|
|
37
|
+
checked: 'mixed' | boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare type CheckboxSlots = {
|
|
40
|
+
/**
|
|
41
|
+
* The root element of the Checkbox.
|
|
42
|
+
*
|
|
43
|
+
* The root slot receives the `className` and `style` specified directly on the `<Checkbox>`.
|
|
44
|
+
* All other native props will be applied to the primary slot: `input`
|
|
45
|
+
*/
|
|
46
|
+
root: NonNullable<Slot<'span'>>;
|
|
47
|
+
/**
|
|
48
|
+
* The Checkbox's label.
|
|
49
|
+
*/
|
|
50
|
+
label?: Slot<typeof Label>;
|
|
51
|
+
/**
|
|
52
|
+
* Hidden input that handles the checkbox's functionality.
|
|
53
|
+
*
|
|
54
|
+
* This is the PRIMARY slot: all native properties specified directly on `<Checkbox>` will be applied to this slot,
|
|
55
|
+
* except `className` and `style`, which remain on the root slot.
|
|
56
|
+
*/
|
|
57
|
+
input: NonNullable<Slot<'input'>>;
|
|
58
|
+
/**
|
|
59
|
+
* The checkbox, with the checkmark icon as its child when checked.
|
|
60
|
+
*/
|
|
61
|
+
indicator: Slot<'div'>;
|
|
62
|
+
};
|
|
12
63
|
/**
|
|
13
|
-
*
|
|
64
|
+
* Checkbox Props
|
|
14
65
|
*/
|
|
15
|
-
export declare type
|
|
66
|
+
export declare type CheckboxProps = Omit<ComponentProps<Partial<CheckboxSlots>, 'input'>, 'size' | 'checked' | 'defaultChecked' | 'onChange'> & Partial<CheckboxCommons> & {
|
|
67
|
+
/**
|
|
68
|
+
* Checkboxes don't support children. To add a label, use the `label` prop.
|
|
69
|
+
*/
|
|
70
|
+
children?: never;
|
|
71
|
+
/**
|
|
72
|
+
* Callback to be called when the checked state value changes.
|
|
73
|
+
*/
|
|
74
|
+
onChange?: (ev: React.FormEvent<HTMLInputElement>, data: CheckboxOnChangeData) => void;
|
|
75
|
+
/**
|
|
76
|
+
* Whether the checkbox should be rendered as checked by default.
|
|
77
|
+
*/
|
|
78
|
+
defaultChecked?: 'mixed' | boolean;
|
|
79
|
+
};
|
|
16
80
|
/**
|
|
17
81
|
* State used in rendering Checkbox
|
|
18
82
|
*/
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
* Ref to the root element
|
|
22
|
-
*/
|
|
23
|
-
ref: React.Ref<HTMLElement>;
|
|
24
|
-
}
|
|
83
|
+
export declare type CheckboxState = ComponentState<CheckboxSlots> & CheckboxCommons;
|
|
84
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.types.js","sourceRoot":"../src/","sources":["components/Checkbox/Checkbox.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"Checkbox.types.js","sourceRoot":"../src/","sources":["components/Checkbox/Checkbox.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { Label } from '@fluentui/react-label';\nimport { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\ninterface CheckboxCommons {\n /**\n * The shape of the checkbox indicator.\n *\n * The `circular` variant is only recommended to be used in a tasks-style UI (checklist),\n * since it otherwise could be confused for a `RadioItem`.\n *\n * @defaultvalue square\n */\n shape: 'square' | 'circular';\n\n /**\n * The controlled value for the checkbox.\n *\n * @defaultvalue false\n */\n checked: 'mixed' | boolean;\n\n /**\n * The size of the checkbox indicator.\n *\n * @defaultvalue medium\n */\n size: 'medium' | 'large';\n\n /**\n * The position of the label relative to the checkbox indicator.\n *\n * @defaultvalue after\n */\n labelPosition: 'before' | 'after';\n}\n\n/**\n * Data for the onChange event for checkbox.\n */\nexport interface CheckboxOnChangeData {\n checked: 'mixed' | boolean;\n}\n\nexport type CheckboxSlots = {\n /**\n * The root element of the Checkbox.\n *\n * The root slot receives the `className` and `style` specified directly on the `<Checkbox>`.\n * All other native props will be applied to the primary slot: `input`\n */\n root: NonNullable<Slot<'span'>>;\n\n /**\n * The Checkbox's label.\n */\n label?: Slot<typeof Label>;\n\n /**\n * Hidden input that handles the checkbox's functionality.\n *\n * This is the PRIMARY slot: all native properties specified directly on `<Checkbox>` will be applied to this slot,\n * except `className` and `style`, which remain on the root slot.\n */\n input: NonNullable<Slot<'input'>>;\n\n /**\n * The checkbox, with the checkmark icon as its child when checked.\n */\n indicator: Slot<'div'>;\n};\n\n/**\n * Checkbox Props\n */\nexport type CheckboxProps = Omit<\n ComponentProps<Partial<CheckboxSlots>, 'input'>,\n 'size' | 'checked' | 'defaultChecked' | 'onChange'\n> &\n Partial<CheckboxCommons> & {\n /**\n * Checkboxes don't support children. To add a label, use the `label` prop.\n */\n children?: never;\n\n /**\n * Callback to be called when the checked state value changes.\n */\n onChange?: (ev: React.FormEvent<HTMLInputElement>, data: CheckboxOnChangeData) => void;\n\n /**\n * Whether the checkbox should be rendered as checked by default.\n */\n defaultChecked?: 'mixed' | boolean;\n };\n\n/**\n * State used in rendering Checkbox\n */\nexport type CheckboxState = ComponentState<CheckboxSlots> & CheckboxCommons;\n"]}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { getSlots } from '@fluentui/react-utilities';
|
|
3
|
+
export const renderCheckbox_unstable = state => {
|
|
4
|
+
const {
|
|
5
|
+
slots,
|
|
6
|
+
slotProps
|
|
7
|
+
} = getSlots(state);
|
|
8
|
+
return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
|
9
|
+
}, /*#__PURE__*/React.createElement(slots.input, { ...slotProps.input
|
|
10
|
+
}), state.labelPosition === 'before' && slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
|
|
11
|
+
}), /*#__PURE__*/React.createElement(slots.indicator, { ...slotProps.indicator
|
|
12
|
+
}), state.labelPosition === 'after' && slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
|
|
13
|
+
}));
|
|
11
14
|
};
|
|
12
15
|
//# sourceMappingURL=renderCheckbox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["components/Checkbox/renderCheckbox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA,OAAO,MAAM,uBAAuB,GAAI,KAAD,IAAyB;AAC9D,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,QAAQ,CAAgB,KAAhB,CAArC;AAEA,sBACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;AAAf,GAAX,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CADF,EAEG,KAAK,CAAC,aAAN,KAAwB,QAAxB,IAAoC,KAAK,CAAC,KAA1C,iBAAmD,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CAFtD,eAGE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,SAAP,EAAgB,EAAA,GAAK,SAAS,CAAC;AAAf,GAAhB,CAHF,EAIG,KAAK,CAAC,aAAN,KAAwB,OAAxB,IAAmC,KAAK,CAAC,KAAzC,iBAAkD,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CAJrD,CADF;AAQD,CAXM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport { CheckboxState, CheckboxSlots } from './Checkbox.types';\n\nexport const renderCheckbox_unstable = (state: CheckboxState) => {\n const { slots, slotProps } = getSlots<CheckboxSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n <slots.input {...slotProps.input} />\n {state.labelPosition === 'before' && slots.label && <slots.label {...slotProps.label} />}\n <slots.indicator {...slotProps.indicator} />\n {state.labelPosition === 'after' && slots.label && <slots.label {...slotProps.label} />}\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { CheckboxProps,
|
|
3
|
-
/**
|
|
4
|
-
* Array of all shorthand properties listed in CheckboxShorthandProps
|
|
5
|
-
*/
|
|
6
|
-
export declare const checkboxShorthandProps: CheckboxShorthandProps[];
|
|
2
|
+
import { CheckboxProps, CheckboxState } from './Checkbox.types';
|
|
7
3
|
/**
|
|
8
4
|
* Create the state required to render Checkbox.
|
|
9
5
|
*
|
|
10
|
-
* The returned state can be modified with hooks such as
|
|
11
|
-
* before being passed to
|
|
6
|
+
* The returned state can be modified with hooks such as useCheckboxStyles_unstable,
|
|
7
|
+
* before being passed to renderCheckbox_unstable.
|
|
12
8
|
*
|
|
13
9
|
* @param props - props from this instance of Checkbox
|
|
14
|
-
* @param ref - reference to
|
|
15
|
-
* @param defaultProps - (optional) default prop values provided by the implementing type
|
|
10
|
+
* @param ref - reference to `<input>` element of Checkbox
|
|
16
11
|
*/
|
|
17
|
-
export declare const
|
|
12
|
+
export declare const useCheckbox_unstable: (props: CheckboxProps, ref: React.Ref<HTMLInputElement>) => CheckboxState;
|