@fluentui/react-switch 9.0.0-nightly.f81b28ceb3.1 → 9.0.0-rc.4

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 (54) hide show
  1. package/CHANGELOG.json +353 -28
  2. package/CHANGELOG.md +96 -16
  3. package/Spec.md +4 -4
  4. package/dist/react-switch.d.ts +60 -46
  5. package/lib/Switch.js.map +1 -1
  6. package/lib/components/Switch/Switch.d.ts +1 -1
  7. package/lib/components/Switch/Switch.js +8 -8
  8. package/lib/components/Switch/Switch.js.map +1 -1
  9. package/lib/components/Switch/Switch.types.d.ts +44 -37
  10. package/lib/components/Switch/Switch.types.js.map +1 -1
  11. package/lib/components/Switch/index.js.map +1 -1
  12. package/lib/components/Switch/renderSwitch.d.ts +2 -2
  13. package/lib/components/Switch/renderSwitch.js +15 -9
  14. package/lib/components/Switch/renderSwitch.js.map +1 -1
  15. package/lib/components/Switch/useSwitch.d.ts +9 -7
  16. package/lib/components/Switch/useSwitch.js +70 -54
  17. package/lib/components/Switch/useSwitch.js.map +1 -1
  18. package/lib/components/Switch/useSwitchStyles.d.ts +6 -2
  19. package/lib/components/Switch/useSwitchStyles.js +155 -267
  20. package/lib/components/Switch/useSwitchStyles.js.map +1 -1
  21. package/lib/index.js.map +1 -1
  22. package/lib-commonjs/Switch.js +1 -1
  23. package/lib-commonjs/Switch.js.map +1 -1
  24. package/lib-commonjs/components/Switch/Switch.d.ts +1 -1
  25. package/lib-commonjs/components/Switch/Switch.js +9 -9
  26. package/lib-commonjs/components/Switch/Switch.js.map +1 -1
  27. package/lib-commonjs/components/Switch/Switch.types.d.ts +44 -37
  28. package/lib-commonjs/components/Switch/Switch.types.js.map +1 -1
  29. package/lib-commonjs/components/Switch/index.js +1 -1
  30. package/lib-commonjs/components/Switch/index.js.map +1 -1
  31. package/lib-commonjs/components/Switch/renderSwitch.d.ts +2 -2
  32. package/lib-commonjs/components/Switch/renderSwitch.js +19 -15
  33. package/lib-commonjs/components/Switch/renderSwitch.js.map +1 -1
  34. package/lib-commonjs/components/Switch/useSwitch.d.ts +9 -7
  35. package/lib-commonjs/components/Switch/useSwitch.js +73 -56
  36. package/lib-commonjs/components/Switch/useSwitch.js.map +1 -1
  37. package/lib-commonjs/components/Switch/useSwitchStyles.d.ts +6 -2
  38. package/lib-commonjs/components/Switch/useSwitchStyles.js +159 -270
  39. package/lib-commonjs/components/Switch/useSwitchStyles.js.map +1 -1
  40. package/lib-commonjs/index.js +1 -1
  41. package/lib-commonjs/index.js.map +1 -1
  42. package/package.json +12 -15
  43. package/lib/common/isConformant.d.ts +0 -4
  44. package/lib/common/isConformant.js +0 -12
  45. package/lib/common/isConformant.js.map +0 -1
  46. package/lib/components/Switch/useSwitchState.d.ts +0 -2
  47. package/lib/components/Switch/useSwitchState.js +0 -152
  48. package/lib/components/Switch/useSwitchState.js.map +0 -1
  49. package/lib-commonjs/common/isConformant.d.ts +0 -4
  50. package/lib-commonjs/common/isConformant.js +0 -23
  51. package/lib-commonjs/common/isConformant.js.map +0 -1
  52. package/lib-commonjs/components/Switch/useSwitchState.d.ts +0 -2
  53. package/lib-commonjs/components/Switch/useSwitchState.js +0 -164
  54. package/lib-commonjs/components/Switch/useSwitchState.js.map +0 -1
@@ -1,58 +1,65 @@
1
1
  import * as React from 'react';
