@fluentui/react-checkbox 9.0.0-beta.2 → 9.0.0-beta.6

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 (51) hide show
  1. package/CHANGELOG.json +331 -1
  2. package/CHANGELOG.md +75 -2
  3. package/Spec.md +25 -115
  4. package/dist/react-checkbox.d.ts +37 -46
  5. package/lib/components/Checkbox/Checkbox.d.ts +2 -1
  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 +29 -34
  9. package/lib/components/Checkbox/renderCheckbox.d.ts +1 -1
  10. package/lib/components/Checkbox/renderCheckbox.js +11 -10
  11. package/lib/components/Checkbox/renderCheckbox.js.map +1 -1
  12. package/lib/components/Checkbox/useCheckbox.d.ts +5 -9
  13. package/lib/components/Checkbox/useCheckbox.js +99 -68
  14. package/lib/components/Checkbox/useCheckbox.js.map +1 -1
  15. package/lib/components/Checkbox/useCheckboxStyles.d.ts +2 -1
  16. package/lib/components/Checkbox/useCheckboxStyles.js +216 -159
  17. package/lib/components/Checkbox/useCheckboxStyles.js.map +1 -1
  18. package/lib-commonjs/Checkbox.js +7 -2
  19. package/lib-commonjs/Checkbox.js.map +1 -1
  20. package/lib-commonjs/components/Checkbox/Checkbox.d.ts +2 -1
  21. package/lib-commonjs/components/Checkbox/Checkbox.js +20 -10
  22. package/lib-commonjs/components/Checkbox/Checkbox.js.map +1 -1
  23. package/lib-commonjs/components/Checkbox/Checkbox.types.d.ts +29 -34
  24. package/lib-commonjs/components/Checkbox/Checkbox.types.js +4 -1
  25. package/lib-commonjs/components/Checkbox/Checkbox.types.js.map +1 -1
  26. package/lib-commonjs/components/Checkbox/index.js +11 -2
  27. package/lib-commonjs/components/Checkbox/index.js.map +1 -1
  28. package/lib-commonjs/components/Checkbox/renderCheckbox.d.ts +1 -1
  29. package/lib-commonjs/components/Checkbox/renderCheckbox.js +23 -15
  30. package/lib-commonjs/components/Checkbox/renderCheckbox.js.map +1 -1
  31. package/lib-commonjs/components/Checkbox/useCheckbox.d.ts +5 -9
  32. package/lib-commonjs/components/Checkbox/useCheckbox.js +113 -73
  33. package/lib-commonjs/components/Checkbox/useCheckbox.js.map +1 -1
  34. package/lib-commonjs/components/Checkbox/useCheckboxStyles.d.ts +2 -1
  35. package/lib-commonjs/components/Checkbox/useCheckboxStyles.js +228 -163
  36. package/lib-commonjs/components/Checkbox/useCheckboxStyles.js.map +1 -1
  37. package/lib-commonjs/index.js +7 -2
  38. package/lib-commonjs/index.js.map +1 -1
  39. package/package.json +11 -11
  40. package/lib/common/isConformant.d.ts +0 -4
  41. package/lib/common/isConformant.js +0 -12
  42. package/lib/common/isConformant.js.map +0 -1
  43. package/lib/components/Checkbox/DefaultIcons.d.ts +0 -4
  44. package/lib/components/Checkbox/DefaultIcons.js +0 -10
  45. package/lib/components/Checkbox/DefaultIcons.js.map +0 -1
  46. package/lib-commonjs/common/isConformant.d.ts +0 -4
  47. package/lib-commonjs/common/isConformant.js +0 -16
  48. package/lib-commonjs/common/isConformant.js.map +0 -1
  49. package/lib-commonjs/components/Checkbox/DefaultIcons.d.ts +0 -4
  50. package/lib-commonjs/components/Checkbox/DefaultIcons.js +0 -17
  51. package/lib-commonjs/components/Checkbox/DefaultIcons.js.map +0 -1
@@ -1,30 +1,26 @@
1
1
  import { ComponentProps } from '@fluentui/react-utilities';
2
2
  import { ComponentState } from '@fluentui/react-utilities';
3
3
  import type { ForwardRefComponent } from '@fluentui/react-utilities';
