@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.
Files changed (79) hide show
  1. package/CHANGELOG.json +1642 -1
  2. package/CHANGELOG.md +548 -2
  3. package/Spec.md +33 -127
  4. package/dist/react-checkbox.d.ts +87 -31
  5. package/lib/components/Checkbox/Checkbox.d.ts +5 -4
  6. package/lib/components/Checkbox/Checkbox.js +10 -8
  7. package/lib/components/Checkbox/Checkbox.js.map +1 -1
  8. package/lib/components/Checkbox/Checkbox.types.d.ts +75 -15
  9. package/lib/components/Checkbox/Checkbox.types.js.map +1 -1
  10. package/lib/components/Checkbox/renderCheckbox.d.ts +1 -4
  11. package/lib/components/Checkbox/renderCheckbox.js +12 -9
  12. package/lib/components/Checkbox/renderCheckbox.js.map +1 -1
  13. package/lib/components/Checkbox/useCheckbox.d.ts +5 -10
  14. package/lib/components/Checkbox/useCheckbox.js +103 -17
  15. package/lib/components/Checkbox/useCheckbox.js.map +1 -1
  16. package/lib/components/Checkbox/useCheckboxStyles.d.ts +2 -1
  17. package/lib/components/Checkbox/useCheckboxStyles.js +204 -14
  18. package/lib/components/Checkbox/useCheckboxStyles.js.map +1 -1
  19. package/lib/tsdoc-metadata.json +1 -1
  20. package/lib-commonjs/Checkbox.js +7 -2
  21. package/lib-commonjs/Checkbox.js.map +1 -1
  22. package/lib-commonjs/components/Checkbox/Checkbox.d.ts +5 -4
  23. package/lib-commonjs/components/Checkbox/Checkbox.js +20 -10
  24. package/lib-commonjs/components/Checkbox/Checkbox.js.map +1 -1
  25. package/lib-commonjs/components/Checkbox/Checkbox.types.d.ts +75 -15
  26. package/lib-commonjs/components/Checkbox/Checkbox.types.js +4 -1
  27. package/lib-commonjs/components/Checkbox/Checkbox.types.js.map +1 -1
  28. package/lib-commonjs/components/Checkbox/index.js +11 -2
  29. package/lib-commonjs/components/Checkbox/index.js.map +1 -1
  30. package/lib-commonjs/components/Checkbox/renderCheckbox.d.ts +1 -4
  31. package/lib-commonjs/components/Checkbox/renderCheckbox.js +23 -13
  32. package/lib-commonjs/components/Checkbox/renderCheckbox.js.map +1 -1
  33. package/lib-commonjs/components/Checkbox/useCheckbox.d.ts +5 -10
  34. package/lib-commonjs/components/Checkbox/useCheckbox.js +115 -20
  35. package/lib-commonjs/components/Checkbox/useCheckbox.js.map +1 -1
  36. package/lib-commonjs/components/Checkbox/useCheckboxStyles.d.ts +2 -1
  37. package/lib-commonjs/components/Checkbox/useCheckboxStyles.js +215 -17
  38. package/lib-commonjs/components/Checkbox/useCheckboxStyles.js.map +1 -1
  39. package/lib-commonjs/index.js +7 -2
  40. package/lib-commonjs/index.js.map +1 -1
  41. package/package.json +23 -11
  42. package/config/api-extractor.json +0 -3
  43. package/config/tests.js +0 -7
  44. package/etc/react-checkbox.api.md +0 -44
  45. package/just.config.ts +0 -3
  46. package/lib/common/isConformant.d.ts +0 -4
  47. package/lib/common/isConformant.js +0 -9
  48. package/lib/common/isConformant.js.map +0 -1
  49. package/lib-amd/Checkbox.d.ts +0 -1
  50. package/lib-amd/Checkbox.js +0 -6
  51. package/lib-amd/Checkbox.js.map +0 -1
  52. package/lib-amd/common/isConformant.d.ts +0 -4
  53. package/lib-amd/common/isConformant.js +0 -14
  54. package/lib-amd/common/isConformant.js.map +0 -1
  55. package/lib-amd/components/Checkbox/Checkbox.d.ts +0 -6
  56. package/lib-amd/components/Checkbox/Checkbox.js +0 -15
  57. package/lib-amd/components/Checkbox/Checkbox.js.map +0 -1
  58. package/lib-amd/components/Checkbox/Checkbox.types.d.ts +0 -24
  59. package/lib-amd/components/Checkbox/Checkbox.types.js +0 -5
  60. package/lib-amd/components/Checkbox/Checkbox.types.js.map +0 -1
  61. package/lib-amd/components/Checkbox/index.d.ts +0 -5
  62. package/lib-amd/components/Checkbox/index.js +0 -10
  63. package/lib-amd/components/Checkbox/index.js.map +0 -1
  64. package/lib-amd/components/Checkbox/renderCheckbox.d.ts +0 -5
  65. package/lib-amd/components/Checkbox/renderCheckbox.js +0 -14
  66. package/lib-amd/components/Checkbox/renderCheckbox.js.map +0 -1
  67. package/lib-amd/components/Checkbox/useCheckbox.d.ts +0 -17
  68. package/lib-amd/components/Checkbox/useCheckbox.js +0 -30
  69. package/lib-amd/components/Checkbox/useCheckbox.js.map +0 -1
  70. package/lib-amd/components/Checkbox/useCheckboxStyles.d.ts +0 -5
  71. package/lib-amd/components/Checkbox/useCheckboxStyles.js +0 -25
  72. package/lib-amd/components/Checkbox/useCheckboxStyles.js.map +0 -1
  73. package/lib-amd/index.d.ts +0 -1
  74. package/lib-amd/index.js +0 -6
  75. package/lib-amd/index.js.map +0 -1
  76. package/lib-commonjs/common/isConformant.d.ts +0 -4
  77. package/lib-commonjs/common/isConformant.js +0 -13
  78. package/lib-commonjs/common/isConformant.js.map +0 -1
  79. 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 are used to represent one or more options, giving the user a way to select one or more of these options.
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>Example Checkbox</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">Circular Checkbox</Checkbox>
109
+ <Checkbox label="Circular Checkbox" circular size="large" />
111
110
 