2
- import type { ComponentProps, ComponentState, IntrinsicShorthandProps } from '@fluentui/react-utilities';
2
+ import { Label } from '@fluentui/react-label';
3
+ import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
3
4
  export declare type SwitchSlots = {
4
5
  /**
5
- * The root of the Switch.
6
- */
7
- root: IntrinsicShorthandProps<'div'>;
8
- /**
9
- * The bar indicating the status of the Switch.
10
- */
11
- track: IntrinsicShorthandProps<'div'>;
12
- /**
13
- * The wrapper around the thumb. It is used as the active area for the thumb to position itself.
6
+ * The root element of the Switch.
7
+ *
8
+ * The root slot receives the `className` and `style` specified directly on the `<Switch>` tag.
9
+ * All other native props will be applied to the primary slot: `input`.
14
10
  */
15
- thumbWrapper: IntrinsicShorthandProps<'div'>;
11
+ root: NonNullable<Slot<'div'>>;
16
12
  /**
17
- * The circular icon indicating the status of the Switch.
13
+ * The track and the thumb sliding over it indicating the on and off status of the Switch.
18
14
  */
19
- thumb: IntrinsicShorthandProps<'div'>;
15
+ indicator: NonNullable<Slot<'div'>>;
20
16
  /**
21
- * The hidden input that handles the Switch's internal functionality.
17
+ * Hidden input that handles the Switch's functionality.
18
+ *
19
+ * This is the PRIMARY slot: all native properties specified directly on the `<Switch>` tag will be applied to this
20
+ * slot, except `className` and `style`, which remain on the root slot.
22
21
  */
23
- input: IntrinsicShorthandProps<'input'>;
22
+ input: NonNullable<Slot<'input'>>;
24
23
  /**
25
- * The area in which the Switch's rail allows for the thumb to be dragged.
24
+ * The Switch's label.
26
25
  */
27
- activeRail: IntrinsicShorthandProps<'div'>;
26
+ label?: Slot<typeof Label>;
28
27
  };
