@fluentui/react-switch 9.0.0-rc.3 → 9.0.0-rc.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 (45) hide show
  1. package/CHANGELOG.json +168 -1
  2. package/CHANGELOG.md +47 -2
  3. package/MIGRATION.md +89 -22
  4. package/Spec.md +179 -84
  5. package/dist/react-switch.d.ts +59 -40
  6. package/lib/components/Switch/Switch.d.ts +1 -1
  7. package/lib/components/Switch/Switch.js +1 -1
  8. package/lib/components/Switch/Switch.js.map +1 -1
  9. package/lib/components/Switch/Switch.types.d.ts +41 -35
  10. package/lib/components/Switch/Switch.types.js.map +1 -1
  11. package/lib/components/Switch/renderSwitch.d.ts +1 -1
  12. package/lib/components/Switch/renderSwitch.js +8 -6
  13. package/lib/components/Switch/renderSwitch.js.map +1 -1
  14. package/lib/components/Switch/useSwitch.d.ts +8 -2
  15. package/lib/components/Switch/useSwitch.js +63 -43
  16. package/lib/components/Switch/useSwitch.js.map +1 -1
  17. package/lib/components/Switch/useSwitchStyles.d.ts +7 -2
  18. package/lib/components/Switch/useSwitchStyles.js +165 -266
  19. package/lib/components/Switch/useSwitchStyles.js.map +1 -1
  20. package/lib/index.d.ts +2 -2
  21. package/lib/index.js +2 -1
  22. package/lib/index.js.map +1 -1
  23. package/lib-commonjs/components/Switch/Switch.d.ts +1 -1
  24. package/lib-commonjs/components/Switch/Switch.js +1 -1
  25. package/lib-commonjs/components/Switch/Switch.js.map +1 -1
  26. package/lib-commonjs/components/Switch/Switch.types.d.ts +41 -35
  27. package/lib-commonjs/components/Switch/renderSwitch.d.ts +1 -1
  28. package/lib-commonjs/components/Switch/renderSwitch.js +8 -6
  29. package/lib-commonjs/components/Switch/renderSwitch.js.map +1 -1
  30. package/lib-commonjs/components/Switch/useSwitch.d.ts +8 -2
  31. package/lib-commonjs/components/Switch/useSwitch.js +65 -43
  32. package/lib-commonjs/components/Switch/useSwitch.js.map +1 -1
  33. package/lib-commonjs/components/Switch/useSwitchStyles.d.ts +7 -2
  34. package/lib-commonjs/components/Switch/useSwitchStyles.js +167 -268
  35. package/lib-commonjs/components/Switch/useSwitchStyles.js.map +1 -1
  36. package/lib-commonjs/index.d.ts +2 -2
  37. package/lib-commonjs/index.js +39 -2
  38. package/lib-commonjs/index.js.map +1 -1
  39. package/package.json +16 -17
  40. package/lib/components/Switch/useSwitchState.d.ts +0 -2
  41. package/lib/components/Switch/useSwitchState.js +0 -144
  42. package/lib/components/Switch/useSwitchState.js.map +0 -1
  43. package/lib-commonjs/components/Switch/useSwitchState.d.ts +0 -2
  44. package/lib-commonjs/components/Switch/useSwitchState.js +0 -156
  45. package/lib-commonjs/components/Switch/useSwitchState.js.map +0 -1
@@ -1,59 +1,65 @@
1
1
  import * as React from 'react';
2
+ import { Label } from '@fluentui/react-label';
2
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: Slot<'div'>;
8
- /**
9
- * The bar indicating the status of the Switch.
10
- */
11
- track: NonNullable<Slot<'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: NonNullable<Slot<'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: NonNullable<Slot<'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
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: NonNullable<Slot<'div'>>;
26
+ label?: Slot<typeof Label>;
28
27
  };
29
- 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<Partial<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;
59
65
  export {};
@@ -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
5
  export declare const renderSwitch_unstable: (state: SwitchState) => JSX.Element;
@@ -9,7 +9,7 @@ const React = /*#__PURE__*/require("react");
9
9
 
10
10
  const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
11
  /**
12
- * Render the final JSX of Switch
12
+ * Render a Switch component by passing the state defined props to the appropriate slots.
13
13
  */
14
14
 
15
15
 
@@ -18,12 +18,14 @@ const renderSwitch_unstable = state => {
18
18
  slots,
19
19
  slotProps
20
20
  } = react_utilities_1.getSlots(state);