4
- import { IntrinsicShorthandProps } from '@fluentui/react-utilities';
5
- import { LabelProps } from '@fluentui/react-label';
6
- import { ObjectShorthandProps } from '@fluentui/react-utilities';
4
+ import { Label } from '@fluentui/react-label';
7
5
  import * as React_2 from 'react';
6
+ import { Slot } from '@fluentui/react-utilities';
8
7
 
9
8
  /**
10
- * 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).
11
11
  */
12
12
  export declare const Checkbox: ForwardRefComponent<CheckboxProps>;
13
13
 
14
- /**
15
- * TODO:
16
- * - Remove as from Omit. Currently it's needed since checkbox Commons shouldn't have as.
17
- * - Instead of extending LabelProps, extend LabelCommons once it's added.
18
- */
19
- export declare interface CheckboxCommons {
14
+ export declare const checkboxClassName = "fui-Checkbox";
15
+
16
+ declare interface CheckboxCommons {
20
17
  /**
21
- * A checkbox can be rendered with a circular shape.
18
+ * Whether to render the checkbox in a circular shape instead of square.
19
+ * This variant is only recommended to be used in a tasks-style UI (checklist),
20
+ * since it otherwise could be confused for a `RadioItem`.
21
+ * @defaultvalue false
22
22
  */
23
23
  circular: boolean;
24
- /**
25
- * ID of the root element that wraps the checkbox and label.
26
- */
27
- rootId: string | undefined;
28
24
  /**
29
25
  * A checkbox's state can be controlled.
30
26
  * @defaultvalue false
@@ -32,19 +28,14 @@ export declare interface CheckboxCommons {
32
28
  checked: 'mixed' | boolean;
33
29
  /**
34
30
  * Checkbox supports two different checkbox sizes.
35
- * @defaultvalue 'medium'
31
+ * @defaultvalue medium
36
32
  */
37
33
  size: 'medium' | 'large';
38
34
  /**
39
35
  * Determines whether the label should be positioned before or after the checkbox.
40
- * @defaultvalue 'after'
36
+ * @defaultvalue after
41
37
  */
42
38
  labelPosition: 'before' | 'after';
43
- /**
44
- * Field required to pass className to container instead of input
45
- * this will be solved by https://github.com/microsoft/fluentui/pull/18983
46
- */
47
- containerClassName?: string;
48
39
  }
49
40
 
50
41
  /**
@@ -57,11 +48,11 @@ export declare interface CheckboxOnChangeData {
57
48
  /**
58
49
  * Checkbox Props
59
50
  */
60
- export declare type CheckboxProps = Omit<ComponentProps<CheckboxSlots>, 'defaultChecked'> & Partial<CheckboxCommons> & {
51
+ export declare type CheckboxProps = Omit<ComponentProps<Partial<CheckboxSlots>, 'input'>, 'size' | 'checked' | 'defaultChecked' | 'onChange'> & Partial<CheckboxCommons> & {
61
52
  /**
62
- * ID of the native element that represents the checkbox.
53
+ * Checkboxes don't support children. To add a label, use the `label` prop.
63
54
  */
64
- id?: string;
55
+ children?: never;
65
56
  /**
66
57
  * Callback to be called when the checked state value changes.
67
58
  */
@@ -70,31 +61,31 @@ export declare type CheckboxProps = Omit<ComponentProps<CheckboxSlots>, 'default
70
61
  * Whether the checkbox should be rendered as checked by default.
71
62
  */
72
63
  defaultChecked?: 'mixed' | boolean;
64
+ };
65
+
66
+ export declare type CheckboxSlots = {
73
67
  /**
74
- * Required state of the checkbox.
68
+ * The root element of the Checkbox.
69
+ *
70
+ * The root slot receives the `className` and `style` specified directly on the `<Checkbox>`.
71
+ * All other native props will be applied to the primary slot: `input`
75
72
  */
76
- required?: boolean;
73
+ root: NonNullable<Slot<'span'>>;
77
74
  /**
78
- * Disabled
75
+ * The Checkbox's label.
79
76
  */
80
- disabled?: boolean;
81
- };
82
-
83
- /**
84
- * Array of all shorthand properties listed as the keys of CheckboxSlots
85
- */
86
- export declare const checkboxShorthandProps: Array<keyof CheckboxSlots>;
87
-
88
- export declare type CheckboxSlots = {
89
- root: ObjectShorthandProps<LabelProps> | IntrinsicShorthandProps<'span'>;
77
+ label?: Slot<typeof Label>;
90
78
  /**
91
79
  * Hidden input that handles the checkbox's functionality.
80
+ *
81
+ * This is the PRIMARY slot: all native properties specified directly on `<Checkbox>` will be applied to this slot,
82
+ * except `className` and `style`, which remain on the root slot.
92
83
  */
93
- input: IntrinsicShorthandProps<'input'>;
84
+ input: NonNullable<Slot<'input'>>;
94
85
  /**
95
86
  * Renders the checkbox, with the checkmark icon as its child when checked.
96
87
  */
97
- indicator: IntrinsicShorthandProps<'div'>;
88
+ indicator: Slot<'div'>;
98
89
  };
99
90
 
100
91
  /**
@@ -102,22 +93,22 @@ export declare type CheckboxSlots = {
102
93
  */
103
94
  export declare type CheckboxState = ComponentState<CheckboxSlots> & CheckboxCommons;
104
95
 
105
- export declare const renderCheckbox: (state: CheckboxState) => JSX.Element;
96
+ export declare const renderCheckbox_unstable: (state: CheckboxState) => JSX.Element;
106
97
 
107
98
  /**
108
99
  * Create the state required to render Checkbox.
109
100
  *
110
- * The returned state can be modified with hooks such as useCheckboxStyles,
111
- * before being passed to renderCheckbox.
101
+ * The returned state can be modified with hooks such as useCheckboxStyles_unstable,
102
+ * before being passed to renderCheckbox_unstable.
112
103
  *
113
104
  * @param props - props from this instance of Checkbox
114
- * @param ref - reference to root HTMLElement of Checkbox
105
+ * @param ref - reference to `<input>` element of Checkbox
115
106
  */
116
- export declare const useCheckbox: (props: CheckboxProps, ref: React_2.Ref<HTMLElement>) => CheckboxState;
107
+ export declare const useCheckbox_unstable: (props: CheckboxProps, ref: React_2.Ref<HTMLInputElement>) => CheckboxState;
117
108
 
118
109
  /**
119
110
  * Apply styling to the Checkbox slots based on the state
120
111
  */
121
- export declare const useCheckboxStyles: (state: CheckboxState) => CheckboxState;
112
+ export declare const useCheckboxStyles_unstable: (state: CheckboxState) => CheckboxState;
122
113
 
123
114
  export { }
@@ -1,6 +1,7 @@
1
1
  import type { CheckboxProps } from './Checkbox.types';
2
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
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":"","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD;;GAEG;AACH,MAAM,CAAC,IAAM,QAAQ,GAAuC,KAAK,CAAC,UAAU,CAAC,UAAC,KAAK,EAAE,GAAG;IACtF,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"}
1
+ {"version":3,"sources":["../../../src/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","sourceRoot":""}
@@ -1,20 +1,14 @@
1
1
  import * as React from 'react';
2
- import { ComponentProps, ComponentState, IntrinsicShorthandProps, ObjectShorthandProps } from '@fluentui/react-utilities';
3
- import { LabelProps } from '@fluentui/react-label';
4
- /**
5
- * TODO:
6
- * - Remove as from Omit. Currently it's needed since checkbox Commons shouldn't have as.
7
- * - Instead of extending LabelProps, extend LabelCommons once it's added.
8
- */
9
- export interface CheckboxCommons {
2
+ import { Label } from '@fluentui/react-label';
3
+ import { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
4
+ interface CheckboxCommons {
10
5
  /**
11
- * A checkbox can be rendered with a circular shape.
6
+ * Whether to render the checkbox in a circular shape instead of square.
7
+ * This variant is only recommended to be used in a tasks-style UI (checklist),
8
+ * since it otherwise could be confused for a `RadioItem`.
9
+ * @defaultvalue false
12
10
  */
13
11
  circular: boolean;
14
- /**
15
- * ID of the root element that wraps the checkbox and label.
16
- */
17
- rootId: string | undefined;
18
12
  /**
19
13
  * A checkbox's state can be controlled.
20
14
  * @defaultvalue false
@@ -22,19 +16,14 @@ export interface CheckboxCommons {
22
16
  checked: 'mixed' | boolean;
23
17
  /**
24
18
  * Checkbox supports two different checkbox sizes.
25
- * @defaultvalue 'medium'
19
+ * @defaultvalue medium
26
20
  */
27
21
  size: 'medium' | 'large';
28
22
  /**
29
23
  * Determines whether the label should be positioned before or after the checkbox.
30
- * @defaultvalue 'after'
24
+ * @defaultvalue after
31
25
  */
32
26
  labelPosition: 'before' | 'after';
33
- /**
34
- * Field required to pass className to container instead of input
35
- * this will be solved by https://github.com/microsoft/fluentui/pull/18983
36
- */
37
- containerClassName?: string;
38
27
  }
39
28
  /**
40
29
  * Data for the onChange event for checkbox.
@@ -43,24 +32,37 @@ export interface CheckboxOnChangeData {
43
32
  checked: 'mixed' | boolean;
44
33
  }
45
34
  export declare type CheckboxSlots = {
46
- root: ObjectShorthandProps<LabelProps> | IntrinsicShorthandProps<'span'>;
35
+ /**
36
+ * The root element of the Checkbox.
37
+ *
38
+ * The root slot receives the `className` and `style` specified directly on the `<Checkbox>`.
39
+ * All other native props will be applied to the primary slot: `input`
40
+ */
41
+ root: NonNullable<Slot<'span'>>;
42
+ /**
43
+ * The Checkbox's label.
44
+ */
45
+ label?: Slot<typeof Label>;
47
46
  /**
48
47
  * Hidden input that handles the checkbox's functionality.
48
+ *
49
+ * This is the PRIMARY slot: all native properties specified directly on `<Checkbox>` will be applied to this slot,
50
+ * except `className` and `style`, which remain on the root slot.
49
51
  */
50
- input: IntrinsicShorthandProps<'input'>;
52
+ input: NonNullable<Slot<'input'>>;
51
53
  /**
52
54
  * Renders the checkbox, with the checkmark icon as its child when checked.
53
55
  */
54
- indicator: IntrinsicShorthandProps<'div'>;
56
+ indicator: Slot<'div'>;
55
57
  };
56
58
  /**
57
59
  * Checkbox Props
58
60
  */
59
- export declare type CheckboxProps = Omit<ComponentProps<CheckboxSlots>, 'defaultChecked'> & Partial<CheckboxCommons> & {
61
+ export declare type CheckboxProps = Omit<ComponentProps<Partial<CheckboxSlots>, 'input'>, 'size' | 'checked' | 'defaultChecked' | 'onChange'> & Partial<CheckboxCommons> & {
60
62
  /**
61
- * ID of the native element that represents the checkbox.
63
+ * Checkboxes don't support children. To add a label, use the `label` prop.
62
64
  */
63
- id?: string;
65
+ children?: never;
64
66
  /**
65
67
  * Callback to be called when the checked state value changes.
66
68
  */
@@ -69,16 +71,9 @@ export declare type CheckboxProps = Omit<ComponentProps<CheckboxSlots>, 'default
69
71
  * Whether the checkbox should be rendered as checked by default.
70
72
  */
71
73
  defaultChecked?: 'mixed' | boolean;
72
- /**
73
- * Required state of the checkbox.
74
- */
75
- required?: boolean;
76
- /**
77
- * Disabled
78
- */
79
- disabled?: boolean;
80
74
  };
81
75
  /**
82
76
  * State used in rendering Checkbox
83
77
  */
84
78
  export declare type CheckboxState = ComponentState<CheckboxSlots> & CheckboxCommons;
79
+ export {};
@@ -1,2 +1,2 @@
1
1
  import { CheckboxState } from './Checkbox.types';
2
- export declare const renderCheckbox: (state: CheckboxState) => JSX.Element;
2
+ export declare const renderCheckbox_unstable: (state: CheckboxState) => JSX.Element;
@@ -1,14 +1,15 @@
1
- import { __assign } from "tslib";
2
1
  import * as React from 'react';
3
2
  import { getSlots } from '@fluentui/react-utilities';
4
- import { checkboxShorthandProps } from './useCheckbox';
5
- export var renderCheckbox = function (state) {
6
- var _a = getSlots(state, checkboxShorthandProps), slots = _a.slots, slotProps = _a.slotProps;
7
- return (React.createElement(slots.root, __assign({}, slotProps.root),
8
- state.labelPosition === 'before' && slotProps.root.children,
9
- React.createElement("div", { className: state.containerClassName },
10
- React.createElement(slots.indicator, __assign({}, slotProps.indicator)),
11
- React.createElement(slots.input, __assign({}, slotProps.input))),
12
- state.labelPosition === 'after' && slotProps.root.children));
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
+ }, state.labelPosition === 'before' && slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
10
+ }), /*#__PURE__*/React.createElement(slots.indicator, { ...slotProps.indicator
11
+ }), /*#__PURE__*/React.createElement(slots.input, { ...slotProps.input
12
+ }), state.labelPosition === 'after' && slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
13
+ }));
13
14
  };