29
- export interface SwitchCommons {
28
+ declare type SwitchCommons = {
30
29
  /**
31
- * The starting value for a uncontrolled Switch. If `true` then the Switch will be enabled.
32
- * Mutually exclusive with `checked` prop.
33
- *
30
+ * Defines the controlled checked state of the Switch.
31
+ * If passed, Switch ignores the `defaultChecked` property.
32
+ * This should only be used if the checked state is to be controlled at a higher level and there is a plan to pass the
33
+ * correct value based on handling `onChange` events and re-rendering.
34
34
  * @default false
35
35
  */
36
- defaultChecked?: boolean;
37
- /**
38
- * The current value for a controlled Switch. If `true` then the Switch will be enabled.
39
- * Mutually exclusive with `defaultChecked` prop.
40
- */
41
36
  checked?: boolean;
42
37
  /**
43
- * Whether the Switch should be disabled.
38
+ * The position of the label relative to the Switch.
44
39
  *
40
+ * @default after
41
+ */
42
+ labelPosition: 'above' | 'after' | 'before';
43
+ };
44
+ export declare type SwitchOnChangeData = {
45
+ checked: boolean;
46
+ };
47
+ /**
48
+ * Switch Props
49
+ */
50
+ export declare type SwitchProps = Omit<ComponentProps<Partial<SwitchSlots>, 'input'>, 'onChange'> & Partial<SwitchCommons> & {
51
+ /**
52
+ * Defines whether the Switch is initially in a checked state or not when rendered.
45
53
  * @default false
46
54
  */
47
- disabled?: boolean;
55
+ defaultChecked?: boolean;
48
56
  /**
49
- * Callback to be called when the `checked` value changes.
57
+ * Callback to be called when the checked state value changes.
50
58
  */
51
- onChange?: (ev: React.PointerEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>, data: {
52
- checked: boolean;
53
- }) => void;
54
- }
55
- export interface SwitchProps extends Omit<ComponentProps<SwitchSlots>, 'onChange'>, SwitchCommons {
56
- }
57
- export interface SwitchState extends ComponentState<SwitchSlots>, SwitchCommons {
58
- }
59
+ onChange?: (ev: React.ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => void;
60
+ };
61
+ /**
62
+ * State used in rendering Switch
63
+ */
64
+ export declare type SwitchState = ComponentState<SwitchSlots> & SwitchCommons;
65
+ export {};
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":""}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var tslib_1 = /*#__PURE__*/require("tslib");
7
+ const tslib_1 = /*#__PURE__*/require("tslib");
8
8
 
9
9
  tslib_1.__exportStar(require("./Switch"), exports);
10
10
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Switch/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,UAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,mBAAA,CAAA,EAAA,OAAA","sourceRoot":""}
1
+ {"version":3,"sources":["components/Switch/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,UAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,mBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Switch';\nexport * from './Switch.types';\nexport * from './renderSwitch';\nexport * from './useSwitch';\nexport * from './useSwitchStyles';\n"],"sourceRoot":"../src/"}
@@ -1,5 +1,5 @@
1
1
  import type { SwitchState } from './Switch.types';
2
2
  /**
3
- * Render the final JSX of Switch
3
+ * Render a Switch component by passing the state defined props to the appropriate slots.
4
4
  */
5
- export declare const renderSwitch: (state: SwitchState) => JSX.Element;
5
+ export declare const renderSwitch_unstable: (state: SwitchState) => JSX.Element;
@@ -3,27 +3,31 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.renderSwitch = void 0;
6
+ exports.renderSwitch_unstable = void 0;
7
7
 
8
- var tslib_1 = /*#__PURE__*/require("tslib");
8
+ const React = /*#__PURE__*/require("react");
9
9
 
10
- var React = /*#__PURE__*/require("react");
11
-
12
- var react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
13
-
14
- var useSwitch_1 = /*#__PURE__*/require("./useSwitch");
10
+ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
15
11
  /**
16
- * Render the final JSX of Switch
12
+ * Render a Switch component by passing the state defined props to the appropriate slots.
17
13
  */
18
14
 
19
15
 
20
- var renderSwitch = function (state) {
21
- var _a = react_utilities_1.getSlots(state, useSwitch_1.switchShorthandProps),
22
- slots = _a.slots,
23
- slotProps = _a.slotProps;
24
-
25
- return React.createElement(slots.root, tslib_1.__assign({}, slotProps.root), React.createElement(slots.track, tslib_1.__assign({}, slotProps.track)), React.createElement(slots.thumbWrapper, tslib_1.__assign({}, slotProps.thumbWrapper), React.createElement(slots.thumb, tslib_1.__assign({}, slotProps.thumb))), React.createElement(slots.input, tslib_1.__assign({}, slotProps.input)), React.createElement(slots.activeRail, tslib_1.__assign({}, slotProps.activeRail)));
16
+ const renderSwitch_unstable = state => {
17
+ const {
18
+ slots,
19
+ slotProps
20
+ } = react_utilities_1.getSlots(state);
21
+ const {
22
+ labelPosition
23
+ } = state;
24
+ return React.createElement(slots.root, { ...slotProps.root
25
+ }, React.createElement(slots.input, { ...slotProps.input
26
+ }), labelPosition !== 'after' && slots.label && React.createElement(slots.label, { ...slotProps.label
27
+ }), React.createElement(slots.indicator, { ...slotProps.indicator
28
+ }), labelPosition === 'after' && slots.label && React.createElement(slots.label, { ...slotProps.label
29
+ }));
26
30
  };
27
31
 
28
- exports.renderSwitch = renderSwitch;
32
+ exports.renderSwitch_unstable = renderSwitch_unstable;
29
33
  //# sourceMappingURL=renderSwitch.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Switch/renderSwitch.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,IAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,IAAA,WAAA,gBAAA,OAAA,CAAA,aAAA,CAAA;AAGA;;AAEG;;;AACI,IAAM,YAAY,GAAG,UAAC,KAAD,EAAmB;AACvC,MAAA,EAAA,GAAuB,iBAAA,CAAA,QAAA,CAAsB,KAAtB,EAA6B,WAAA,CAAA,oBAA7B,CAAvB;AAAA,MAAE,KAAK,GAAA,EAAA,CAAA,KAAP;AAAA,MAAS,SAAS,GAAA,EAAA,CAAA,SAAlB;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f,GAAX,EACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CADF,EAEG,aAAa,KAAK,OAAlB,IAA6B,KAAK,CAAC,KAAnC,IAA4C,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CAF/C,EAGE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,SAAP,EAAgB,EAAA,GAAK,SAAS,CAAC;AAAf,GAAhB,CAHF,EAIG,aAAa,KAAK,OAAlB,IAA6B,KAAK,CAAC,KAAnC,IAA4C,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CAJ/C,CADF;AAQD,CAZM;;AAAM,OAAA,CAAA,qBAAA,GAAqB,qBAArB","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { SwitchState, SwitchSlots } from './Switch.types';\n\n/**\n * Render a Switch component by passing the state defined props to the appropriate slots.\n */\nexport const renderSwitch_unstable = (state: SwitchState) => {\n const { slots, slotProps } = getSlots<SwitchSlots>(state);\n const { labelPosition } = state;\n\n return (\n <slots.root {...slotProps.root}>\n <slots.input {...slotProps.input} />\n {labelPosition !== 'after' && slots.label && <slots.label {...slotProps.label} />}\n <slots.indicator {...slotProps.indicator} />\n {labelPosition === 'after' && slots.label && <slots.label {...slotProps.label} />}\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
@@ -1,10 +1,12 @@
1
1
  import * as React from 'react';
2
- import type { SwitchProps, SwitchSlots, SwitchState } from './Switch.types';
2
+ import type { SwitchProps, SwitchState } from './Switch.types';
3
3
  /**
4
- * Array of all shorthand properties listed in SwitchSlots
4
+ * Create the state required to render Switch.
5
+ *
6
+ * The returned state can be modified with hooks such as useSwitchStyles_unstable,
7
+ * before being passed to renderSwitch_unstable.
8
+ *
9
+ * @param props - props from this instance of Switch
10
+ * @param ref - reference to `<input>` element of Switch
5
11
  */
6
- export declare const switchShorthandProps: (keyof SwitchSlots)[];
7
- /**
8
- * Given user props, returns state and render function for a Switch.
9
- */
10
- export declare const useSwitch: (props: SwitchProps, ref: React.Ref<HTMLElement>) => SwitchState;
12
+ export declare const useSwitch_unstable: (props: SwitchProps, ref: React.Ref<HTMLInputElement>) => SwitchState;
@@ -3,73 +3,90 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useSwitch = exports.switchShorthandProps = void 0;
6
+ exports.useSwitch_unstable = void 0;
7
7
 
8
- var tslib_1 = /*#__PURE__*/require("tslib");
8
+ const React = /*#__PURE__*/require("react");
9
9
 
10
- var react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
-
12
- var useSwitchState_1 = /*#__PURE__*/require("./useSwitchState");
13
- /**
14
- * Array of all shorthand properties listed in SwitchSlots
15
- */
10
+ const react_icons_1 = /*#__PURE__*/require("@fluentui/react-icons");
16
11
 
12
+ const react_label_1 = /*#__PURE__*/require("@fluentui/react-label");
17
13
 
18
- exports.switchShorthandProps = ['root', 'track', 'thumbWrapper', 'thumb', 'activeRail', 'input'];
14
+ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
19
15
  /**
20
- * Given user props, returns state and render function for a Switch.
16
+ * Create the state required to render Switch.
17
+ *
18
+ * The returned state can be modified with hooks such as useSwitchStyles_unstable,
19
+ * before being passed to renderSwitch_unstable.
20
+ *
21
+ * @param props - props from this instance of Switch
22
+ * @param ref - reference to `<input>` element of Switch
21
23
  */
22
24
 
23
- var useSwitch = function (props, ref) {
24
- var track = props.track,
25
- thumbWrapper = props.thumbWrapper,
26
- thumb = props.thumb,
27
- activeRail = props.activeRail,
28
- input = props.input,
29
- defaultChecked = props.defaultChecked,
30
- checked = props.checked,
31
- disabled = props.disabled,
32
- onChange = props.onChange;
33
- var state = {
34
- defaultChecked: defaultChecked,
35
- checked: checked,
36
- disabled: disabled,
37
- onChange: onChange,
38
- root: react_utilities_1.getNativeElementProps('span', tslib_1.__assign(tslib_1.__assign({
39
- ref: ref
40
- }, props), {
41
- id: react_utilities_1.useId('switch-', props.id)
42
- })),
25
+
26
+ const useSwitch_unstable = (props, ref) => {
27
+ const {
28
+ checked,
29
+ defaultChecked,
30
+ disabled,
31
+ labelPosition = 'after',
32
+ onChange,
33
+ required
34
+ } = props;
35
+ const nativeProps = react_utilities_1.getPartitionedNativeProps({
36
+ props,
37
+ primarySlotTagName: 'input',
38
+ excludedPropNames: ['checked', 'defaultChecked', 'onChange']
39
+ });
40
+ const id = react_utilities_1.useId('switch-', nativeProps.primary.id);
41
+ const root = react_utilities_1.resolveShorthand(props.root, {
42
+ defaultProps: nativeProps.root,
43
+ required: true
44
+ });
45
+ const indicator = react_utilities_1.resolveShorthand(props.indicator, {
46
+ defaultProps: {
47
+ 'aria-hidden': true,
48
+ children: React.createElement(react_icons_1.CircleFilled, null)
49
+ },
50
+ required: true
51
+ });
52
+ const input = react_utilities_1.resolveShorthand(props.input, {
53
+ defaultProps: {
54
+ checked,
55
+ defaultChecked,
56
+ id,
57
+ ref,
58
+ role: 'switch',
59
+ type: 'checkbox',
60
+ ...nativeProps.primary
61
+ },
62
+ required: true
63
+ });
64
+ input.onChange = react_utilities_1.useMergedEventCallbacks(input.onChange, ev => onChange === null || onChange === void 0 ? void 0 : onChange(ev, {
65
+ checked: ev.currentTarget.checked
66
+ }));
67
+ const label = react_utilities_1.resolveShorthand(props.label, {
68
+ defaultProps: {
69
+ disabled,
70
+ htmlFor: id,
71
+ required,
72
+ size: 'medium'
73
+ }
74
+ });
75
+ return {
76
+ labelPosition,
77
+ //Slots definition
43
78
  components: {
44
79
  root: 'div',
45
- track: 'div',
46
- thumbWrapper: 'div',
47
- thumb: 'div',
48
- activeRail: 'div',
49
- input: 'input'
80
+ indicator: 'div',
81
+ input: 'input',
82
+ label: react_label_1.Label
50
83
  },
51
- track: react_utilities_1.resolveShorthand(track, {
52
- required: true
53
- }),
54
- thumbWrapper: react_utilities_1.resolveShorthand(thumbWrapper, {
55
- required: true
56
- }),
57
- thumb: react_utilities_1.resolveShorthand(thumb, {
58
- required: true
59
- }),
60
- activeRail: react_utilities_1.resolveShorthand(activeRail, {
61
- required: true
62
- }),
63
- input: react_utilities_1.resolveShorthand(input, {
64
- required: true,
65
- defaultProps: {
66
- type: 'checkbox'
67
- }
68
- })
84
+ root,
85
+ indicator,
86
+ input,
87
+ label
69
88
  };
70
- useSwitchState_1.useSwitchState(state);
71
- return state;
72
89
  };
73
90
 
74
- exports.useSwitch = useSwitch;
91
+ exports.useSwitch_unstable = useSwitch_unstable;
75
92
  //# sourceMappingURL=useSwitch.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Switch/useSwitch.ts"],"names":[],"mappings":";;;;;;;;;AACA,IAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,IAAA,gBAAA,gBAAA,OAAA,CAAA,kBAAA,CAAA;AAGA;;AAEG;;;AACU,OAAA,CAAA,oBAAA,GAA8C,CACzD,MADyD,EAEzD,OAFyD,EAGzD,cAHyD,EAIzD,OAJyD,EAKzD,YALyD,EAMzD,OANyD,CAA9C;AASb;;AAEG;;AACI,IAAM,SAAS,GAAG,UAAC,KAAD,EAAqB,GAArB,EAAgD;AAC/D,MAAA,KAAK,GAA0F,KAAK,CAA/F,KAAL;AAAA,MAAO,YAAY,GAA4E,KAAK,CAAjF,YAAnB;AAAA,MAAqB,KAAK,GAAqE,KAAK,CAA1E,KAA1B;AAAA,MAA4B,UAAU,GAAyD,KAAK,CAA9D,UAAtC;AAAA,MAAwC,KAAK,GAAkD,KAAK,CAAvD,KAA7C;AAAA,MAA+C,cAAc,GAAkC,KAAK,CAAvC,cAA7D;AAAA,MAA+D,OAAO,GAAyB,KAAK,CAA9B,OAAtE;AAAA,MAAwE,QAAQ,GAAe,KAAK,CAApB,QAAhF;AAAA,MAAkF,QAA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AXK;AAYL,IAAA,SAZK;AAaL,IAAA,KAbK;AAcL,IAAA;AAdK,GAAP;AAgBD,CA/DM;;AAAM,OAAA,CAAA,kBAAA,GAAkB,kBAAlB","sourcesContent":["import * as React from 'react';\nimport { CircleFilled } from '@fluentui/react-icons';\nimport { Label } from '@fluentui/react-label';\nimport { getPartitionedNativeProps, resolveShorthand, useId, useMergedEventCallbacks } from '@fluentui/react-utilities';\nimport type { SwitchProps, SwitchState } from './Switch.types';\n\n/**\n * Create the state required to render Switch.\n *\n * The returned state can be modified with hooks such as useSwitchStyles_unstable,\n * before being passed to renderSwitch_unstable.\n *\n * @param props - props from this instance of Switch\n * @param ref - reference to `<input>` element of Switch\n */\nexport const useSwitch_unstable = (props: SwitchProps, ref: React.Ref<HTMLInputElement>): SwitchState => {\n const { checked, defaultChecked, disabled, labelPosition = 'after', onChange, required } = props;\n\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['checked', 'defaultChecked', 'onChange'],\n });\n\n const id = useId('switch-', nativeProps.primary.id);\n\n const root = resolveShorthand(props.root, {\n defaultProps: nativeProps.root,\n required: true,\n });\n\n const indicator = resolveShorthand(props.indicator, {\n defaultProps: {\n 'aria-hidden': true,\n children: <CircleFilled />,\n },\n required: true,\n });\n\n const input = resolveShorthand(props.input, {\n defaultProps: {\n checked,\n defaultChecked,\n id,\n ref,\n role: 'switch',\n type: 'checkbox',\n ...nativeProps.primary,\n },\n required: true,\n });\n input.onChange = useMergedEventCallbacks(input.onChange, ev => onChange?.(ev, { checked: ev.currentTarget.checked }));\n\n const label = resolveShorthand(props.label, {\n defaultProps: {\n disabled,\n htmlFor: id,\n required,\n size: 'medium',\n },\n });\n\n return {\n labelPosition,\n\n //Slots definition\n components: {\n root: 'div',\n indicator: 'div',\n input: 'input',\n label: Label,\n },\n\n root,\n indicator,\n input,\n label,\n };\n};\n"],"sourceRoot":"../src/"}
@@ -1,5 +1,9 @@
1
- import type { SwitchState } from './Switch.types';
1
+ import type { SwitchSlots, SwitchState } from './Switch.types';
2
+ export declare const switchClassNames: {
3
+ [SlotName in keyof SwitchSlots]-?: string;
4
+ };
5
+ export declare const switchClassName: string;
2
6
  /**
3
7
  * Apply styling to the Switch slots based on the state
4
8
  */
5
- export declare const useSwitchStyles: (state: SwitchState) => SwitchState;
9
+ export declare const useSwitchStyles_unstable: (state: SwitchState) => SwitchState;