112
- <Checkbox onChange={onChangeFunction}>Controlled Checkbox</Checkbox>
111
+ <Checkbox label="Controlled Checkbox" onChange={onChangeFunction} />
113
112
 
114
- <Checkbox checked="mixed">Mixed Checkbox</Checkbox>
113
+ <Checkbox label="Mixed Checkbox" checked="mixed" />
115
114
 
116
- <Checkbox>{{ children: 'Custom Label', style: { color: 'red' }, required: true }}</Chekbox>
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
- ```tsx
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
- Some feedback needed for props are:
130
+ ## Structure
212
131
 
213
- - `checked` will work similar to `aria-checked` and have `true`, `false`, and `mixed` options.
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
- ## Structure
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
- ```tsx
223
- <Checkbox>Example Checkbox</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 === 'start' && <slots.label {...slotProps.label} />}
231
- <div className={state.checkboxClassName}>
232
- <div className={state.iconClassName}>{icon}</div>
233
- <input {...inputProps} />
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
- In this case, the label position is set to end as per default.
242
-
243
- ```tsx
244
- <div {/* Root Element */}>
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
- <label for="cbox-1">
252
- Example Checkbox
253
- </label>
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
- - Keyboard
264
- - When checkbox is focused, if `space` is pressed the checkbox's state is toggled.
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
- - If a label is used with the checkbox, an `aria-label` will be set on the `input` element.
275
- - Checkbox will have a tri-state `aria-checked`.
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.
@@ -1,63 +1,119 @@
1
- import { ComponentPropsCompat } from '@fluentui/react-utilities';
2
- import { ComponentStateCompat } from '@fluentui/react-utilities';
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
- * A Checkbox component provides a way to represent options that can be selected
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: React_2.ForwardRefExoticComponent<CheckboxProps & React_2.RefAttributes<HTMLElement>>;
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
- * Checkbox Props
17
- */
18
- export declare interface CheckboxProps extends ComponentPropsCompat, React_2.HTMLAttributes<HTMLElement> {
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
- * Names of the shorthand properties in CheckboxProps
47
+ * Data for the onChange event for checkbox.
23
48
  */
24
- export declare type CheckboxShorthandProps = never;
49
+ export declare interface CheckboxOnChangeData {
50
+ checked: 'mixed' | boolean;
51
+ }
25
52
 
26
53
  /**
27
- * Array of all shorthand properties listed in CheckboxShorthandProps
54
+ * Checkbox Props
28
55
  */
29
- export declare const checkboxShorthandProps: CheckboxShorthandProps[];
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
- * Ref to the root element
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
- ref: React_2.Ref<HTMLElement>;
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
- * Render the final JSX of Checkbox
97
+ * State used in rendering Checkbox
43
98
  */
44
- export declare const renderCheckbox: (state: CheckboxState) => JSX.Element;
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 useCheckboxStyles,
50
- * before being passed to renderCheckbox.
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 root HTMLElement of Checkbox
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 useCheckbox: (props: CheckboxProps, ref: React_2.Ref<HTMLElement>, defaultProps?: CheckboxProps | undefined) => CheckboxState;
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 useCheckboxStyles: (state: CheckboxState) => CheckboxState;
117
+ export declare const useCheckboxStyles_unstable: (state: CheckboxState) => CheckboxState;
62
118
 
63
119
  export { }
@@ -1,6 +1,7 @@
1
- import * as React from 'react';
2
- import { CheckboxProps } from './Checkbox.types';
1
+ import type { CheckboxProps } from './Checkbox.types';
2
+ import type { ForwardRefComponent } from '@fluentui/react-utilities';
3
3
  /**
4
- * A Checkbox component provides a way to represent options that can be selected
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: React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLElement>>;
7
+ export declare const Checkbox: ForwardRefComponent<CheckboxProps>;
@@ -1,14 +1,16 @@
1
1
  import * as React from 'react';
2
- import { useCheckbox } from './useCheckbox';
3
- import { renderCheckbox } from './renderCheckbox';
4
- import { useCheckboxStyles } from './useCheckboxStyles';
2
+ import { useCheckbox_unstable } from './useCheckbox';
3
+ import { renderCheckbox_unstable } from './renderCheckbox';
4
+ import { useCheckboxStyles_unstable } from './useCheckboxStyles';
5
5
  /**
6
- * A Checkbox component provides a way to represent options that can be selected
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
- export var Checkbox = React.forwardRef(function (props, ref) {
9
- var state = useCheckbox(props, ref);
10
- useCheckboxStyles(state);
11
- return renderCheckbox(state);
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,"file":"Checkbox.js","sourceRoot":"../src/","sources":["components/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,IAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAA6B,UAAC,KAAK,EAAE,GAAG;IAC9E,IAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEtC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACzB,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,WAAW,GAAG,UAAU,CAAC","sourcesContent":["import * as React from 'react';\nimport { useCheckbox } from './useCheckbox';\nimport { CheckboxProps } from './Checkbox.types';\nimport { renderCheckbox } from './renderCheckbox';\nimport { useCheckboxStyles } from './useCheckboxStyles';\n\n/**\n * A Checkbox component provides a way to represent options that can be selected\n */\nexport const Checkbox = React.forwardRef<HTMLElement, CheckboxProps>((props, ref) => {\n const state = useCheckbox(props, ref);\n\n useCheckboxStyles(state);\n return renderCheckbox(state);\n});\n\nCheckbox.displayName = 'Checkbox';\n"]}
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 { ComponentPropsCompat, ComponentStateCompat } from '@fluentui/react-utilities';
3
- /**
4
- * Checkbox Props
5
- */
6
- export interface CheckboxProps extends ComponentPropsCompat, React.HTMLAttributes<HTMLElement> {
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
- * Names of the shorthand properties in CheckboxProps
34
+ * Data for the onChange event for checkbox.
10
35
  */
11
- export declare type CheckboxShorthandProps = never;
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
- * Names of CheckboxProps that have a default value in useCheckbox
64
+ * Checkbox Props
14
65
  */
15
- export declare type CheckboxDefaultedProps = never;
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 interface CheckboxState extends ComponentStateCompat<CheckboxProps, CheckboxShorthandProps, CheckboxDefaultedProps> {
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 { ComponentPropsCompat, ComponentStateCompat } from '@fluentui/react-utilities';\n\n/**\n * Checkbox Props\n */\nexport interface CheckboxProps extends ComponentPropsCompat, React.HTMLAttributes<HTMLElement> {\n /*\n * TODO Add props and slots here\n * Any slot property should be listed in the checkboxShorthandProps array below\n * Any property that has a default value should be listed in CheckboxDefaultedProps as e.g. 'size' | 'icon'\n */\n}\n\n/**\n * Names of the shorthand properties in CheckboxProps\n */\nexport type CheckboxShorthandProps = never; // TODO add shorthand property names\n\n/**\n * Names of CheckboxProps that have a default value in useCheckbox\n */\nexport type CheckboxDefaultedProps = never; // TODO add names of properties with default values\n\n/**\n * State used in rendering Checkbox\n */\nexport interface CheckboxState\n extends ComponentStateCompat<CheckboxProps, CheckboxShorthandProps, CheckboxDefaultedProps> {\n /**\n * Ref to the root element\n */\n ref: React.Ref<HTMLElement>;\n}\n"]}
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,5 +1,2 @@
1
1
  import { CheckboxState } from './Checkbox.types';
2
- /**
3
- * Render the final JSX of Checkbox
4
- */
5
- export declare const renderCheckbox: (state: CheckboxState) => JSX.Element;
2
+ export declare const renderCheckbox_unstable: (state: CheckboxState) => JSX.Element;
@@ -1,12 +1,15 @@
1
- import { __assign } from "tslib";
2
1
  import * as React from 'react';
3
- import { getSlotsCompat } from '@fluentui/react-utilities';
4
- import { checkboxShorthandProps } from './useCheckbox';
5
- /**
6
- * Render the final JSX of Checkbox
7
- */
8
- export var renderCheckbox = function (state) {
9
- var _a = getSlotsCompat(state, checkboxShorthandProps), slots = _a.slots, slotProps = _a.slotProps;
10
- return (React.createElement(slots.root, __assign({}, slotProps.root), state.children));
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,"file":"renderCheckbox.js","sourceRoot":"../src/","sources":["components/Checkbox/renderCheckbox.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD;;GAEG;AACH,MAAM,CAAC,IAAM,cAAc,GAAG,UAAC,KAAoB;IAC3C,IAAA,KAAuB,cAAc,CAAC,KAAK,EAAE,sBAAsB,CAAC,EAAlE,KAAK,WAAA,EAAE,SAAS,eAAkD,CAAC;IAE3E,OAAO,CACL,oBAAC,KAAK,CAAC,IAAI,eAAK,SAAS,CAAC,IAAI,GAE3B,KAAK,CAAC,QAAQ,CACJ,CACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport { getSlotsCompat } from '@fluentui/react-utilities';\nimport { CheckboxState } from './Checkbox.types';\nimport { checkboxShorthandProps } from './useCheckbox';\n\n/**\n * Render the final JSX of Checkbox\n */\nexport const renderCheckbox = (state: CheckboxState) => {\n const { slots, slotProps } = getSlotsCompat(state, checkboxShorthandProps);\n\n return (\n <slots.root {...slotProps.root}>\n {/* TODO Add additional slots in the appropriate place */}\n {state.children}\n </slots.root>\n );\n};\n"]}
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, CheckboxShorthandProps, CheckboxState } from './Checkbox.types';
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 useCheckboxStyles,
11
- * before being passed to renderCheckbox.
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 root HTMLElement of Checkbox
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 useCheckbox: (props: CheckboxProps, ref: React.Ref<HTMLElement>, defaultProps?: CheckboxProps | undefined) => CheckboxState;
12
+ export declare const useCheckbox_unstable: (props: CheckboxProps, ref: React.Ref<HTMLInputElement>) => CheckboxState;