@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,92 +1,106 @@
1
1
  import type { ComponentProps } from '@fluentui/react-utilities';
2
2
  import type { ComponentState } from '@fluentui/react-utilities';
3
3
  import type { ForwardRefComponent } from '@fluentui/react-utilities';
4
- import type { IntrinsicShorthandProps } from '@fluentui/react-utilities';
4
+ import { Label } from '@fluentui/react-label';
5
5
  import * as React_2 from 'react';
6
+ import type { Slot } from '@fluentui/react-utilities';
6
7
 
7
8
  /**
8
- * Render the final JSX of Switch
9
+ * Render a Switch component by passing the state defined props to the appropriate slots.
9
10
  */
10
- export declare const renderSwitch: (state: SwitchState) => JSX.Element;
11
+ export declare const renderSwitch_unstable: (state: SwitchState) => JSX.Element;
11
12
 
12
13
  /**
13
- * The Switch control enables users to trigger an option on or off through pressing on the component.
14
+ * Switches enable users to trigger an option on or off through pressing the component.
14
15
  */
15
16
  export declare const Switch: ForwardRefComponent<SwitchProps>;
16
17
 
17
- export declare interface SwitchCommons {
18
+ export declare const switchClassName: string;
19
+
20
+ export declare const switchClassNames: {
21
+ [SlotName in keyof SwitchSlots]-?: string;
22
+ };
23
+
24
+ declare type SwitchCommons = {
18
25
  /**
19
- * The starting value for a uncontrolled Switch. If `true` then the Switch will be enabled.
20
- * Mutually exclusive with `checked` prop.
21
- *
26
+ * Defines the controlled checked state of the Switch.
27
+ * If passed, Switch ignores the `defaultChecked` property.
28
+ * 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
29
+ * correct value based on handling `onChange` events and re-rendering.
22
30
  * @default false
23
31
  */
24
- defaultChecked?: boolean;
25
- /**
26
- * The current value for a controlled Switch. If `true` then the Switch will be enabled.
27
- * Mutually exclusive with `defaultChecked` prop.
28
- */
29
32
  checked?: boolean;
30
33
  /**
31
- * Whether the Switch should be disabled.
34
+ * The position of the label relative to the Switch.
32
35
  *
33
- * @default false
34
- */
35
- disabled?: boolean;
36
- /**
37
- * Callback to be called when the `checked` value changes.
36
+ * @default after
38
37
  */
39
- onChange?: (ev: React_2.PointerEvent<HTMLDivElement> | React_2.KeyboardEvent<HTMLDivElement>, data: {
40
- checked: boolean;
41
- }) => void;
42
- }
38
+ labelPosition: 'above' | 'after' | 'before';
39
+ };
43
40
 
44
- export declare interface SwitchProps extends Omit<ComponentProps<SwitchSlots>, 'onChange'>, SwitchCommons {
45
- }
41
+ export declare type SwitchOnChangeData = {
42
+ checked: boolean;
43
+ };
46
44
 
47
45
  /**
48
- * Array of all shorthand properties listed in SwitchSlots
46
+ * Switch Props
49
47
  */