14
15
  //# sourceMappingURL=renderCheckbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderCheckbox.js","sourceRoot":"","sources":["../../../src/components/Checkbox/renderCheckbox.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,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K,SAAS,CAAC;AAAf,GAAhB,CAFF,eAGE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,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","sourceRoot":""}
@@ -1,16 +1,12 @@
1
1
  import * as React from 'react';
2
- import { CheckboxProps, CheckboxSlots, CheckboxState } from './Checkbox.types';
3
- /**
4
- * Array of all shorthand properties listed as the keys of CheckboxSlots
5
- */
6
- export declare const checkboxShorthandProps: Array<keyof CheckboxSlots>;
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
10
+ * @param ref - reference to `<input>` element of Checkbox
15
11
  */
16
- export declare const useCheckbox: (props: CheckboxProps, ref: React.Ref<HTMLElement>) => CheckboxState;
12
+ export declare const useCheckbox_unstable: (props: CheckboxProps, ref: React.Ref<HTMLInputElement>) => CheckboxState;
@@ -1,80 +1,111 @@
1
- import { __assign } from "tslib";
2
1
  import * as React from 'react';
3
- import { getNativeElementProps, resolveShorthand, useControllableState, useId, useIsomorphicLayoutEffect, useMergedRefs, useEventCallback, } from '@fluentui/react-utilities';
4
- import { Mixed12Regular, Mixed16Regular, Checkmark12Regular, Checkmark16Regular } from './DefaultIcons';
2
+ import { getPartitionedNativeProps, resolveShorthand, useControllableState, useEventCallback, useId, useIsomorphicLayoutEffect, useMergedRefs } from '@fluentui/react-utilities';
3
+ import { Checkmark12Filled, Checkmark16Filled, Square12Filled, Square16Filled, Circle12Filled, Circle16Filled } from '@fluentui/react-icons';
5
4
  import { Label } from '@fluentui/react-label';