21
+ const {
22
+ labelPosition
23
+ } = state;
21
24
  return React.createElement(slots.root, { ...slotProps.root
22
- }, React.createElement(slots.track, { ...slotProps.track
23
- }), React.createElement(slots.thumbWrapper, { ...slotProps.thumbWrapper
24
- }, React.createElement(slots.thumb, { ...slotProps.thumb
25
- })), React.createElement(slots.input, { ...slotProps.input
26
- }), React.createElement(slots.activeRail, { ...slotProps.activeRail
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
27
29
  }));
28
30
  };
29
31
 
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Switch/renderSwitch.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,qBAAqB,GAAI,KAAD,IAAuB;AAC1D,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,iBAAA,CAAA,QAAA,CAAsB,KAAtB,CAA7B;AAEA,SACE,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,EAEE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,YAAP,EAAmB,EAAA,GAAK,SAAS,CAAC;AAAf,GAAnB,EACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CADF,CAFF,EAKE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CALF,EAME,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,UAAP,EAAiB,EAAA,GAAK,SAAS,CAAC;AAAf,GAAjB,CANF,CADF;AAUD,CAbM;;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 the final JSX of Switch\n */\nexport const renderSwitch_unstable = (state: SwitchState) => {\n const { slots, slotProps } = getSlots<SwitchSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n <slots.track {...slotProps.track} />\n <slots.thumbWrapper {...slotProps.thumbWrapper}>\n <slots.thumb {...slotProps.thumb} />\n </slots.thumbWrapper>\n <slots.input {...slotProps.input} />\n <slots.activeRail {...slotProps.activeRail} />\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/Switch/renderSwitch.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,qBAAqB,GAAI,KAAD,IAAuB;AAC1D,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,iBAAA,CAAA,QAAA,CAAsB,KAAtB,CAA7B;AACA,QAAM;AAAE,IAAA;AAAF,MAAoB,KAA1B;AAEA,SACE,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,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,6 +1,12 @@
1
1
  import * as React from 'react';
2
2
  import type { SwitchProps, SwitchState } from './Switch.types';
3
3
  /**
4
- * Given user props, returns state and render function for a Switch.
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 useSwitch_unstable: (props: SwitchProps, ref: React.Ref<HTMLElement>) => SwitchState;
12
+ export declare const useSwitch_unstable: (props: SwitchProps, ref: React.Ref<HTMLInputElement>) => SwitchState;
@@ -5,65 +5,87 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useSwitch_unstable = void 0;
7
7
 
8
- const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const react_icons_1 = /*#__PURE__*/require("@fluentui/react-icons");
9
11
 
10
- const useSwitchState_1 = /*#__PURE__*/require("./useSwitchState");
12
+ const react_label_1 = /*#__PURE__*/require("@fluentui/react-label");
13
+
14
+ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
15
  /**
12
- * 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
13
23
  */
14
24
 
15
25
 
16
26
  const useSwitch_unstable = (props, ref) => {
17
27
  const {
18
- track,
19
- thumbWrapper,
20
- thumb,
21
- activeRail,
22
- input,
23
- defaultChecked,
24
28
  checked,
25
- disabled,
26
- onChange
27
- } = props;
28
- const state = {
29
29
  defaultChecked,
30
- checked,
31
30
  disabled,
31
+ labelPosition = 'after',
32
32
  onChange,
33
- root: react_utilities_1.getNativeElementProps('span', {
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,
34
57
  ref,
35
- ...props,
36
- id: react_utilities_1.useId('switch-', props.id)
37
- }),
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
38
78
  components: {
39
79
  root: 'div',
40
- track: 'div',
41
- thumbWrapper: 'div',
42
- thumb: 'div',
43
- activeRail: 'div',
44
- input: 'input'
80
+ indicator: 'div',
81
+ input: 'input',
82
+ label: react_label_1.Label
45
83
  },
46
- track: react_utilities_1.resolveShorthand(track, {
47
- required: true
48
- }),
49
- thumbWrapper: react_utilities_1.resolveShorthand(thumbWrapper, {
50
- required: true
51
- }),
52
- thumb: react_utilities_1.resolveShorthand(thumb, {
53
- required: true
54
- }),
55
- activeRail: react_utilities_1.resolveShorthand(activeRail, {
56
- required: true
57
- }),
58
- input: react_utilities_1.resolveShorthand(input, {
59
- required: true,
60
- defaultProps: {
61
- type: 'checkbox'
62
- }
63
- })
84
+ root,
85
+ indicator,
86
+ input,
87
+ label
64
88
  };
65
- useSwitchState_1.useSwitchState(state);
66
- return state;
67
89
  };
68
90
 
69
91
  exports.useSwitch_unstable = useSwitch_unstable;
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Switch/useSwitch.ts"],"names":[],"mappings":";;;;;;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,gBAAA,gBAAA,OAAA,CAAA,kBAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,kBAAkB,GAAG,CAAC,KAAD,EAAqB,GAArB,KAAiE;AACjG,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA,YAAT;AAAuB,IAAA,KAAvB;AAA8B,IAAA,UAA9B;AAA0C,IAAA,KAA1C;AAAiD,IAAA,cAAjD;AAAiE,IAAA,OAAjE;AAA0E,IAAA,QAA1E;AAAoF,IAAA;AAApF,MAAiG,KAAvG;AACA,QAAM,KAAK,GAAgB;AACzB,IAAA,cADyB;AAEzB,IAAA,OAFyB;AAGzB,IAAA,QAHyB;AAIzB,IAAA,QAJyB;AAKzB,IAAA,IAAI,EAAE,iBAAA,CAAA,qBAAA,CAAsB,MAAtB,EAA8B;AAClC,MAAA,GADkC;AAElC,SAAG,KAF+B;AAGlC,MAAA,EAAE,EAAE,iBAAA,CAAA,KAAA,CAAM,SAAN,EAAiB,KAAK,CAAC,EAAvB;AAH8B,KAA9B,CALmB;AAUzB,IAAA,UAAU,EAAE;AACV,MAAA,IAAI,EAAE,KADI;AAEV,MAAA,KAAK,EAAE,KAFG;AAGV,MAAA,YAAY,EAAE,KAHJ;AAIV,MAAA,KAAK,EAAE,KAJG;AAKV,MAAA,UAAU,EAAE,KALF;AAMV,MAAA,KAAK,EAAE;AANG,KAVa;AAkBzB,IAAA,KAAK,EAAE,iBAAA,CAAA,gBAAA,CAAiB,KAAjB,EAAwB;AAAE,MAAA,QAAQ,EAAE;AAAZ,KAAxB,CAlBkB;AAmBzB,IAAA,YAAY,EAAE,iBAAA,CAAA,gBAAA,CAAiB,YAAjB,EAA+B;AAAE,MAAA,QAAQ,EAAE;AAAZ,KAA/B,CAnBW;AAoBzB,IAAA,KAAK,EAAE,iBAAA,CAAA,gBAAA,CAAiB,KAAjB,EAAwB;AAAE,MAAA,QAAQ,EAAE;AAAZ,KAAxB,CApBkB;AAqBzB,IAAA,UAAU,EAAE,iBAAA,CAAA,gBAAA,CAAiB,UAAjB,EAA6B;AAAE,MAAA,QAAQ,EAAE;AAAZ,KAA7B,CArBa;AAsBzB,IAAA,KAAK,EAAE,iBAAA,CAAA,gBAAA,CAAiB,KAAjB,EAAwB;AAC7B,MAAA,QAAQ,EAAE,IADmB;AAE7B,MAAA,YAAY,EAAE;AACZ,QAAA,IAAI,EAAE;AADM;AAFe,KAAxB;AAtBkB,GAA3B;AA8BA,EAAA,gBAAA,CAAA,cAAA,CAAe,KAAf;AAEA,SAAO,KAAP;AACD,CAnCM;;AAAM,OAAA,CAAA,kBAAA,GAAkB,kBAAlB","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useId } from '@fluentui/react-utilities';\nimport { useSwitchState } from './useSwitchState';\nimport type { SwitchProps, SwitchState } from './Switch.types';\n\n/**\n * Given user props, returns state and render function for a Switch.\n */\nexport const useSwitch_unstable = (props: SwitchProps, ref: React.Ref<HTMLElement>): SwitchState => {\n const { track, thumbWrapper, thumb, activeRail, input, defaultChecked, checked, disabled, onChange } = props;\n const state: SwitchState = {\n defaultChecked,\n checked,\n disabled,\n onChange,\n root: getNativeElementProps('span', {\n ref,\n ...props,\n id: useId('switch-', props.id),\n }),\n components: {\n root: 'div',\n track: 'div',\n thumbWrapper: 'div',\n thumb: 'div',\n activeRail: 'div',\n input: 'input',\n },\n track: resolveShorthand(track, { required: true }),\n thumbWrapper: resolveShorthand(thumbWrapper, { required: true }),\n thumb: resolveShorthand(thumb, { required: true }),\n activeRail: resolveShorthand(activeRail, { required: true }),\n input: resolveShorthand(input, {\n required: true,\n defaultProps: {\n type: 'checkbox',\n },\n }),\n };\n\n useSwitchState(state);\n\n return state;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/Switch/useSwitch.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,aAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;;AACA,MAAA,aAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAGA;;;;;;;;AAQG;;;AACI,MAAM,kBAAkB,GAAG,CAAC,KAAD,EAAqB,GAArB,KAAsE;AACtG,QAAM;AAAE,IAAA,OAAF;AAAW,IAAA,cAAX;AAA2B,IAAA,QAA3B;AAAqC,IAAA,aAAa,GAAG,OAArD;AAA8D,IAAA,QAA9D;AAAwE,IAAA;AAAxE,MAAqF,KAA3F;AAEA,QAAM,WAAW,GAAG,iBAAA,CAAA,yBAAA,CAA0B;AAC5C,IAAA,KAD4C;AAE5C,IAAA,kBAAkB,EAAE,OAFwB;AAG5C,IAAA,iBAAiB,EAAE,CAAC,SAAD,EAAY,gBAAZ,EAA8B,UAA9B;AAHyB,GAA1B,CAApB;AAMA,QAAM,EAAE,GAAG,iBAAA,CAAA,KAAA,CAAM,SAAN,EAAiB,WAAW,CAAC,OAAZ,CAAoB,EAArC,CAAX;AAEA,QAAM,IAAI,GAAG,iBAAA,CAAA,gBAAA,CAAiB,KAAK,CAAC,IAAvB,EAA6B;AACxC,IAAA,YAAY,EAAE,WAAW,CAAC,IADc;AAExC,IAAA,QAAQ,EAAE;AAF8B,GAA7B,CAAb;AAKA,QAAM,SAAS,GAAG,iBAAA,CAAA,gBAAA,CAAiB,KAAK,CAAC,SAAvB,EAAkC;AAClD,IAAA,YAAY,EAAE;AACZ,qBAAe,IADH;AAEZ,MAAA,QAAQ,EAAE,KAAA,CAAA,aAAA,CAAC,aAAA,CAAA,YAAD,EAAa,IAAb;AAFE,KADoC;AAKlD,IAAA,QAAQ,EAAE;AALwC,GAAlC,CAAlB;AAQA,QAAM,KAAK,GAAG,iBAAA,CAAA,gBAAA,CAAiB,KAAK,CAAC,KAAvB,EAA8B;AAC1C,IAAA,YAAY,EAAE;AACZ,MAAA,OADY;AAEZ,MAAA,cAFY;AAGZ,MAAA,EAHY;AAIZ,MAAA,GAJY;AAKZ,MAAA,IAAI,EAAE,QALM;AAMZ,MAAA,IAAI,EAAE,UANM;AAOZ,SAAG,WAAW,CAAC;AAPH,KAD4B;AAU1C,IAAA,QAAQ,EAAE;AAVgC,GAA9B,CAAd;AAYA,EAAA,KAAK,CAAC,QAAN,GAAiB,iBAAA,CAAA,uBAAA,CAAwB,KAAK,CAAC,QAA9B,EAAwC,EAAE,IAAI,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAQ,KAAA,CAAR,GAAA,QAAQ,CAAG,EAAH,EAAO;AAAE,IAAA,OAAO,EAAE,EAAE,CAAC,aAAH,CAAiB;AAA5B,GAAP,CAAtD,CAAjB;AAEA,QAAM,KAAK,GAAG,iBAAA,CAAA,gBAAA,CAAiB,KAAK,CAAC,KAAvB,EAA8B;AAC1C,IAAA,YAAY,EAAE;AACZ,MAAA,QADY;AAEZ,MAAA,OAAO,EAAE,EAFG;AAGZ,MAAA,QAHY;AAIZ,MAAA,IAAI,EAAE;AAJM;AAD4B,GAA9B,CAAd;AASA,SAAO;AACL,IAAA,aADK;AAGL;AACA,IAAA,UAAU,EAAE;AACV,MAAA,IAAI,EAAE,KADI;AAEV,MAAA,SAAS,EAAE,KAFD;AAGV,MAAA,KAAK,EAAE,OAHG;AAIV,MAAA,KAAK,EAAE,aAAA,CAAA;AAJG,KAJP;AAWL,IAAA,IAXK;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,10 @@
1
- import type { SwitchState } from './Switch.types';
2
- export declare const switchClassName = "fui-Switch";
1
+ import type { SlotClassNames } from '@fluentui/react-utilities';
2
+ import type { SwitchSlots, SwitchState } from './Switch.types';
3
+ export declare const switchClassNames: SlotClassNames<SwitchSlots>;
4
+ /**
5
+ * @deprecated Use `switchClassNames.root` instead.
6
+ */
7
+ export declare const switchClassName: string;
3
8
  /**
4
9
  * Apply styling to the Switch slots based on the state
5
10
  */