@fluentui/react-switch 9.0.0-rc.1 → 9.0.0-rc.5

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 (44) hide show
  1. package/CHANGELOG.json +130 -1
  2. package/CHANGELOG.md +43 -2
  3. package/dist/react-switch.d.ts +56 -40
  4. package/lib/Switch.js.map +1 -1
  5. package/lib/components/Switch/Switch.d.ts +1 -1
  6. package/lib/components/Switch/Switch.js +1 -1
  7. package/lib/components/Switch/Switch.js.map +1 -1
  8. package/lib/components/Switch/Switch.types.d.ts +41 -35
  9. package/lib/components/Switch/Switch.types.js.map +1 -1
  10. package/lib/components/Switch/index.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 +4 -2
  18. package/lib/components/Switch/useSwitchStyles.js +144 -262
  19. package/lib/components/Switch/useSwitchStyles.js.map +1 -1
  20. package/lib/index.js.map +1 -1
  21. package/lib-commonjs/Switch.js.map +1 -1
  22. package/lib-commonjs/components/Switch/Switch.d.ts +1 -1
  23. package/lib-commonjs/components/Switch/Switch.js +1 -1
  24. package/lib-commonjs/components/Switch/Switch.js.map +1 -1
  25. package/lib-commonjs/components/Switch/Switch.types.d.ts +41 -35
  26. package/lib-commonjs/components/Switch/Switch.types.js.map +1 -1
  27. package/lib-commonjs/components/Switch/index.js.map +1 -1
  28. package/lib-commonjs/components/Switch/renderSwitch.d.ts +1 -1
  29. package/lib-commonjs/components/Switch/renderSwitch.js +8 -6
  30. package/lib-commonjs/components/Switch/renderSwitch.js.map +1 -1
  31. package/lib-commonjs/components/Switch/useSwitch.d.ts +8 -2
  32. package/lib-commonjs/components/Switch/useSwitch.js +65 -43
  33. package/lib-commonjs/components/Switch/useSwitch.js.map +1 -1
  34. package/lib-commonjs/components/Switch/useSwitchStyles.d.ts +4 -2
  35. package/lib-commonjs/components/Switch/useSwitchStyles.js +146 -264
  36. package/lib-commonjs/components/Switch/useSwitchStyles.js.map +1 -1
  37. package/lib-commonjs/index.js.map +1 -1
  38. package/package.json +14 -5
  39. package/lib/components/Switch/useSwitchState.d.ts +0 -2
  40. package/lib/components/Switch/useSwitchState.js +0 -144
  41. package/lib/components/Switch/useSwitchState.js.map +0 -1
  42. package/lib-commonjs/components/Switch/useSwitchState.d.ts +0 -2
  43. package/lib-commonjs/components/Switch/useSwitchState.js +0 -156
  44. package/lib-commonjs/components/Switch/useSwitchState.js.map +0 -1
package/CHANGELOG.json CHANGED
@@ -2,7 +2,136 @@
2
2
  "name": "@fluentui/react-switch",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 10 Feb 2022 08:44:05 GMT",