6
- /**
7
- * Array of all shorthand properties listed as the keys of CheckboxSlots
8
- */
9
- export var checkboxShorthandProps = ['root', 'indicator', 'input'];
10
5
  /**
11
6
  * Create the state required to render Checkbox.
12
7
  *
13
- * The returned state can be modified with hooks such as useCheckboxStyles,
14
- * before being passed to renderCheckbox.
8
+ * The returned state can be modified with hooks such as useCheckboxStyles_unstable,
9
+ * before being passed to renderCheckbox_unstable.
15
10
  *
16
11
  * @param props - props from this instance of Checkbox
17
- * @param ref - reference to root HTMLElement of Checkbox
12
+ * @param ref - reference to `<input>` element of Checkbox
18
13
  */
19
- export var useCheckbox = function (props, ref) {
20
- var _a = props.disabled, disabled = _a === void 0 ? false : _a, _b = props.circular, circular = _b === void 0 ? false : _b, _c = props.required, required = _c === void 0 ? false : _c, id = props.id, rootId = props.rootId, userOnChange = props.onChange;
21
- var _d = useControllableState({
22
- defaultState: props.defaultChecked,
23
- state: props.checked,
24
- initialState: false,
25
- }), checked = _d[0], setChecked = _d[1];
26
- var inputInternalRef = React.useRef(null);
27
- var inputShorthand = resolveShorthand(props.input, {
28
- required: true,
29
- defaultProps: {
30
- disabled: disabled,
31
- type: 'checkbox',
32
- required: required,
33
- },
34
- });
35
- var state = {
36
- circular: circular,
37
- checked: checked,
38
- size: 'medium',
39
- labelPosition: 'after',
40
- rootId: rootId,
41
- components: {
42
- root: props.children !== undefined ? Label : 'span',
43
- indicator: 'div',
44
- input: 'input',
45
- },
46
- input: __assign(__assign({}, inputShorthand), { ref: useMergedRefs(inputShorthand.ref, inputInternalRef) }),
47
- indicator: resolveShorthand(props.indicator, {
48
- required: true,
49
- }),
50
- root: getNativeElementProps('div', __assign({ ref: ref }, props)),
51
- };
52
- state.input.checked = checked === true;
53
- state.checked = checked ? checked : false;
54
- if (state.indicator && !state.indicator.children) {
55
- if (state.size === 'medium') {
56
- state.indicator.children = checked === 'mixed' ? React.createElement(Mixed12Regular, null) : React.createElement(Checkmark12Regular, null);
57
- }
58
- else {
59
- state.indicator.children = checked === 'mixed' ? React.createElement(Mixed16Regular, null) : React.createElement(Checkmark16Regular, null);
60
- }
14
+
15
+ export const useCheckbox_unstable = (props, ref) => {
16
+ const {
17
+ disabled,
18
+ required,
19
+ circular = false,
20
+ size = 'medium',
21
+ labelPosition = 'after',
22
+ onChange
23
+ } = props;
24
+ const [checked, setChecked] = useControllableState({
25
+ defaultState: props.defaultChecked,
26
+ state: props.checked,
27
+ initialState: false
28
+ });
29
+ const nativeProps = getPartitionedNativeProps({
30
+ props,
31
+ primarySlotTagName: 'input',
32
+ excludedPropNames: ['checked', 'defaultChecked', 'size', 'onChange']
33
+ });
34
+ const mixed = checked === 'mixed';
35
+ const id = useId('checkbox-', nativeProps.primary.id);
36
+ let checkmarkIcon;
37
+
38
+ if (mixed) {
39
+ if (circular) {
40
+ checkmarkIcon = size === 'large' ? /*#__PURE__*/React.createElement(Circle16Filled, null) : /*#__PURE__*/React.createElement(Circle12Filled, null);
41
+ } else {
42
+ checkmarkIcon = size === 'large' ? /*#__PURE__*/React.createElement(Square16Filled, null) : /*#__PURE__*/React.createElement(Square12Filled, null);
61
43
  }
62
- var inputOnChange = state.input.onChange;
63
- state.input.onChange = useEventCallback(function (ev) {
64
- ev.stopPropagation();
65
- inputOnChange === null || inputOnChange === void 0 ? void 0 : inputOnChange(ev);
66
- var val = ev.currentTarget.indeterminate ? 'mixed' : ev.currentTarget.checked;
67
- userOnChange === null || userOnChange === void 0 ? void 0 : userOnChange(ev, { checked: val });
68
- setChecked(val);
44
+ } else {
45
+ checkmarkIcon = size === 'large' ? /*#__PURE__*/React.createElement(Checkmark16Filled, null) : /*#__PURE__*/React.createElement(Checkmark12Filled, null);
46
+ }
47
+
48
+ const state = {
49
+ circular,
50
+ checked,
51
+ size,
52
+ labelPosition,
53
+ components: {
54
+ root: 'span',
55
+ input: 'input',
56
+ indicator: 'div',
57
+ label: Label
58
+ },
59
+ root: resolveShorthand(props.root, {
60
+ required: true,
61
+ defaultProps: nativeProps.root
62
+ }),
63
+ input: resolveShorthand(props.input, {
64
+ required: true,
65
+ defaultProps: {
66
+ type: 'checkbox',
67
+ id,
68
+ ref,
69
+ checked: checked === true,
70
+ ...nativeProps.primary
71
+ }
72
+ }),
73
+ label: resolveShorthand(props.label, {
74
+ required: false,
75
+ defaultProps: {
76
+ htmlFor: id,
77
+ disabled,
78
+ required,
79
+ size: 'medium' // Even if the checkbox itself is large
80
+
81
+ }
82
+ }),
83
+ indicator: resolveShorthand(props.indicator, {
84
+ required: true,
85
+ defaultProps: {
86
+ 'aria-hidden': true,
87
+ children: checkmarkIcon
88
+ }
89
+ })
90
+ };
91
+ state.input.onChange = useEventCallback(ev => {
92
+ const val = ev.currentTarget.indeterminate ? 'mixed' : ev.currentTarget.checked;
93
+ onChange === null || onChange === void 0 ? void 0 : onChange(ev, {
94
+ checked: val
69
95
  });
70
- state.input.id = useId('checkbox-', id);
71
- state.root.id = state.rootId;
72
- var isMixed = checked === 'mixed';
73
- useIsomorphicLayoutEffect(function () {
74
- if (inputInternalRef.current) {
75
- inputInternalRef.current.indeterminate = isMixed;
76
- }
77
- }, [isMixed]);
78
- return state;
96
+ setChecked(val);
97
+ }); // Create a ref object for the input element so we can use it to set the indeterminate prop.
98
+ // Use useMergedRefs, since the ref might be undefined or a function-ref (no .current)
99
+
100
+ const inputRef = useMergedRefs(state.input.ref);
101
+ state.input.ref = inputRef; // Set the <input> element's checked and indeterminate properties based on our tri-state property.
102
+ // Since indeterminate can only be set via javascript, it has to be done in a layout effect.
103
+
104
+ useIsomorphicLayoutEffect(() => {
105
+ if (inputRef.current) {
106
+ inputRef.current.indeterminate = mixed;
107
+ }
108
+ }, [inputRef, mixed]);
109
+ return state;
79
110
  };
80
111
  //# sourceMappingURL=useCheckbox.js.map
@@ -1 +1 @@
1
- {"version":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AAY,EAAE;AACZ,uBAAe,IADH;AAEZ,QAAA,QAAQ,EAAE;AAFE;AAF6B,KAAlB;AAlCA,GAA7B;AA2CA,EAAA,KAAK,CAAC,KAAN,CAAY,QAAZ,GAAuB,gBAAgB,CAAC,EAAE,IAAG;AAC3C,UAAM,GAAG,GAAG,EAAE,CAAC,aAAH,CAAiB,aAAjB,GAAiC,OAAjC,GAA2C,EAAE,CAAC,aAAH,CAAiB,OAAxE;AACA,IAAA,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAQ,KAAA,CAAR,GAAA,QAAQ,CAAG,EAAH,EAAO;AAAE,MAAA,OAAO,EAAE;AAAX,KAAP,CAAR;AACA,IAAA,UAAU,CAAC,GAAD,CAAV;AACD,GAJsC,CAAvC,CAxE4G,CA8E5G;AACA;;AACA,QAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,KAAN,CAAY,GAAb,CAA9B;AACA,EAAA,KAAK,CAAC,KAAN,CAAY,GAAZ,GAAkB,QAAlB,CAjF4G,CAmF5G;AACA;;AACA,EAAA,yBAAyB,CAAC,MAAK;AAC7B,QAAI,QAAQ,CAAC,OAAb,EAAsB;AACpB,MAAA,QAAQ,CAAC,OAAT,CAAiB,aAAjB,GAAiC,KAAjC;AACD;AACF,GAJwB,EAItB,CAAC,QAAD,EAAW,KAAX,CAJsB,CAAzB;AAMA,SAAO,KAAP;AACD,CA5FM","sourceRoot":""}
@@ -1,5 +1,6 @@
1
1
  import { CheckboxState } from './Checkbox.types';
2
+ export declare const checkboxClassName = "fui-Checkbox";
2
3
  /**
3
4
  * Apply styling to the Checkbox slots based on the state
4
5
  */
5
- export declare const useCheckboxStyles: (state: CheckboxState) => CheckboxState;
6
+ export declare const useCheckboxStyles_unstable: (state: CheckboxState) => CheckboxState;