50
- export declare const switchShorthandProps: (keyof SwitchSlots)[];
51
-
52
- export declare type SwitchSlots = {
48
+ export declare type SwitchProps = Omit<ComponentProps<Partial<SwitchSlots>, 'input'>, 'onChange'> & Partial<SwitchCommons> & {
53
49
  /**
54
- * The root of the Switch.
50
+ * Defines whether the Switch is initially in a checked state or not when rendered.
51
+ * @default false
55
52
  */
56
- root: IntrinsicShorthandProps<'div'>;
53
+ defaultChecked?: boolean;
57
54
  /**
58
- * The bar indicating the status of the Switch.
55
+ * Callback to be called when the checked state value changes.
59
56
  */
60
- track: IntrinsicShorthandProps<'div'>;
57
+ onChange?: (ev: React_2.ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => void;
58
+ };
59
+
60
+ export declare type SwitchSlots = {
61
61
  /**
62
- * The wrapper around the thumb. It is used as the active area for the thumb to position itself.
62
+ * The root element of the Switch.
63
+ *
64
+ * The root slot receives the `className` and `style` specified directly on the `<Switch>` tag.
65
+ * All other native props will be applied to the primary slot: `input`.
63
66
  */
64
- thumbWrapper: IntrinsicShorthandProps<'div'>;
67
+ root: NonNullable<Slot<'div'>>;
65
68
  /**
66
- * The circular icon indicating the status of the Switch.
69
+ * The track and the thumb sliding over it indicating the on and off status of the Switch.
67
70
  */
68
- thumb: IntrinsicShorthandProps<'div'>;
71
+ indicator: NonNullable<Slot<'div'>>;
69
72
  /**
70
- * The hidden input that handles the Switch's internal functionality.
73
+ * Hidden input that handles the Switch's functionality.
74
+ *
75
+ * This is the PRIMARY slot: all native properties specified directly on the `<Switch>` tag will be applied to this
76
+ * slot, except `className` and `style`, which remain on the root slot.
71
77
  */
72
- input: IntrinsicShorthandProps<'input'>;
78
+ input: NonNullable<Slot<'input'>>;
73
79
  /**
74
- * The area in which the Switch's rail allows for the thumb to be dragged.
80
+ * The Switch's label.
75
81
  */
76
- activeRail: IntrinsicShorthandProps<'div'>;
82
+ label?: Slot<typeof Label>;
77
83
  };
78
84
 
79
- export declare interface SwitchState extends ComponentState<SwitchSlots>, SwitchCommons {
80
- }
85
+ /**
86
+ * State used in rendering Switch
87
+ */
88
+ export declare type SwitchState = ComponentState<SwitchSlots> & SwitchCommons;
81
89
 
82
90
  /**
83
- * Given user props, returns state and render function for a Switch.
91
+ * Create the state required to render Switch.
92
+ *
93
+ * The returned state can be modified with hooks such as useSwitchStyles_unstable,
94
+ * before being passed to renderSwitch_unstable.
95
+ *
96
+ * @param props - props from this instance of Switch
97
+ * @param ref - reference to `<input>` element of Switch
84
98
  */
85
- export declare const useSwitch: (props: SwitchProps, ref: React_2.Ref<HTMLElement>) => SwitchState;
99
+ export declare const useSwitch_unstable: (props: SwitchProps, ref: React_2.Ref<HTMLInputElement>) => SwitchState;
86
100
 
87
101
  /**
88
102
  * Apply styling to the Switch slots based on the state
89
103
  */
90
- export declare const useSwitchStyles: (state: SwitchState) => SwitchState;
104
+ export declare const useSwitchStyles_unstable: (state: SwitchState) => SwitchState;
91
105
 
92
106
  export { }
package/lib/Switch.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.js","sourceRoot":"","sources":["../src/Switch.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"Switch.js","sourceRoot":"../src/","sources":["Switch.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC","sourcesContent":["export * from './components/Switch/index';\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { SwitchProps } from './Switch.types';
2
2
  import type { ForwardRefComponent } from '@fluentui/react-utilities';
3
3
  /**
4
- * The Switch control enables users to trigger an option on or off through pressing on the component.
4
+ * Switches enable users to trigger an option on or off through pressing the component.
5
5
  */
6
6
  export declare const Switch: ForwardRefComponent<SwitchProps>;
@@ -1,15 +1,15 @@
1
1
  import * as React from 'react';
2
- import { useSwitch } from './useSwitch';
3
- import { renderSwitch } from './renderSwitch';
4
- import { useSwitchStyles } from './useSwitchStyles';
2
+ import { useSwitch_unstable } from './useSwitch';
3
+ import { renderSwitch_unstable } from './renderSwitch';
4
+ import { useSwitchStyles_unstable } from './useSwitchStyles';
5
5
  /**
6
- * The Switch control enables users to trigger an option on or off through pressing on the component.
6
+ * Switches enable users to trigger an option on or off through pressing the component.
7
7
  */
8
8
 
9
- export var Switch = /*#__PURE__*/React.forwardRef(function (props, ref) {
10
- var state = useSwitch(props, ref);
11
- useSwitchStyles(state);
12
- return renderSwitch(state);
9
+ export const Switch = /*#__PURE__*/React.forwardRef((props, ref) => {
10
+ const state = useSwitch_unstable(props, ref);
11
+ useSwitchStyles_unstable(state);
12
+ return renderSwitch_unstable(state);
13
13
  });
14
14
  Switch.displayName = 'Switch';
15
15
  //# sourceMappingURL=Switch.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Switch/Switch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,SAAT,QAA0B,aAA1B;AACA,SAAS,YAAT,QAA6B,gBAA7B;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAIA;;AAEG;;AACH,OAAO,IAAM,MAAM,gBAAqC,KAAK,CAAC,UAAN,CAAiB,UAAC,KAAD,EAAQ,GAAR,EAAW;AAClF,MAAM,KAAK,GAAG,SAAS,CAAC,KAAD,EAAQ,GAAR,CAAvB;AAEA,EAAA,eAAe,CAAC,KAAD,CAAf;AAEA,SAAO,YAAY,CAAC,KAAD,CAAnB;AACD,CANuD,CAAjD;AAQP,MAAM,CAAC,WAAP,GAAqB,QAArB","sourceRoot":""}
1
+ {"version":3,"sources":["components/Switch/Switch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,kBAAT,QAAmC,aAAnC;AACA,SAAS,qBAAT,QAAsC,gBAAtC;AACA,SAAS,wBAAT,QAAyC,mBAAzC;AAIA;;AAEG;;AACH,OAAO,MAAM,MAAM,gBAAqC,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;AACtF,QAAM,KAAK,GAAG,kBAAkB,CAAC,KAAD,EAAQ,GAAR,CAAhC;AAEA,EAAA,wBAAwB,CAAC,KAAD,CAAxB;AAEA,SAAO,qBAAqB,CAAC,KAAD,CAA5B;AACD,CANuD,CAAjD;AAQP,MAAM,CAAC,WAAP,GAAqB,QAArB","sourcesContent":["import * as React from 'react';\nimport { useSwitch_unstable } from './useSwitch';\nimport { renderSwitch_unstable } from './renderSwitch';\nimport { useSwitchStyles_unstable } from './useSwitchStyles';\nimport type { SwitchProps } from './Switch.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\n\n/**\n * Switches enable users to trigger an option on or off through pressing the component.\n */\nexport const Switch: ForwardRefComponent<SwitchProps> = React.forwardRef((props, ref) => {\n const state = useSwitch_unstable(props, ref);\n\n useSwitchStyles_unstable(state);\n\n return renderSwitch_unstable(state);\n});\n\nSwitch.displayName = 'Switch';\n"],"sourceRoot":"../src/"}
@@ -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,"file":"Switch.types.js","sourceRoot":"","sources":["../../../src/components/Switch/Switch.types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"Switch.types.js","sourceRoot":"../src/","sources":["components/Switch/Switch.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { Label } from '@fluentui/react-label';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\nexport type SwitchSlots = {\n /**\n * The root element of the Switch.\n *\n * The root slot receives the `className` and `style` specified directly on the `<Switch>` tag.\n * All other native props will be applied to the primary slot: `input`.\n */\n root: NonNullable<Slot<'div'>>;\n\n /**\n * The track and the thumb sliding over it indicating the on and off status of the Switch.\n */\n indicator: NonNullable<Slot<'div'>>;\n\n /**\n * Hidden input that handles the Switch's functionality.\n *\n * This is the PRIMARY slot: all native properties specified directly on the `<Switch>` tag will be applied to this\n * slot, except `className` and `style`, which remain on the root slot.\n */\n input: NonNullable<Slot<'input'>>;\n\n /**\n * The Switch's label.\n */\n label?: Slot<typeof Label>;\n};\n\ntype SwitchCommons = {\n /**\n * Defines the controlled checked state of the Switch.\n * If passed, Switch ignores the `defaultChecked` property.\n * 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\n * correct value based on handling `onChange` events and re-rendering.\n * @default false\n */\n checked?: boolean;\n\n /**\n * The position of the label relative to the Switch.\n *\n * @default after\n */\n labelPosition: 'above' | 'after' | 'before';\n};\n\nexport type SwitchOnChangeData = {\n checked: boolean;\n};\n\n/**\n * Switch Props\n */\nexport type SwitchProps = Omit<ComponentProps<Partial<SwitchSlots>, 'input'>, 'onChange'> &\n Partial<SwitchCommons> & {\n /**\n * Defines whether the Switch is initially in a checked state or not when rendered.\n * @default false\n */\n defaultChecked?: boolean;\n\n /**\n * Callback to be called when the checked state value changes.\n */\n onChange?: (ev: React.ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => void;\n };\n\n/**\n * State used in rendering Switch\n */\nexport type SwitchState = ComponentState<SwitchSlots> & SwitchCommons;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Switch/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Switch/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC","sourcesContent":["export * from './Switch';\nexport * from './Switch.types';\nexport * from './renderSwitch';\nexport * from './useSwitch';\nexport * from './useSwitchStyles';\n"]}
@@ -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;
@@ -1,16 +1,22 @@
1
- import { __assign } from "tslib";
2
1
  import * as React from 'react';
3
2
  import { getSlots } from '@fluentui/react-utilities';
4
- import { switchShorthandProps } from './useSwitch';
5
3
  /**
6
- * Render the final JSX of Switch
4
+ * Render a Switch component by passing the state defined props to the appropriate slots.
7
5
  */
8
6
 
9
- export var renderSwitch = function (state) {
10
- var _a = getSlots(state, switchShorthandProps),
11
- slots = _a.slots,
12
- slotProps = _a.slotProps;
13
-
14
- return /*#__PURE__*/React.createElement(slots.root, __assign({}, slotProps.root), /*#__PURE__*/React.createElement(slots.track, __assign({}, slotProps.track)), /*#__PURE__*/React.createElement(slots.thumbWrapper, __assign({}, slotProps.thumbWrapper), /*#__PURE__*/React.createElement(slots.thumb, __assign({}, slotProps.thumb))), /*#__PURE__*/React.createElement(slots.input, __assign({}, slotProps.input)), /*#__PURE__*/React.createElement(slots.activeRail, __assign({}, slotProps.activeRail)));
7
+ export const renderSwitch_unstable = state => {
8
+ const {
9
+ slots,
10
+ slotProps
11
+ } = getSlots(state);
12
+ const {
13
+ labelPosition
14
+ } = state;
15
+ return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
16
+ }, /*#__PURE__*/React.createElement(slots.input, { ...slotProps.input
17
+ }), labelPosition !== 'after' && slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
18
+ }), /*#__PURE__*/React.createElement(slots.indicator, { ...slotProps.indicator
19
+ }), labelPosition === 'after' && slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
20
+ }));
15
21
  };
16
22
  //# sourceMappingURL=renderSwitch.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Switch/renderSwitch.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AACA,SAAS,oBAAT,QAAqC,aAArC;AAGA;;AAEG;;AACH,OAAO,IAAM,YAAY,GAAG,UAAC,KAAD,EAAmB;AACvC,MAAA,EAAA,GAAuB,QAAQ,CAAc,KAAd,EAAqB,oBAArB,CAA/B;AAAA,MAAE,KAAK,GAAA,EAAA,CAAA,KAAP;AAAA,MAAS,SAAS,GAAA,EAAA,CAAA,SAAlB;;AAEN,sBACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,IAAf,CAAX,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,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EAAA,GAAK,SAAS,CAAC;AAAf,GAAhB,CAHF,EAIG,aAAa,KAAK,OAAlB,IAA6B,KAAK,CAAC,KAAnC,iBAA4C,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CAJ/C,CADF;AAQD,CAZM","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;
@@ -1,63 +1,79 @@
1
- import { __assign } from "tslib";
2
- import { getNativeElementProps, resolveShorthand, useId } from '@fluentui/react-utilities';
3
- import { useSwitchState } from './useSwitchState';
1
+ import * as React from 'react';
2
+ import { CircleFilled } from '@fluentui/react-icons';
3
+ import { Label } from '@fluentui/react-label';
4
+ import { getPartitionedNativeProps, resolveShorthand, useId, useMergedEventCallbacks } from '@fluentui/react-utilities';
4
5
  /**
5
- * Array of all shorthand properties listed in SwitchSlots
6
+ * Create the state required to render Switch.
7
+ *
8
+ * The returned state can be modified with hooks such as useSwitchStyles_unstable,
9
+ * before being passed to renderSwitch_unstable.
10
+ *
11
+ * @param props - props from this instance of Switch
12
+ * @param ref - reference to `<input>` element of Switch
6
13
  */
7
14
 
8
- export var switchShorthandProps = ['root', 'track', 'thumbWrapper', 'thumb', 'activeRail', 'input'];
9
- /**
10
- * Given user props, returns state and render function for a Switch.
11
- */
12
-
13
- export var useSwitch = function (props, ref) {
14
- var track = props.track,
15
- thumbWrapper = props.thumbWrapper,
16
- thumb = props.thumb,
17
- activeRail = props.activeRail,
18
- input = props.input,
19
- defaultChecked = props.defaultChecked,
20
- checked = props.checked,
21
- disabled = props.disabled,
22
- onChange = props.onChange;
23
- var state = {
24
- defaultChecked: defaultChecked,
25
- checked: checked,
26
- disabled: disabled,
27
- onChange: onChange,
28
- root: getNativeElementProps('span', __assign(__assign({
29
- ref: ref
30
- }, props), {
31
- id: useId('switch-', props.id)
32
- })),
15
+ export const useSwitch_unstable = (props, ref) => {
16
+ const {
17
+ checked,
18
+ defaultChecked,
19
+ disabled,
20
+ labelPosition = 'after',
21
+ onChange,
22
+ required
23
+ } = props;
24
+ const nativeProps = getPartitionedNativeProps({
25
+ props,
26
+ primarySlotTagName: 'input',
27
+ excludedPropNames: ['checked', 'defaultChecked', 'onChange']
28
+ });
29
+ const id = useId('switch-', nativeProps.primary.id);
30
+ const root = resolveShorthand(props.root, {
31
+ defaultProps: nativeProps.root,
32
+ required: true
33
+ });
34
+ const indicator = resolveShorthand(props.indicator, {
35
+ defaultProps: {
36
+ 'aria-hidden': true,
37
+ children: /*#__PURE__*/React.createElement(CircleFilled, null)
38
+ },
39
+ required: true
40
+ });
41
+ const input = resolveShorthand(props.input, {
42
+ defaultProps: {
43
+ checked,
44
+ defaultChecked,
45
+ id,
46
+ ref,
47
+ role: 'switch',
48
+ type: 'checkbox',
49
+ ...nativeProps.primary
50
+ },
51
+ required: true
52
+ });
53
+ input.onChange = useMergedEventCallbacks(input.onChange, ev => onChange === null || onChange === void 0 ? void 0 : onChange(ev, {
54
+ checked: ev.currentTarget.checked
55
+ }));
56
+ const label = resolveShorthand(props.label, {
57
+ defaultProps: {
58
+ disabled,
59
+ htmlFor: id,
60
+ required,
61
+ size: 'medium'
62
+ }
63
+ });
64
+ return {
65
+ labelPosition,
66
+ //Slots definition
33
67
  components: {
34
68
  root: 'div',
35
- track: 'div',
36
- thumbWrapper: 'div',
37
- thumb: 'div',
38
- activeRail: 'div',
39
- input: 'input'
69
+ indicator: 'div',
70
+ input: 'input',
71
+ label: Label
40
72
  },
41
- track: resolveShorthand(track, {
42
- required: true
43
- }),
44
- thumbWrapper: resolveShorthand(thumbWrapper, {
45
- required: true
46
- }),
47
- thumb: resolveShorthand(thumb, {
48
- required: true
49
- }),
50
- activeRail: resolveShorthand(activeRail, {
51
- required: true
52
- }),
53
- input: resolveShorthand(input, {
54
- required: true,
55
- defaultProps: {
56
- type: 'checkbox'
57
- }
58
- })
73
+ root,
74
+ indicator,
75
+ input,
76
+ label
59
77
  };
60
- useSwitchState(state);
61
- return state;
62
78
  };
63
79
  //# sourceMappingURL=useSwitch.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Switch/useSwitch.ts"],"names":[],"mappings":";AACA,SAAS,qBAAT,EAAgC,gBAAhC,EAAkD,KAAlD,QAA+D,2BAA/D;AACA,SAAS,cAAT,QAA+B,kBAA/B;AAGA;;AAEG;;AACH,OAAO,IAAM,oBAAoB,GAA0B,CACzD,MADyD,EAEzD,OAFyD,EAGzD,cAHyD,EAIzD,OAJyD,EAKzD,YALyD,EAMzD,OANyD,CAApD;AASP;;A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AI,EAAE,KADI;AAEV,MAAA,SAAS,EAAE,KAFD;AAGV,MAAA,KAAK,EAAE,OAHG;AAIV,MAAA,KAAK,EAAE;AAJG,KAJP;AAWL,IAAA,IAXK;AAYL,IAAA,SAZK;AAaL,IAAA,KAbK;AAcL,IAAA;AAdK,GAAP;AAgBD,CA/DM","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;