@fluentui/react-checkbox 9.0.0-beta.3 → 9.0.0-beta.8

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 (55) hide show
  1. package/CHANGELOG.json +311 -1
  2. package/CHANGELOG.md +73 -2
  3. package/Spec.md +25 -115
  4. package/dist/react-checkbox.d.ts +37 -46
  5. package/lib/Checkbox.js.map +1 -1
  6. package/lib/components/Checkbox/Checkbox.d.ts +2 -1
  7. package/lib/components/Checkbox/Checkbox.js +10 -8
  8. package/lib/components/Checkbox/Checkbox.js.map +1 -1
  9. package/lib/components/Checkbox/Checkbox.types.d.ts +29 -34
  10. package/lib/components/Checkbox/Checkbox.types.js.map +1 -1
  11. package/lib/components/Checkbox/index.js.map +1 -1
  12. package/lib/components/Checkbox/renderCheckbox.d.ts +1 -1
  13. package/lib/components/Checkbox/renderCheckbox.js +11 -10
  14. package/lib/components/Checkbox/renderCheckbox.js.map +1 -1
  15. package/lib/components/Checkbox/useCheckbox.d.ts +5 -9
  16. package/lib/components/Checkbox/useCheckbox.js +99 -68
  17. package/lib/components/Checkbox/useCheckbox.js.map +1 -1
  18. package/lib/components/Checkbox/useCheckboxStyles.d.ts +2 -1
  19. package/lib/components/Checkbox/useCheckboxStyles.js +216 -159
  20. package/lib/components/Checkbox/useCheckboxStyles.js.map +1 -1
  21. package/lib/index.js.map +1 -1
  22. package/lib-commonjs/Checkbox.js +7 -2
  23. package/lib-commonjs/Checkbox.js.map +1 -1
  24. package/lib-commonjs/components/Checkbox/Checkbox.d.ts +2 -1
  25. package/lib-commonjs/components/Checkbox/Checkbox.js +20 -10
  26. package/lib-commonjs/components/Checkbox/Checkbox.js.map +1 -1
  27. package/lib-commonjs/components/Checkbox/Checkbox.types.d.ts +29 -34
  28. package/lib-commonjs/components/Checkbox/Checkbox.types.js +4 -1
  29. package/lib-commonjs/components/Checkbox/Checkbox.types.js.map +1 -1
  30. package/lib-commonjs/components/Checkbox/index.js +11 -2
  31. package/lib-commonjs/components/Checkbox/index.js.map +1 -1
  32. package/lib-commonjs/components/Checkbox/renderCheckbox.d.ts +1 -1
  33. package/lib-commonjs/components/Checkbox/renderCheckbox.js +23 -15
  34. package/lib-commonjs/components/Checkbox/renderCheckbox.js.map +1 -1
  35. package/lib-commonjs/components/Checkbox/useCheckbox.d.ts +5 -9
  36. package/lib-commonjs/components/Checkbox/useCheckbox.js +113 -73
  37. package/lib-commonjs/components/Checkbox/useCheckbox.js.map +1 -1
  38. package/lib-commonjs/components/Checkbox/useCheckboxStyles.d.ts +2 -1
  39. package/lib-commonjs/components/Checkbox/useCheckboxStyles.js +228 -163
  40. package/lib-commonjs/components/Checkbox/useCheckboxStyles.js.map +1 -1
  41. package/lib-commonjs/index.js +7 -2
  42. package/lib-commonjs/index.js.map +1 -1
  43. package/package.json +11 -11
  44. package/lib/common/isConformant.d.ts +0 -4
  45. package/lib/common/isConformant.js +0 -12
  46. package/lib/common/isConformant.js.map +0 -1
  47. package/lib/components/Checkbox/DefaultIcons.d.ts +0 -4
  48. package/lib/components/Checkbox/DefaultIcons.js +0 -10
  49. package/lib/components/Checkbox/DefaultIcons.js.map +0 -1
  50. package/lib-commonjs/common/isConformant.d.ts +0 -4
  51. package/lib-commonjs/common/isConformant.js +0 -16
  52. package/lib-commonjs/common/isConformant.js.map +0 -1
  53. package/lib-commonjs/components/Checkbox/DefaultIcons.d.ts +0 -4
  54. package/lib-commonjs/components/Checkbox/DefaultIcons.js +0 -17
  55. package/lib-commonjs/components/Checkbox/DefaultIcons.js.map +0 -1