5
+ "date": "Fri, 04 Mar 2022 05:15:44 GMT",
6
+ "tag": "@fluentui/react-switch_v9.0.0-rc.5",
7
+ "version": "9.0.0-rc.5",
8
+ "comments": {
9
+ "prerelease": [
10
+ {
11
+ "author": "dzearing@microsoft.com",
12
+ "package": "@fluentui/react-switch",
13
+ "commit": "f2f1c0ea948cc3517eeb442c05433eb0918def29",
14
+ "comment": "Adding explicit export maps on all consumer packages for FUIR 8 and 9."
15
+ },
16
+ {
17
+ "author": "email not defined",
18
+ "package": "@fluentui/react-switch",
19
+ "commit": "852bd412ad6a682db9dfa44b7275f23fcaccb298",
20
+ "comment": "Updating class names to use slot class names helper type."
21
+ },
22
+ {
23
+ "author": "beachball",
24
+ "package": "@fluentui/react-switch",
25
+ "comment": "Bump @fluentui/react-label to v9.0.0-beta.9",
26
+ "commit": "1494f0b620f6d5aae7f0aef33fc9e8f6eb7f8749"
27
+ },
28
+ {
29
+ "author": "beachball",
30
+ "package": "@fluentui/react-switch",
31
+ "comment": "Bump @fluentui/react-tabster to v9.0.0-rc.5",
32
+ "commit": "1494f0b620f6d5aae7f0aef33fc9e8f6eb7f8749"
33
+ },
34
+ {
35
+ "author": "beachball",
36
+ "package": "@fluentui/react-switch",
37
+ "comment": "Bump @fluentui/react-theme to v9.0.0-rc.4",
38
+ "commit": "1494f0b620f6d5aae7f0aef33fc9e8f6eb7f8749"
39
+ },
40
+ {
41
+ "author": "beachball",
42
+ "package": "@fluentui/react-switch",
43
+ "comment": "Bump @fluentui/react-utilities to v9.0.0-rc.5",
44
+ "commit": "1494f0b620f6d5aae7f0aef33fc9e8f6eb7f8749"
45
+ }
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ "date": "Tue, 01 Mar 2022 02:17:38 GMT",
51
+ "tag": "@fluentui/react-switch_v9.0.0-rc.4",
52
+ "version": "9.0.0-rc.4",
53
+ "comments": {
54
+ "prerelease": [
55
+ {
56
+ "author": "Humberto.Morimoto@microsoft.com",
57
+ "package": "@fluentui/react-switch",
58
+ "commit": "72b08d56fa19f3b580da0497758af54a6afcf69b",
59
+ "comment": "Switch: Re-implementing component to make it simpler and making it adhere to latest patterns."
60
+ },
61
+ {
62
+ "author": "olfedias@microsoft.com",
63
+ "package": "@fluentui/react-switch",
64
+ "commit": "084d7408855f3e52b67cbca172da1acef9dcb98f",
65
+ "comment": "fix: Add react-theme as dependency"
66
+ },
67
+ {
68
+ "author": "beachball",
69
+ "package": "@fluentui/react-switch",
70
+ "comment": "Bump @fluentui/react-label to v9.0.0-beta.8",
71
+ "commit": "0bc1e755543ed69443d5d03e1976c630583242f7"
72
+ },
73
+ {
74
+ "author": "beachball",
75
+ "package": "@fluentui/react-switch",
76
+ "comment": "Bump @fluentui/react-tabster to v9.0.0-rc.4",
77
+ "commit": "0bc1e755543ed69443d5d03e1976c630583242f7"
78
+ },
79
+ {
80
+ "author": "beachball",
81
+ "package": "@fluentui/react-switch",
82
+ "comment": "Bump @fluentui/react-utilities to v9.0.0-rc.4",
83
+ "commit": "0bc1e755543ed69443d5d03e1976c630583242f7"
84
+ }
85
+ ]
86
+ }
87
+ },
88
+ {
89
+ "date": "Fri, 18 Feb 2022 13:35:34 GMT",
90
+ "tag": "@fluentui/react-switch_v9.0.0-rc.3",
91
+ "version": "9.0.0-rc.3",
92
+ "comments": {
93
+ "prerelease": [
94
+ {
95
+ "author": "mgodbolt@microsoft.com",
96
+ "package": "@fluentui/react-switch",
97
+ "commit": "2c9804dd585c1b485736c34321264dc62abe6fe1",
98
+ "comment": "fix visual display of controlled switches"
99
+ },
100
+ {
101
+ "author": "lingfangao@hotmail.com",
102
+ "package": "@fluentui/react-switch",
103
+ "commit": "1aa9e691fcccd9a64168cea7941c0f1e71fa1d14",
104
+ "comment": "fix: Source maps contain original source code"
105
+ },
106
+ {
107
+ "author": "beachball",
108
+ "package": "@fluentui/react-switch",
109
+ "comment": "Bump @fluentui/react-shared-contexts to v9.0.0-rc.3",
110
+ "commit": "3b9c1e931c23173da3d1af0c696cdc58516ce504"
111
+ },
112
+ {
113
+ "author": "beachball",
114
+ "package": "@fluentui/react-switch",
115
+ "comment": "Bump @fluentui/react-tabster to v9.0.0-rc.3",
116
+ "commit": "3b9c1e931c23173da3d1af0c696cdc58516ce504"
117
+ },
118
+ {
119
+ "author": "beachball",
120
+ "package": "@fluentui/react-switch",
121
+ "comment": "Bump @fluentui/react-utilities to v9.0.0-rc.3",
122
+ "commit": "3b9c1e931c23173da3d1af0c696cdc58516ce504"
123
+ },
124
+ {
125
+ "author": "beachball",
126
+ "package": "@fluentui/react-switch",
127
+ "comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.3",
128
+ "commit": "3b9c1e931c23173da3d1af0c696cdc58516ce504"
129
+ }
130
+ ]
131
+ }
132
+ },
133
+ {
134
+ "date": "Thu, 10 Feb 2022 08:50:51 GMT",
6
135
  "tag": "@fluentui/react-switch_v9.0.0-rc.1",
7
136
  "version": "9.0.0-rc.1",
8
137
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,53 @@
1
1
  # Change Log - @fluentui/react-switch
2
2
 
3
- This log was last generated on Thu, 10 Feb 2022 08:44:05 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 04 Mar 2022 05:15:44 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.0.0-rc.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.0.0-rc.5)
8
+
9
+ Fri, 04 Mar 2022 05:15:44 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.0.0-rc.4..@fluentui/react-switch_v9.0.0-rc.5)
11
+
12
+ ### Changes
13
+
14
+ - Adding explicit export maps on all consumer packages for FUIR 8 and 9. ([PR #21508](https://github.com/microsoft/fluentui/pull/21508) by dzearing@microsoft.com)
15
+ - Updating class names to use slot class names helper type. ([PR #21933](https://github.com/microsoft/fluentui/pull/21933) by email not defined)
16
+ - Bump @fluentui/react-label to v9.0.0-beta.9 ([PR #21947](https://github.com/microsoft/fluentui/pull/21947) by beachball)
17
+ - Bump @fluentui/react-tabster to v9.0.0-rc.5 ([PR #21947](https://github.com/microsoft/fluentui/pull/21947) by beachball)
18
+ - Bump @fluentui/react-theme to v9.0.0-rc.4 ([PR #21947](https://github.com/microsoft/fluentui/pull/21947) by beachball)
19
+ - Bump @fluentui/react-utilities to v9.0.0-rc.5 ([PR #21947](https://github.com/microsoft/fluentui/pull/21947) by beachball)
20
+
21
+ ## [9.0.0-rc.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.0.0-rc.4)
22
+
23
+ Tue, 01 Mar 2022 02:17:38 GMT
24
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.0.0-rc.3..@fluentui/react-switch_v9.0.0-rc.4)
25
+
26
+ ### Changes
27
+
28
+ - Switch: Re-implementing component to make it simpler and making it adhere to latest patterns. ([PR #21849](https://github.com/microsoft/fluentui/pull/21849) by Humberto.Morimoto@microsoft.com)
29
+ - fix: Add react-theme as dependency ([PR #21825](https://github.com/microsoft/fluentui/pull/21825) by olfedias@microsoft.com)
30
+ - Bump @fluentui/react-label to v9.0.0-beta.8 ([PR #21884](https://github.com/microsoft/fluentui/pull/21884) by beachball)
31
+ - Bump @fluentui/react-tabster to v9.0.0-rc.4 ([PR #21884](https://github.com/microsoft/fluentui/pull/21884) by beachball)
32
+ - Bump @fluentui/react-utilities to v9.0.0-rc.4 ([PR #21884](https://github.com/microsoft/fluentui/pull/21884) by beachball)
33
+
34
+ ## [9.0.0-rc.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.0.0-rc.3)
35
+
36
+ Fri, 18 Feb 2022 13:35:34 GMT
37
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.0.0-rc.1..@fluentui/react-switch_v9.0.0-rc.3)
38
+
39
+ ### Changes
40
+
41
+ - fix visual display of controlled switches ([PR #21704](https://github.com/microsoft/fluentui/pull/21704) by mgodbolt@microsoft.com)
42
+ - fix: Source maps contain original source code ([PR #21690](https://github.com/microsoft/fluentui/pull/21690) by lingfangao@hotmail.com)
43
+ - Bump @fluentui/react-shared-contexts to v9.0.0-rc.3 ([PR #21800](https://github.com/microsoft/fluentui/pull/21800) by beachball)
44
+ - Bump @fluentui/react-tabster to v9.0.0-rc.3 ([PR #21800](https://github.com/microsoft/fluentui/pull/21800) by beachball)
45
+ - Bump @fluentui/react-utilities to v9.0.0-rc.3 ([PR #21800](https://github.com/microsoft/fluentui/pull/21800) by beachball)
46
+ - Bump @fluentui/react-conformance-griffel to v9.0.0-beta.3 ([PR #21800](https://github.com/microsoft/fluentui/pull/21800) by beachball)
47
+
7
48
  ## [9.0.0-rc.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.0.0-rc.1)
8
49
 
9
- Thu, 10 Feb 2022 08:44:05 GMT
50
+ Thu, 10 Feb 2022 08:50:51 GMT
10
51
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.0.0-beta.5..@fluentui/react-switch_v9.0.0-rc.1)
11
52
 
12
53
  ### Changes
@@ -1,85 +1,101 @@
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 { Label } from '@fluentui/react-label';
4
5
  import * as React_2 from 'react';
5
6
  import type { Slot } from '@fluentui/react-utilities';
7
+ import type { SlotClassNames } from '@fluentui/react-utilities';
6
8
 
7
9
  /**
8
- * Render the final JSX of Switch
10
+ * Render a Switch component by passing the state defined props to the appropriate slots.
9
11
  */
10
12
  export declare const renderSwitch_unstable: (state: SwitchState) => JSX.Element;
11
13
 
12
14
  /**
13
- * The Switch control enables users to trigger an option on or off through pressing on the component.
15
+ * Switches enable users to trigger an option on or off through pressing the component.
14
16
  */
15
17
  export declare const Switch: ForwardRefComponent<SwitchProps>;
16
18
 
17
- export declare const switchClassName = "fui-Switch";
19
+ export declare const switchClassName: string;
18
20
 
19
- declare interface SwitchCommons {
21
+ export declare const switchClassNames: SlotClassNames<SwitchSlots>;
22
+
23
+ declare type SwitchCommons = {
20
24
  /**
21
- * The starting value for a uncontrolled Switch. If `true` then the Switch will be enabled.
22
- * Mutually exclusive with `checked` prop.
23
- *
25
+ * Defines the controlled checked state of the Switch.
26
+ * If passed, Switch ignores the `defaultChecked` property.
27
+ * 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
28
+ * correct value based on handling `onChange` events and re-rendering.
24
29
  * @default false
25
30
  */
26
- defaultChecked?: boolean;
27
- /**
28
- * The current value for a controlled Switch. If `true` then the Switch will be enabled.
29
- * Mutually exclusive with `defaultChecked` prop.
30
- */
31
31
  checked?: boolean;
32
32
  /**
33
- * Whether the Switch should be disabled.
33
+ * The position of the label relative to the Switch.
34
34
  *
35
- * @default false
35
+ * @default after
36
36
  */
37
- disabled?: boolean;
38
- /**
39
- * Callback to be called when the `checked` value changes.
40
- */
41
- onChange?: (ev: React_2.PointerEvent<HTMLDivElement> | React_2.KeyboardEvent<HTMLDivElement>, data: {
42
- checked: boolean;
43
- }) => void;
44
- }
37
+ labelPosition: 'above' | 'after' | 'before';
38
+ };
45
39
 
46
- export declare interface SwitchProps extends Omit<ComponentProps<Partial<SwitchSlots>>, 'onChange'>, SwitchCommons {
47
- }
40
+ export declare type SwitchOnChangeData = {
41
+ checked: boolean;
42
+ };
48
43
 
49
- export declare type SwitchSlots = {
44
+ /**
45
+ * Switch Props
46
+ */
47
+ export declare type SwitchProps = Omit<ComponentProps<Partial<SwitchSlots>, 'input'>, 'onChange'> & Partial<SwitchCommons> & {
50
48
  /**
51
- * The root of the Switch.
49
+ * Defines whether the Switch is initially in a checked state or not when rendered.
50
+ * @default false
52
51
  */
53
- root: Slot<'div'>;
52
+ defaultChecked?: boolean;
54
53
  /**
55
- * The bar indicating the status of the Switch.
54
+ * Callback to be called when the checked state value changes.
56
55
  */
57
- track: NonNullable<Slot<'div'>>;
56
+ onChange?: (ev: React_2.ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => void;
57
+ };
58
+
59
+ export declare type SwitchSlots = {
58
60
  /**
59
- * The wrapper around the thumb. It is used as the active area for the thumb to position itself.
61
+ * The root element of the Switch.
62
+ *
63
+ * The root slot receives the `className` and `style` specified directly on the `<Switch>` tag.
64
+ * All other native props will be applied to the primary slot: `input`.
60
65
  */
61
- thumbWrapper: NonNullable<Slot<'div'>>;
66
+ root: NonNullable<Slot<'div'>>;
62
67
  /**
63
- * The circular icon indicating the status of the Switch.
68
+ * The track and the thumb sliding over it indicating the on and off status of the Switch.
64
69
  */
65
- thumb: NonNullable<Slot<'div'>>;
70
+ indicator: NonNullable<Slot<'div'>>;
66
71
  /**
67
- * The hidden input that handles the Switch's internal functionality.
72
+ * Hidden input that handles the Switch's functionality.
73
+ *
74
+ * This is the PRIMARY slot: all native properties specified directly on the `<Switch>` tag will be applied to this
75
+ * slot, except `className` and `style`, which remain on the root slot.
68
76
  */
69
77
  input: NonNullable<Slot<'input'>>;
70
78
  /**
71
- * The area in which the Switch's rail allows for the thumb to be dragged.
79
+ * The Switch's label.
72
80
  */
73
- activeRail: NonNullable<Slot<'div'>>;
81
+ label?: Slot<typeof Label>;
74
82
  };
75
83
 
76
- export declare interface SwitchState extends ComponentState<SwitchSlots>, SwitchCommons {
77
- }
84
+ /**
85
+ * State used in rendering Switch
86
+ */
87
+ export declare type SwitchState = ComponentState<SwitchSlots> & SwitchCommons;
78
88
 
79
89
  /**
80
- * Given user props, returns state and render function for a Switch.
90
+ * Create the state required to render Switch.
91
+ *
92
+ * The returned state can be modified with hooks such as useSwitchStyles_unstable,
93
+ * before being passed to renderSwitch_unstable.
94
+ *
95
+ * @param props - props from this instance of Switch
96
+ * @param ref - reference to `<input>` element of Switch
81
97
  */
82
- export declare const useSwitch_unstable: (props: SwitchProps, ref: React_2.Ref<HTMLElement>) => SwitchState;
98
+ export declare const useSwitch_unstable: (props: SwitchProps, ref: React_2.Ref<HTMLInputElement>) => SwitchState;
83
99
 
84
100
  /**
85
101
  * Apply styling to the Switch slots based on the state
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>;
@@ -3,7 +3,7 @@ import { useSwitch_unstable } from './useSwitch';
3
3
  import { renderSwitch_unstable } from './renderSwitch';
4
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
9
  export const Switch = /*#__PURE__*/React.forwardRef((props, ref) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/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","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,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 +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
5
  export declare const renderSwitch_unstable: (state: SwitchState) => JSX.Element;
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { getSlots } from '@fluentui/react-utilities';
3
3
  /**
4
- * Render the final JSX of Switch
4
+ * Render a Switch component by passing the state defined props to the appropriate slots.
5
5
  */
6
6
 
7
7
  export const renderSwitch_unstable = state => {
@@ -9,12 +9,14 @@ export const renderSwitch_unstable = state => {
9
9
  slots,
10
10
  slotProps
11
11
  } = getSlots(state);
12
+ const {
13
+ labelPosition
14
+ } = state;
12
15
  return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
13
- }, /*#__PURE__*/React.createElement(slots.track, { ...slotProps.track
14
- }), /*#__PURE__*/React.createElement(slots.thumbWrapper, { ...slotProps.thumbWrapper
15
- }, /*#__PURE__*/React.createElement(slots.thumb, { ...slotProps.thumb
16
- })), /*#__PURE__*/React.createElement(slots.input, { ...slotProps.input
17
- }), /*#__PURE__*/React.createElement(slots.activeRail, { ...slotProps.activeRail
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
18
20
  }));
19
21
  };
20
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;AAGA;;AAEG;;AACH,OAAO,MAAM,qBAAqB,GAAI,KAAD,IAAuB;AAC1D,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,QAAQ,CAAc,KAAd,CAArC;AAEA,sBACE,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","sourceRoot":""}
1
+ {"version":3,"sources":["components/Switch/renderSwitch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,qBAAqB,GAAI,KAAD,IAAuB;AAC1D,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,QAAQ,CAAc,KAAd,CAArC;AACA,QAAM;AAAE,IAAA;AAAF,MAAoB,KAA1B;AAEA,sBACE,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,iBAA4C,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,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,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;