@@ -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,3 +1,6 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  //# sourceMappingURL=Checkbox.types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Checkbox.types.js","sourceRoot":"","sources":["../../../src/components/Checkbox/Checkbox.types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ const tslib_1 = /*#__PURE__*/require("tslib");
8
+
4
9
  tslib_1.__exportStar(require("./Checkbox"), exports);
10
+
5
11
  tslib_1.__exportStar(require("./Checkbox.types"), exports);
12
+
6
13
  tslib_1.__exportStar(require("./renderCheckbox"), exports);
14
+
7
15
  tslib_1.__exportStar(require("./useCheckbox"), exports);
16
+
8
17
  tslib_1.__exportStar(require("./useCheckboxStyles"), exports);
9
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Checkbox/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,2DAAiC;AACjC,2DAAiC;AACjC,wDAA8B;AAC9B,8DAAoC"}
1
+ {"version":3,"sources":["components/Checkbox/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Checkbox';\nexport * from './Checkbox.types';\nexport * from './renderCheckbox';\nexport * from './useCheckbox';\nexport * from './useCheckboxStyles';\n"],"sourceRoot":"../src/"}
@@ -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,18 +1,26 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderCheckbox = void 0;
4
- var tslib_1 = require("tslib");
5
- var React = require("react");
6
- var react_utilities_1 = require("@fluentui/react-utilities");
7
- var useCheckbox_1 = require("./useCheckbox");
8
- var renderCheckbox = function (state) {
9
- var _a = react_utilities_1.getSlots(state, useCheckbox_1.checkboxShorthandProps), slots = _a.slots, slotProps = _a.slotProps;
10
- return (React.createElement(slots.root, tslib_1.__assign({}, slotProps.root),
11
- state.labelPosition === 'before' && slotProps.root.children,
12
- React.createElement("div", { className: state.containerClassName },
13
- React.createElement(slots.indicator, tslib_1.__assign({}, slotProps.indicator)),
14
- React.createElement(slots.input, tslib_1.__assign({}, slotProps.input))),
15
- state.labelPosition === 'after' && slotProps.root.children));
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.renderCheckbox_unstable = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
+
12
+ const renderCheckbox_unstable = state => {
13
+ const {
14
+ slots,
15
+ slotProps
16
+ } = react_utilities_1.getSlots(state);
17
+ return React.createElement(slots.root, { ...slotProps.root
18
+ }, state.labelPosition === 'before' && slots.label && React.createElement(slots.label, { ...slotProps.label
19
+ }), React.createElement(slots.indicator, { ...slotProps.indicator
20
+ }), React.createElement(slots.input, { ...slotProps.input
21
+ }), state.labelPosition === 'after' && slots.label && React.createElement(slots.label, { ...slotProps.label
22
+ }));
16
23
  };
17
- exports.renderCheckbox = renderCheckbox;
24
+
25
+ exports.renderCheckbox_unstable = renderCheckbox_unstable;
18
26
  //# sourceMappingURL=renderCheckbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderCheckbox.js","sourceRoot":"","sources":["../../../src/components/Checkbox/renderCheckbox.tsx"],"names":[],"mappings":";;;;AAAA,6BAA+B;AAC/B,6DAAqD;AAErD,6CAAuD;AAEhD,IAAM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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,IAAkD,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CAJrD,CADF;AAQD,CAXM;;AAAM,OAAA,CAAA,uBAAA,GAAuB,uBAAvB","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 {state.labelPosition === 'before' && slots.label && <slots.label {...slotProps.label} />}\n <slots.indicator {...slotProps.indicator} />\n <slots.input {...slotProps.input} />\n {state.labelPosition === 'after' && slots.label && <slots.label {...slotProps.label} />}\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
@@ -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,84 +1,124 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useCheckbox = exports.checkboxShorthandProps = void 0;
4
- var tslib_1 = require("tslib");
5
- var React = require("react");
6
- var react_utilities_1 = require("@fluentui/react-utilities");
7
- var DefaultIcons_1 = require("./DefaultIcons");
8
- var react_label_1 = require("@fluentui/react-label");
9
- /**
10
- * Array of all shorthand properties listed as the keys of CheckboxSlots
11
- */
12
- exports.checkboxShorthandProps = ['root', 'indicator', 'input'];
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useCheckbox_unstable = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
+
12
+ const react_icons_1 = /*#__PURE__*/require("@fluentui/react-icons");
13
+
14
+ const react_label_1 = /*#__PURE__*/require("@fluentui/react-label");
13
15
  /**
14
16
  * Create the state required to render Checkbox.
15
17
  *
16
- * The returned state can be modified with hooks such as useCheckboxStyles,
17
- * before being passed to renderCheckbox.
18
+ * The returned state can be modified with hooks such as useCheckboxStyles_unstable,
19
+ * before being passed to renderCheckbox_unstable.
18
20
  *
19
21
  * @param props - props from this instance of Checkbox
20
- * @param ref - reference to root HTMLElement of Checkbox
22
+ * @param ref - reference to `<input>` element of Checkbox
21
23
  */
22
- var useCheckbox = function (props, ref) {
23
- 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;
24
- var _d = react_utilities_1.useControllableState({
25
- defaultState: props.defaultChecked,
26
- state: props.checked,
27
- initialState: false,
28
- }), checked = _d[0], setChecked = _d[1];
29
- var inputInternalRef = React.useRef(null);
30
- var inputShorthand = react_utilities_1.resolveShorthand(props.input, {
31
- required: true,
32
- defaultProps: {
33
- disabled: disabled,
34
- type: 'checkbox',
35
- required: required,
36
- },
37
- });
38
- var state = {
39
- circular: circular,
40
- checked: checked,
41
- size: 'medium',
42
- labelPosition: 'after',
43
- rootId: rootId,
44
- components: {
45
- root: props.children !== undefined ? react_label_1.Label : 'span',
46
- indicator: 'div',
47
- input: 'input',
48
- },
49
- input: tslib_1.__assign(tslib_1.__assign({}, inputShorthand), { ref: react_utilities_1.useMergedRefs(inputShorthand.ref, inputInternalRef) }),
50
- indicator: react_utilities_1.resolveShorthand(props.indicator, {
51
- required: true,
52
- }),
53
- root: react_utilities_1.getNativeElementProps('div', tslib_1.__assign({ ref: ref }, props)),
54
- };
55
- state.input.checked = checked === true;
56
- state.checked = checked ? checked : false;
57
- if (state.indicator && !state.indicator.children) {
58
- if (state.size === 'medium') {
59
- state.indicator.children = checked === 'mixed' ? React.createElement(DefaultIcons_1.Mixed12Regular, null) : React.createElement(DefaultIcons_1.Checkmark12Regular, null);
60
- }
61
- else {
62
- state.indicator.children = checked === 'mixed' ? React.createElement(DefaultIcons_1.Mixed16Regular, null) : React.createElement(DefaultIcons_1.Checkmark16Regular, null);
63
- }
24
+
25
+
26
+ const useCheckbox_unstable = (props, ref) => {
27
+ const {
28
+ disabled,
29
+ required,
30
+ circular = false,
31
+ size = 'medium',
32
+ labelPosition = 'after',
33
+ onChange
34
+ } = props;
35
+ const [checked, setChecked] = react_utilities_1.useControllableState({
36
+ defaultState: props.defaultChecked,
37
+ state: props.checked,
38
+ initialState: false
39
+ });
40
+ const nativeProps = react_utilities_1.getPartitionedNativeProps({
41
+ props,
42
+ primarySlotTagName: 'input',
43
+ excludedPropNames: ['checked', 'defaultChecked', 'size', 'onChange']
44
+ });
45
+ const mixed = checked === 'mixed';
46
+ const id = react_utilities_1.useId('checkbox-', nativeProps.primary.id);
47
+ let checkmarkIcon;
48
+
49
+ if (mixed) {
50
+ if (circular) {
51
+ checkmarkIcon = size === 'large' ? React.createElement(react_icons_1.Circle16Filled, null) : React.createElement(react_icons_1.Circle12Filled, null);
52
+ } else {
53
+ checkmarkIcon = size === 'large' ? React.createElement(react_icons_1.Square16Filled, null) : React.createElement(react_icons_1.Square12Filled, null);
64
54
  }
65
- var inputOnChange = state.input.onChange;
66
- state.input.onChange = react_utilities_1.useEventCallback(function (ev) {
67
- ev.stopPropagation();
68
- inputOnChange === null || inputOnChange === void 0 ? void 0 : inputOnChange(ev);
69
- var val = ev.currentTarget.indeterminate ? 'mixed' : ev.currentTarget.checked;
70
- userOnChange === null || userOnChange === void 0 ? void 0 : userOnChange(ev, { checked: val });
71
- setChecked(val);
55
+ } else {
56
+ checkmarkIcon = size === 'large' ? React.createElement(react_icons_1.Checkmark16Filled, null) : React.createElement(react_icons_1.Checkmark12Filled, null);
57
+ }
58
+
59
+ const state = {
60
+ circular,
61
+ checked,
62
+ size,
63
+ labelPosition,
64
+ components: {
65
+ root: 'span',
66
+ input: 'input',
67
+ indicator: 'div',
68
+ label: react_label_1.Label
69
+ },
70
+ root: react_utilities_1.resolveShorthand(props.root, {
71
+ required: true,
72
+ defaultProps: nativeProps.root
73
+ }),
74
+ input: react_utilities_1.resolveShorthand(props.input, {
75
+ required: true,
76
+ defaultProps: {
77
+ type: 'checkbox',
78
+ id,
79
+ ref,
80
+ checked: checked === true,
81
+ ...nativeProps.primary
82
+ }
83
+ }),
84
+ label: react_utilities_1.resolveShorthand(props.label, {
85
+ required: false,
86
+ defaultProps: {
87
+ htmlFor: id,
88
+ disabled,
89
+ required,
90
+ size: 'medium' // Even if the checkbox itself is large
91
+
92
+ }
93
+ }),
94
+ indicator: react_utilities_1.resolveShorthand(props.indicator, {
95
+ required: true,
96
+ defaultProps: {
97
+ 'aria-hidden': true,
98
+ children: checkmarkIcon
99
+ }
100
+ })
101
+ };
102
+ state.input.onChange = react_utilities_1.useEventCallback(ev => {
103
+ const val = ev.currentTarget.indeterminate ? 'mixed' : ev.currentTarget.checked;
104
+ onChange === null || onChange === void 0 ? void 0 : onChange(ev, {
105
+ checked: val
72
106
  });
73
- state.input.id = react_utilities_1.useId('checkbox-', id);
74
- state.root.id = state.rootId;
75
- var isMixed = checked === 'mixed';
76
- react_utilities_1.useIsomorphicLayoutEffect(function () {
77
- if (inputInternalRef.current) {
78
- inputInternalRef.current.indeterminate = isMixed;
79
- }
80
- }, [isMixed]);
81
- return state;
107
+ setChecked(val);
108
+ }); // Create a ref object for the input element so we can use it to set the indeterminate prop.
109
+ // Use useMergedRefs, since the ref might be undefined or a function-ref (no .current)
110
+
111
+ const inputRef = react_utilities_1.useMergedRefs(state.input.ref);
112
+ state.input.ref = inputRef; // Set the <input> element's checked and indeterminate properties based on our tri-state property.
113
+ // Since indeterminate can only be set via javascript, it has to be done in a layout effect.
114
+
115
+ react_utilities_1.useIsomorphicLayoutEffect(() => {
116
+ if (inputRef.current) {
117
+ inputRef.current.indeterminate = mixed;
118
+ }
119
+ }, [inputRef, mixed]);
120
+ return state;
82
121
  };
83
- exports.useCheckbox = useCheckbox;
122
+
123
+ exports.useCheckbox_unstable = useCheckbox_unstable;
84
124
  //# sourceMappingURL=useCheckbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCheckbox.js","sourceRoot":"","sources":["../../../src/components/Checkbox/useCheckbox.tsx"],"names":[],"mappings":";;;;AAAA,6BAA+B;AAC/B,6DAQmC;AAEnC,+CAAwG;AACxG,qDAA0D;AAE1D;;GAEG;AACU,QAAA,sBAAsB,GAA+B,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AAEjG;;;;;;;;GAQG;AACI,IAAM,WAAW,GAAG,UAAC,KAAoB,EAAE,GAA2B;IACnE,IAAA,KAA6F,KAAK,SAAlF,EAAhB,QAAQ,mBAAG,KAAK,KAAA,EAAE,KAA2E,KAAK,SAAhE,EAAhB,QAAQ,mBAAG,KAAK,KAAA,EAAE,KAAyD,KAAK,SAA9C,EAAhB,QAAQ,mBAAG,KAAK,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AA1B,CAAjB;AACA,EAAA,KAAK,CAAC,KAAN,CAAY,GAAZ,GAAkB,QAAlB,CAjF4G,CAmF5G;AACA;;AACA,EAAA,iBAAA,CAAA,yBAAA,CAA0B,MAAK;AAC7B,QAAI,QAAQ,CAAC,OAAb,EAAsB;AACpB,MAAA,QAAQ,CAAC,OAAT,CAAiB,aAAjB,GAAiC,KAAjC;AACD;AACF,GAJD,EAIG,CAAC,QAAD,EAAW,KAAX,CAJH;AAMA,SAAO,KAAP;AACD,CA5FM;;AAAM,OAAA,CAAA,oBAAA,GAAoB,oBAApB","sourcesContent":["import * as React from 'react';\nimport {\n getPartitionedNativeProps,\n resolveShorthand,\n useControllableState,\n useEventCallback,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport { CheckboxProps, CheckboxState } from './Checkbox.types';\nimport {\n Checkmark12Filled,\n Checkmark16Filled,\n Square12Filled,\n Square16Filled,\n Circle12Filled,\n Circle16Filled,\n} from '@fluentui/react-icons';\nimport { Label } from '@fluentui/react-label';\n\n/**\n * Create the state required to render Checkbox.\n *\n * The returned state can be modified with hooks such as useCheckboxStyles_unstable,\n * before being passed to renderCheckbox_unstable.\n *\n * @param props - props from this instance of Checkbox\n * @param ref - reference to `<input>` element of Checkbox\n */\nexport const useCheckbox_unstable = (props: CheckboxProps, ref: React.Ref<HTMLInputElement>): CheckboxState => {\n const { disabled, required, circular = false, size = 'medium', labelPosition = 'after', onChange } = props;\n\n const [checked, setChecked] = useControllableState({\n defaultState: props.defaultChecked,\n state: props.checked,\n initialState: false,\n });\n\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['checked', 'defaultChecked', 'size', 'onChange'],\n });\n\n const mixed = checked === 'mixed';\n const id = useId('checkbox-', nativeProps.primary.id);\n\n let checkmarkIcon;\n if (mixed) {\n if (circular) {\n checkmarkIcon = size === 'large' ? <Circle16Filled /> : <Circle12Filled />;\n } else {\n checkmarkIcon = size === 'large' ? <Square16Filled /> : <Square12Filled />;\n }\n } else {\n checkmarkIcon = size === 'large' ? <Checkmark16Filled /> : <Checkmark12Filled />;\n }\n\n const state: CheckboxState = {\n circular,\n checked,\n size,\n labelPosition,\n components: {\n root: 'span',\n input: 'input',\n indicator: 'div',\n label: Label,\n },\n root: resolveShorthand(props.root, {\n required: true,\n defaultProps: nativeProps.root,\n }),\n input: resolveShorthand(props.input, {\n required: true,\n defaultProps: {\n type: 'checkbox',\n id,\n ref,\n checked: checked === true,\n ...nativeProps.primary,\n },\n }),\n label: resolveShorthand(props.label, {\n required: false,\n defaultProps: {\n htmlFor: id,\n disabled,\n required,\n size: 'medium', // Even if the checkbox itself is large\n },\n }),\n indicator: resolveShorthand(props.indicator, {\n required: true,\n defaultProps: {\n 'aria-hidden': true,\n children: checkmarkIcon,\n },\n }),\n };\n\n state.input.onChange = useEventCallback(ev => {\n const val = ev.currentTarget.indeterminate ? 'mixed' : ev.currentTarget.checked;\n onChange?.(ev, { checked: val });\n setChecked(val);\n });\n\n // Create a ref object for the input element so we can use it to set the indeterminate prop.\n // Use useMergedRefs, since the ref might be undefined or a function-ref (no .current)\n const inputRef = useMergedRefs(state.input.ref);\n state.input.ref = inputRef;\n\n // Set the <input> element's checked and indeterminate properties based on our tri-state property.\n // Since indeterminate can only be set via javascript, it has to be done in a layout effect.\n useIsomorphicLayoutEffect(() => {\n if (inputRef.current) {\n inputRef.current.indeterminate = mixed;\n }\n }, [inputRef, mixed]);\n\n return state;\n};\n"],"sourceRoot":"../src/"}
@@ -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;