@fluentui/react-switch 9.0.0-alpha.5 → 9.0.0-alpha.9

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 (64) hide show
  1. package/CHANGELOG.json +227 -1
  2. package/CHANGELOG.md +62 -2
  3. package/dist/react-switch.d.ts +5 -1
  4. package/lib/Switch.js.map +1 -1
  5. package/lib/common/isConformant.js.map +1 -1
  6. package/lib/components/Switch/Switch.js.map +1 -1
  7. package/lib/components/Switch/Switch.types.d.ts +5 -1
  8. package/lib/components/Switch/Switch.types.js.map +1 -1
  9. package/lib/components/Switch/index.js.map +1 -1
  10. package/lib/components/Switch/renderSwitch.js +1 -1
  11. package/lib/components/Switch/renderSwitch.js.map +1 -1
  12. package/lib/components/Switch/useSwitch.js +6 -1
  13. package/lib/components/Switch/useSwitch.js.map +1 -1
  14. package/lib/components/Switch/useSwitchState.js +125 -19
  15. package/lib/components/Switch/useSwitchState.js.map +1 -1
  16. package/lib/components/Switch/useSwitchStyles.js +154 -82
  17. package/lib/components/Switch/useSwitchStyles.js.map +1 -1
  18. package/lib/index.js.map +1 -1
  19. package/lib-commonjs/Switch.js.map +1 -1
  20. package/lib-commonjs/common/isConformant.js.map +1 -1
  21. package/lib-commonjs/components/Switch/Switch.js.map +1 -1
  22. package/lib-commonjs/components/Switch/Switch.types.d.ts +5 -1
  23. package/lib-commonjs/components/Switch/Switch.types.js.map +1 -1
  24. package/lib-commonjs/components/Switch/index.js.map +1 -1
  25. package/lib-commonjs/components/Switch/renderSwitch.js +1 -1
  26. package/lib-commonjs/components/Switch/renderSwitch.js.map +1 -1
  27. package/lib-commonjs/components/Switch/useSwitch.js +6 -1
  28. package/lib-commonjs/components/Switch/useSwitch.js.map +1 -1
  29. package/lib-commonjs/components/Switch/useSwitchState.js +124 -18
  30. package/lib-commonjs/components/Switch/useSwitchState.js.map +1 -1
  31. package/lib-commonjs/components/Switch/useSwitchStyles.js +154 -82
  32. package/lib-commonjs/components/Switch/useSwitchStyles.js.map +1 -1
  33. package/lib-commonjs/index.js.map +1 -1
  34. package/package.json +13 -13
  35. package/lib-amd/Switch.d.ts +0 -1
  36. package/lib-amd/Switch.js +0 -6
  37. package/lib-amd/Switch.js.map +0 -1
  38. package/lib-amd/common/isConformant.d.ts +0 -4
  39. package/lib-amd/common/isConformant.js +0 -16
  40. package/lib-amd/common/isConformant.js.map +0 -1
  41. package/lib-amd/components/Switch/Switch.d.ts +0 -6
  42. package/lib-amd/components/Switch/Switch.js +0 -15
  43. package/lib-amd/components/Switch/Switch.js.map +0 -1
  44. package/lib-amd/components/Switch/Switch.types.d.ts +0 -54
  45. package/lib-amd/components/Switch/Switch.types.js +0 -5
  46. package/lib-amd/components/Switch/Switch.types.js.map +0 -1
  47. package/lib-amd/components/Switch/index.d.ts +0 -5
  48. package/lib-amd/components/Switch/index.js +0 -10
  49. package/lib-amd/components/Switch/index.js.map +0 -1
  50. package/lib-amd/components/Switch/renderSwitch.d.ts +0 -5
  51. package/lib-amd/components/Switch/renderSwitch.js +0 -18
  52. package/lib-amd/components/Switch/renderSwitch.js.map +0 -1
  53. package/lib-amd/components/Switch/useSwitch.d.ts +0 -10
  54. package/lib-amd/components/Switch/useSwitch.js +0 -42
  55. package/lib-amd/components/Switch/useSwitch.js.map +0 -1
  56. package/lib-amd/components/Switch/useSwitchState.d.ts +0 -2
  57. package/lib-amd/components/Switch/useSwitchState.js +0 -44
  58. package/lib-amd/components/Switch/useSwitchState.js.map +0 -1
  59. package/lib-amd/components/Switch/useSwitchStyles.d.ts +0 -5
  60. package/lib-amd/components/Switch/useSwitchStyles.js +0 -161
  61. package/lib-amd/components/Switch/useSwitchStyles.js.map +0 -1
  62. package/lib-amd/index.d.ts +0 -2
  63. package/lib-amd/index.js +0 -6
  64. package/lib-amd/index.js.map +0 -1
package/CHANGELOG.json CHANGED
@@ -2,7 +2,233 @@
2
2
  "name": "@fluentui/react-switch",
3
3
  "entries": [
4
4
  {
5
- "date": "Fri, 17 Sep 2021 07:32:57 GMT",
5
+ "date": "Thu, 23 Sep 2021 08:19:56 GMT",
6
+ "tag": "@fluentui/react-switch_v9.0.0-alpha.9",
7
+ "version": "9.0.0-alpha.9",
8
+ "comments": {
9
+ "none": [
10
+ {
11
+ "author": "czearing@outlook.com",
12
+ "package": "@fluentui/react-switch",
13
+ "comment": "Importing clamp from react-utilities.",
14
+ "commit": "95682da34c48813f7658032ae490d21d2f363b90"
15
+ }
16
+ ],
17
+ "prerelease": [
18
+ {
19
+ "author": "czearing@outlook.com",
20
+ "package": "@fluentui/react-switch",
21
+ "comment": "Adding dragging to the Switch component.",
22
+ "commit": "95682da34c48813f7658032ae490d21d2f363b90"
23
+ },
24
+ {
25
+ "author": "beachball",
26
+ "package": "@fluentui/react-switch",
27
+ "comment": "Bump @fluentui/react-make-styles to v9.0.0-alpha.71",
28
+ "commit": "95682da34c48813f7658032ae490d21d2f363b90"
29
+ },
30
+ {
31
+ "author": "beachball",
32
+ "package": "@fluentui/react-switch",
33
+ "comment": "Bump @fluentui/react-tabster to v9.0.0-alpha.65",
34
+ "commit": "95682da34c48813f7658032ae490d21d2f363b90"
35
+ },
36
+ {
37
+ "author": "beachball",
38
+ "package": "@fluentui/react-switch",
39
+ "comment": "Bump @fluentui/react-utilities to v9.0.0-alpha.51",
40
+ "commit": "95682da34c48813f7658032ae490d21d2f363b90"
41
+ },
42
+ {
43
+ "author": "beachball",
44
+ "package": "@fluentui/react-switch",
45
+ "comment": "Bump @fluentui/babel-make-styles to v9.0.0-alpha.53",
46
+ "commit": "95682da34c48813f7658032ae490d21d2f363b90"
47
+ },
48
+ {
49
+ "author": "beachball",
50
+ "package": "@fluentui/react-switch",
51
+ "comment": "Bump @fluentui/jest-serializer-make-styles to v9.0.0-alpha.46",
52
+ "commit": "95682da34c48813f7658032ae490d21d2f363b90"
53
+ },
54
+ {
55
+ "author": "beachball",
56
+ "package": "@fluentui/react-switch",
57
+ "comment": "Bump @fluentui/react-conformance-make-styles to v9.0.0-alpha.15",
58
+ "commit": "95682da34c48813f7658032ae490d21d2f363b90"
59
+ },
60
+ {
61
+ "author": "beachball",
62
+ "package": "@fluentui/react-switch",
63
+ "comment": "Bump @fluentui/react-label to v9.0.0-alpha.44",
64
+ "commit": "95682da34c48813f7658032ae490d21d2f363b90"
65
+ },
66
+ {
67
+ "author": "beachball",
68
+ "package": "@fluentui/react-switch",
69
+ "comment": "Bump @fluentui/react-provider to v9.0.0-alpha.82",
70
+ "commit": "95682da34c48813f7658032ae490d21d2f363b90"
71
+ }
72
+ ]
73
+ }
74
+ },
75
+ {
76
+ "date": "Wed, 22 Sep 2021 10:10:07 GMT",
77
+ "tag": "@fluentui/react-switch_v9.0.0-alpha.8",
78
+ "version": "9.0.0-alpha.8",
79
+ "comments": {
80
+ "prerelease": [
81
+ {
82
+ "author": "czearing@outlook.com",
83
+ "package": "@fluentui/react-switch",
84
+ "comment": "Adding switch role to the hidden input element.",
85
+ "commit": "bc3f1ec72fc7784a558b0dd6598ee0662f4649c1"
86
+ },
87
+ {
88
+ "author": "beachball",
89
+ "package": "@fluentui/react-switch",
90
+ "comment": "Bump @fluentui/react-make-styles to v9.0.0-alpha.70",
91
+ "commit": "bc3f1ec72fc7784a558b0dd6598ee0662f4649c1"
92
+ },
93
+ {
94
+ "author": "beachball",
95
+ "package": "@fluentui/react-switch",
96
+ "comment": "Bump @fluentui/react-tabster to v9.0.0-alpha.64",
97
+ "commit": "bc3f1ec72fc7784a558b0dd6598ee0662f4649c1"
98
+ },
99
+ {
100
+ "author": "beachball",
101
+ "package": "@fluentui/react-switch",
102
+ "comment": "Bump @fluentui/react-utilities to v9.0.0-alpha.50",
103
+ "commit": "bc3f1ec72fc7784a558b0dd6598ee0662f4649c1"
104
+ },
105
+ {
106
+ "author": "beachball",
107
+ "package": "@fluentui/react-switch",
108
+ "comment": "Bump @fluentui/babel-make-styles to v9.0.0-alpha.52",
109
+ "commit": "bc3f1ec72fc7784a558b0dd6598ee0662f4649c1"
110
+ },
111
+ {
112
+ "author": "beachball",
113
+ "package": "@fluentui/react-switch",
114
+ "comment": "Bump @fluentui/jest-serializer-make-styles to v9.0.0-alpha.45",
115
+ "commit": "bc3f1ec72fc7784a558b0dd6598ee0662f4649c1"
116
+ },
117
+ {
118
+ "author": "beachball",
119
+ "package": "@fluentui/react-switch",
120
+ "comment": "Bump @fluentui/react-conformance-make-styles to v9.0.0-alpha.14",
121
+ "commit": "bc3f1ec72fc7784a558b0dd6598ee0662f4649c1"
122
+ },
123
+ {
124
+ "author": "beachball",
125
+ "package": "@fluentui/react-switch",
126
+ "comment": "Bump @fluentui/react-label to v9.0.0-alpha.43",
127
+ "commit": "bc3f1ec72fc7784a558b0dd6598ee0662f4649c1"
128
+ },
129
+ {
130
+ "author": "beachball",
131
+ "package": "@fluentui/react-switch",
132
+ "comment": "Bump @fluentui/react-provider to v9.0.0-alpha.81",
133
+ "commit": "bc3f1ec72fc7784a558b0dd6598ee0662f4649c1"
134
+ }
135
+ ]
136
+ }
137
+ },
138
+ {
139
+ "date": "Tue, 21 Sep 2021 07:42:34 GMT",
140
+ "tag": "@fluentui/react-switch_v9.0.0-alpha.7",
141
+ "version": "9.0.0-alpha.7",
142
+ "comments": {
143
+ "prerelease": [
144
+ {
145
+ "author": "beachball",
146
+ "package": "@fluentui/react-switch",
147
+ "comment": "Bump @fluentui/react-make-styles to v9.0.0-alpha.69",
148
+ "commit": "363765ba3d08d2facbb97fb80ab54ff27ac714fd"
149
+ },
150
+ {
151
+ "author": "beachball",
152
+ "package": "@fluentui/react-switch",
153
+ "comment": "Bump @fluentui/react-shared-contexts to v9.0.0-alpha.25",
154
+ "commit": "363765ba3d08d2facbb97fb80ab54ff27ac714fd"
155
+ },
156
+ {
157
+ "author": "beachball",
158
+ "package": "@fluentui/react-switch",
159
+ "comment": "Bump @fluentui/react-tabster to v9.0.0-alpha.63",
160
+ "commit": "363765ba3d08d2facbb97fb80ab54ff27ac714fd"
161
+ },
162
+ {
163
+ "author": "beachball",
164
+ "package": "@fluentui/react-switch",
165
+ "comment": "Bump @fluentui/babel-make-styles to v9.0.0-alpha.51",
166
+ "commit": "363765ba3d08d2facbb97fb80ab54ff27ac714fd"
167
+ },
168
+ {
169
+ "author": "beachball",
170
+ "package": "@fluentui/react-switch",
171
+ "comment": "Bump @fluentui/jest-serializer-make-styles to v9.0.0-alpha.44",
172
+ "commit": "363765ba3d08d2facbb97fb80ab54ff27ac714fd"
173
+ },
174
+ {
175
+ "author": "beachball",
176
+ "package": "@fluentui/react-switch",
177
+ "comment": "Bump @fluentui/react-conformance-make-styles to v9.0.0-alpha.13",
178
+ "commit": "363765ba3d08d2facbb97fb80ab54ff27ac714fd"
179
+ },
180
+ {
181
+ "author": "beachball",
182
+ "package": "@fluentui/react-switch",
183
+ "comment": "Bump @fluentui/react-label to v9.0.0-alpha.42",
184
+ "commit": "363765ba3d08d2facbb97fb80ab54ff27ac714fd"
185
+ },
186
+ {
187
+ "author": "beachball",
188
+ "package": "@fluentui/react-switch",
189
+ "comment": "Bump @fluentui/react-provider to v9.0.0-alpha.80",
190
+ "commit": "363765ba3d08d2facbb97fb80ab54ff27ac714fd"
191
+ },
192
+ {
193
+ "author": "beachball",
194
+ "package": "@fluentui/react-switch",
195
+ "comment": "Bump @fluentui/react-theme to v9.0.0-alpha.23",
196
+ "commit": "363765ba3d08d2facbb97fb80ab54ff27ac714fd"
197
+ }
198
+ ]
199
+ }
200
+ },
201
+ {
202
+ "date": "Mon, 20 Sep 2021 07:36:26 GMT",
203
+ "tag": "@fluentui/react-switch_v9.0.0-alpha.6",
204
+ "version": "9.0.0-alpha.6",
205
+ "comments": {
206
+ "none": [
207
+ {
208
+ "author": "czearing@outlook.com",
209
+ "package": "@fluentui/react-switch",
210
+ "comment": "Adding missing theme tokens and updating styles.",
211
+ "commit": "b8a304770f77c0353553a152dad34421070400a6"
212
+ },
213
+ {
214
+ "author": "lingfangao@hotmail.com",
215
+ "package": "@fluentui/react-switch",
216
+ "comment": "chore: use versioon eslint-plugin and react-conformance in dev dependencies",
217
+ "commit": "b8a304770f77c0353553a152dad34421070400a6"
218
+ }
219
+ ],
220
+ "prerelease": [
221
+ {
222
+ "author": "lingfangao@hotmail.com",
223
+ "package": "@fluentui/react-switch",
224
+ "commit": "b8a304770f77c0353553a152dad34421070400a6",
225
+ "comment": "Bump @fluentui/react-switch to v9.0.0-alpha.6"
226
+ }
227
+ ]
228
+ }
229
+ },
230
+ {
231
+ "date": "Fri, 17 Sep 2021 07:35:26 GMT",
6
232
  "tag": "@fluentui/react-switch_v9.0.0-alpha.5",
7
233
  "version": "9.0.0-alpha.5",
8
234
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,72 @@
1
1
  # Change Log - @fluentui/react-switch
2
2
 
3
- This log was last generated on Fri, 17 Sep 2021 07:32:57 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 23 Sep 2021 08:19:56 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.0.0-alpha.9](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.0.0-alpha.9)
8
+
9
+ Thu, 23 Sep 2021 08:19:56 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.0.0-alpha.8..@fluentui/react-switch_v9.0.0-alpha.9)
11
+
12
+ ### Changes
13
+
14
+ - Adding dragging to the Switch component. ([commit](https://github.com/microsoft/fluentui/commit/95682da34c48813f7658032ae490d21d2f363b90) by czearing@outlook.com)
15
+ - Bump @fluentui/react-make-styles to v9.0.0-alpha.71 ([commit](https://github.com/microsoft/fluentui/commit/95682da34c48813f7658032ae490d21d2f363b90) by beachball)
16
+ - Bump @fluentui/react-tabster to v9.0.0-alpha.65 ([commit](https://github.com/microsoft/fluentui/commit/95682da34c48813f7658032ae490d21d2f363b90) by beachball)
17
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.51 ([commit](https://github.com/microsoft/fluentui/commit/95682da34c48813f7658032ae490d21d2f363b90) by beachball)
18
+ - Bump @fluentui/babel-make-styles to v9.0.0-alpha.53 ([commit](https://github.com/microsoft/fluentui/commit/95682da34c48813f7658032ae490d21d2f363b90) by beachball)
19
+ - Bump @fluentui/jest-serializer-make-styles to v9.0.0-alpha.46 ([commit](https://github.com/microsoft/fluentui/commit/95682da34c48813f7658032ae490d21d2f363b90) by beachball)
20
+ - Bump @fluentui/react-conformance-make-styles to v9.0.0-alpha.15 ([commit](https://github.com/microsoft/fluentui/commit/95682da34c48813f7658032ae490d21d2f363b90) by beachball)
21
+ - Bump @fluentui/react-label to v9.0.0-alpha.44 ([commit](https://github.com/microsoft/fluentui/commit/95682da34c48813f7658032ae490d21d2f363b90) by beachball)
22
+ - Bump @fluentui/react-provider to v9.0.0-alpha.82 ([commit](https://github.com/microsoft/fluentui/commit/95682da34c48813f7658032ae490d21d2f363b90) by beachball)
23
+
24
+ ## [9.0.0-alpha.8](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.0.0-alpha.8)
25
+
26
+ Wed, 22 Sep 2021 10:10:07 GMT
27
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.0.0-alpha.7..@fluentui/react-switch_v9.0.0-alpha.8)
28
+
29
+ ### Changes
30
+
31
+ - Adding switch role to the hidden input element. ([commit](https://github.com/microsoft/fluentui/commit/bc3f1ec72fc7784a558b0dd6598ee0662f4649c1) by czearing@outlook.com)
32
+ - Bump @fluentui/react-make-styles to v9.0.0-alpha.70 ([commit](https://github.com/microsoft/fluentui/commit/bc3f1ec72fc7784a558b0dd6598ee0662f4649c1) by beachball)
33
+ - Bump @fluentui/react-tabster to v9.0.0-alpha.64 ([commit](https://github.com/microsoft/fluentui/commit/bc3f1ec72fc7784a558b0dd6598ee0662f4649c1) by beachball)
34
+ - Bump @fluentui/react-utilities to v9.0.0-alpha.50 ([commit](https://github.com/microsoft/fluentui/commit/bc3f1ec72fc7784a558b0dd6598ee0662f4649c1) by beachball)
35
+ - Bump @fluentui/babel-make-styles to v9.0.0-alpha.52 ([commit](https://github.com/microsoft/fluentui/commit/bc3f1ec72fc7784a558b0dd6598ee0662f4649c1) by beachball)
36
+ - Bump @fluentui/jest-serializer-make-styles to v9.0.0-alpha.45 ([commit](https://github.com/microsoft/fluentui/commit/bc3f1ec72fc7784a558b0dd6598ee0662f4649c1) by beachball)
37
+ - Bump @fluentui/react-conformance-make-styles to v9.0.0-alpha.14 ([commit](https://github.com/microsoft/fluentui/commit/bc3f1ec72fc7784a558b0dd6598ee0662f4649c1) by beachball)
38
+ - Bump @fluentui/react-label to v9.0.0-alpha.43 ([commit](https://github.com/microsoft/fluentui/commit/bc3f1ec72fc7784a558b0dd6598ee0662f4649c1) by beachball)
39
+ - Bump @fluentui/react-provider to v9.0.0-alpha.81 ([commit](https://github.com/microsoft/fluentui/commit/bc3f1ec72fc7784a558b0dd6598ee0662f4649c1) by beachball)
40
+
41
+ ## [9.0.0-alpha.7](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.0.0-alpha.7)
42
+
43
+ Tue, 21 Sep 2021 07:42:34 GMT
44
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.0.0-alpha.6..@fluentui/react-switch_v9.0.0-alpha.7)
45
+
46
+ ### Changes
47
+
48
+ - Bump @fluentui/react-make-styles to v9.0.0-alpha.69 ([PR #19865](https://github.com/microsoft/fluentui/pull/19865) by beachball)
49
+ - Bump @fluentui/react-shared-contexts to v9.0.0-alpha.25 ([PR #19865](https://github.com/microsoft/fluentui/pull/19865) by beachball)
50
+ - Bump @fluentui/react-tabster to v9.0.0-alpha.63 ([PR #19865](https://github.com/microsoft/fluentui/pull/19865) by beachball)
51
+ - Bump @fluentui/babel-make-styles to v9.0.0-alpha.51 ([PR #19865](https://github.com/microsoft/fluentui/pull/19865) by beachball)
52
+ - Bump @fluentui/jest-serializer-make-styles to v9.0.0-alpha.44 ([PR #19865](https://github.com/microsoft/fluentui/pull/19865) by beachball)
53
+ - Bump @fluentui/react-conformance-make-styles to v9.0.0-alpha.13 ([PR #19865](https://github.com/microsoft/fluentui/pull/19865) by beachball)
54
+ - Bump @fluentui/react-label to v9.0.0-alpha.42 ([PR #19865](https://github.com/microsoft/fluentui/pull/19865) by beachball)
55
+ - Bump @fluentui/react-provider to v9.0.0-alpha.80 ([PR #19865](https://github.com/microsoft/fluentui/pull/19865) by beachball)
56
+ - Bump @fluentui/react-theme to v9.0.0-alpha.23 ([PR #19865](https://github.com/microsoft/fluentui/pull/19865) by beachball)
57
+
58
+ ## [9.0.0-alpha.6](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.0.0-alpha.6)
59
+
60
+ Mon, 20 Sep 2021 07:36:26 GMT
61
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.0.0-alpha.5..@fluentui/react-switch_v9.0.0-alpha.6)
62
+
63
+ ### Changes
64
+
65
+ - Bump @fluentui/react-switch to v9.0.0-alpha.6 ([PR #19844](https://github.com/microsoft/fluentui/pull/19844) by lingfangao@hotmail.com)
66
+
7
67
  ## [9.0.0-alpha.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.0.0-alpha.5)
8
68
 
9
- Fri, 17 Sep 2021 07:32:57 GMT
69
+ Fri, 17 Sep 2021 07:35:26 GMT
10
70
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.0.0-alpha.4..@fluentui/react-switch_v9.0.0-alpha.5)
11
71
 
12
72
  ### Changes
@@ -35,7 +35,7 @@ export declare interface SwitchCommons {
35
35
  /**
36
36
  * Callback to be called when the `checked` value changes.
37
37
  */
38
- onChange?: (ev: React_2.ChangeEvent<HTMLInputElement>, data: {
38
+ onChange?: (ev: React_2.PointerEvent<HTMLDivElement> | React_2.KeyboardEvent<HTMLDivElement>, data: {
39
39
  checked: boolean;
40
40
  }) => void;
41
41
  }
@@ -69,6 +69,10 @@ export declare type SwitchSlots = {
69
69
  * The hidden input that handles the Switch's internal functionality.
70
70
  */
71
71
  input: IntrinsicShorthandProps<'input'>;
72
+ /**
73
+ * The area in which the Switch's rail allows for the thumb to be dragged.
74
+ */
75
+ activeRail: IntrinsicShorthandProps<'div'>;
72
76
  };
73
77
 
74
78
  export declare interface SwitchState extends ComponentState<SwitchSlots>, SwitchCommons {
package/lib/Switch.js.map CHANGED
@@ -1 +1 @@
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
+ {"version":3,"file":"Switch.js","sourceRoot":"","sources":["../src/Switch.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["common/isConformant.ts"],"names":[],"mappings":"AAAA,SAAS,YAAY,IAAI,gBAAzB,QAAiD,6BAAjD;AAEA,OAAO,eAAP,MAA4B,yCAA5B;AAEA,OAAM,SAAU,YAAV,CACJ,QADI,EACqF;AAEzF,MAAM,cAAc,GAAyC;AAC3D,IAAA,gBAAgB,EAAE,IADyC;AAE3D,IAAA,aAAa,EAAE,MAAO,CAAC,MAAR,CAAgB,QAAhB,CAAyB,OAAzB,CAAiC,OAAjC,EAA0C,EAA1C,CAF4C;AAG3D,IAAA,UAAU,EAAE,eAH+C;AAI3D,IAAA,eAAe,EAAE;AAJ0C,GAA7D;AAOA,EAAA,gBAAgB,CAAC,cAAD,EAAiB,QAAjB,CAAhB;AACD","sourcesContent":["import { isConformant as baseIsConformant } from '@fluentui/react-conformance';\nimport type { IsConformantOptions, TestObject } from '@fluentui/react-conformance';\nimport makeStylesTests from '@fluentui/react-conformance-make-styles';\n\nexport function isConformant<TProps = {}>(\n testInfo: Omit<IsConformantOptions<TProps>, 'componentPath'> & { componentPath?: string },\n) {\n const defaultOptions: Partial<IsConformantOptions<TProps>> = {\n asPropHandlesRef: true,\n componentPath: module!.parent!.filename.replace('.test', ''),\n extraTests: makeStylesTests as TestObject<TProps>,\n skipAsPropTests: true,\n };\n\n baseIsConformant(defaultOptions, testInfo);\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["../../src/common/isConformant.ts"],"names":[],"mappings":"AAAA,SAAS,YAAY,IAAI,gBAAzB,QAAiD,6BAAjD;AAEA,OAAO,eAAP,MAA4B,yCAA5B;AAEA,OAAM,SAAU,YAAV,CACJ,QADI,EACqF;AAEzF,MAAM,cAAc,GAAyC;AAC3D,IAAA,gBAAgB,EAAE,IADyC;AAE3D,IAAA,aAAa,EAAE,MAAO,CAAC,MAAR,CAAgB,QAAhB,CAAyB,OAAzB,CAAiC,OAAjC,EAA0C,EAA1C,CAF4C;AAG3D,IAAA,UAAU,EAAE,eAH+C;AAI3D,IAAA,eAAe,EAAE;AAJ0C,GAA7D;AAOA,EAAA,gBAAgB,CAAC,cAAD,EAAiB,QAAjB,CAAhB;AACD","sourceRoot":""}
@@ -1 +1 @@
1
- {"version":3,"sources":["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;AAGA;;AAEG;;AACH,OAAO,IAAM,MAAM,gBAAG,KAAK,CAAC,UAAN,CAA8C,UAAC,KAAD,EAAQ,GAAR,EAAW;AAC7E,MAAM,KAAK,GAAG,SAAS,CAAC,KAAD,EAAQ,GAAR,CAAvB;AAEA,EAAA,eAAe,CAAC,KAAD,CAAf;AAEA,SAAO,YAAY,CAAC,KAAD,CAAnB;AACD,CANqB,CAAf;AAQP,MAAM,CAAC,WAAP,GAAqB,QAArB","sourcesContent":["import * as React from 'react';\nimport { useSwitch } from './useSwitch';\nimport { renderSwitch } from './renderSwitch';\nimport { useSwitchStyles } from './useSwitchStyles';\nimport type { SwitchProps } from './Switch.types';\n\n/**\n * The Switch control enables users to trigger an option on or off through pressing on the component.\n */\nexport const Switch = React.forwardRef<HTMLDivElement, SwitchProps>((props, ref) => {\n const state = useSwitch(props, ref);\n\n useSwitchStyles(state);\n\n return renderSwitch(state);\n});\n\nSwitch.displayName = 'Switch';\n"],"sourceRoot":"../src/"}
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;AAGA;;AAEG;;AACH,OAAO,IAAM,MAAM,gBAAG,KAAK,CAAC,UAAN,CAA8C,UAAC,KAAD,EAAQ,GAAR,EAAW;AAC7E,MAAM,KAAK,GAAG,SAAS,CAAC,KAAD,EAAQ,GAAR,CAAvB;AAEA,EAAA,eAAe,CAAC,KAAD,CAAf;AAEA,SAAO,YAAY,CAAC,KAAD,CAAnB;AACD,CANqB,CAAf;AAQP,MAAM,CAAC,WAAP,GAAqB,QAArB","sourceRoot":""}
@@ -21,6 +21,10 @@ export declare type SwitchSlots = {
21
21
  * The hidden input that handles the Switch's internal functionality.
22
22
  */
23
23
  input: IntrinsicShorthandProps<'input'>;
24
+ /**
25
+ * The area in which the Switch's rail allows for the thumb to be dragged.
26
+ */
27
+ activeRail: IntrinsicShorthandProps<'div'>;
24
28
  };
25
29
  export interface SwitchCommons {
26
30
  /**
@@ -44,7 +48,7 @@ export interface SwitchCommons {
44
48
  /**
45
49
  * Callback to be called when the `checked` value changes.
46
50
  */
47
- onChange?: (ev: React.ChangeEvent<HTMLInputElement>, data: {
51
+ onChange?: (ev: React.PointerEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>, data: {
48
52
  checked: boolean;
49
53
  }) => void;
50
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.types.js","sourceRoot":"../src/","sources":["components/Switch/Switch.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, IntrinsicShorthandProps } from '@fluentui/react-utilities';\n\nexport type SwitchSlots = {\n /**\n * The root of the Switch.\n */\n root: IntrinsicShorthandProps<'div'>;\n\n /**\n * The bar indicating the status of the Switch.\n */\n track: IntrinsicShorthandProps<'div'>;\n\n /**\n * The wrapper around the thumb. It is used as the active area for the thumb to position itself.\n */\n thumbWrapper: IntrinsicShorthandProps<'div'>;\n\n /**\n * The circular icon indicating the status of the Switch.\n */\n thumb: IntrinsicShorthandProps<'div'>;\n\n /**\n * The hidden input that handles the Switch's internal functionality.\n */\n input: IntrinsicShorthandProps<'input'>;\n};\n\nexport interface SwitchCommons {\n /**\n * The starting value for a uncontrolled Switch. If `true` then the Switch will be enabled.\n * Mutually exclusive with `checked` prop.\n *\n * @default false\n */\n defaultChecked?: boolean;\n\n /**\n * The current value for a controlled Switch. If `true` then the Switch will be enabled.\n * Mutually exclusive with `defaultChecked` prop.\n */\n checked?: boolean;\n\n /**\n * Whether the Switch should be disabled.\n *\n * @default false\n */\n disabled?: boolean;\n\n /**\n * Callback to be called when the `checked` value changes.\n */\n onChange?: (\n ev: React.ChangeEvent<HTMLInputElement>,\n data: {\n checked: boolean;\n },\n ) => void;\n}\n\nexport interface SwitchProps extends Omit<ComponentProps<SwitchSlots>, 'onChange'>, SwitchCommons {}\n\nexport interface SwitchState extends ComponentState<SwitchSlots>, SwitchCommons {}\n"]}
1
+ {"version":3,"file":"Switch.types.js","sourceRoot":"","sources":["../../../src/components/Switch/Switch.types.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
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
+ {"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"}
@@ -11,6 +11,6 @@ export var renderSwitch = function (state) {
11
11
  slots = _a.slots,
12
12
  slotProps = _a.slotProps;
13
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)));
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)));
15
15
  };
16
16
  //# sourceMappingURL=renderSwitch.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["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,EAAY,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,KAAf,CAAZ,CADF,eAEE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,YAAP,EAAmB,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,YAAf,CAAnB,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,KAAf,CAAZ,CADF,CAFF,eAKE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,KAAf,CAAZ,CALF,CADF;AASD,CAZM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport { switchShorthandProps } from './useSwitch';\nimport type { SwitchState, SwitchSlots } from './Switch.types';\n\n/**\n * Render the final JSX of Switch\n */\nexport const renderSwitch = (state: SwitchState) => {\n const { slots, slotProps } = getSlots<SwitchSlots>(state, switchShorthandProps);\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.root>\n );\n};\n"],"sourceRoot":"../src/"}
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,EAAY,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,KAAf,CAAZ,CADF,eAEE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,YAAP,EAAmB,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,YAAf,CAAnB,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,KAAf,CAAZ,CADF,CAFF,eAKE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,KAAf,CAAZ,CALF,eAME,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,UAAP,EAAiB,QAAA,CAAA,EAAA,EAAK,SAAS,CAAC,UAAf,CAAjB,CANF,CADF;AAUD,CAbM","sourceRoot":""}
@@ -5,7 +5,7 @@ import { useSwitchState } from './useSwitchState';
5
5
  * Array of all shorthand properties listed in SwitchSlots
6
6
  */
7
7
 
8
- export var switchShorthandProps = ['root', 'track', 'thumbWrapper', 'thumb', 'input'];
8
+ export var switchShorthandProps = ['root', 'track', 'thumbWrapper', 'thumb', 'activeRail', 'input'];
9
9
  /**
10
10
  * Given user props, returns state and render function for a Switch.
11
11
  */
@@ -14,6 +14,7 @@ export var useSwitch = function (props, ref) {
14
14
  var track = props.track,
15
15
  thumbWrapper = props.thumbWrapper,
16
16
  thumb = props.thumb,
17
+ activeRail = props.activeRail,
17
18
  input = props.input,
18
19
  defaultChecked = props.defaultChecked,
19
20
  checked = props.checked,
@@ -34,6 +35,7 @@ export var useSwitch = function (props, ref) {
34
35
  track: 'div',
35
36
  thumbWrapper: 'div',
36
37
  thumb: 'div',
38
+ activeRail: 'div',
37
39
  input: 'input'
38
40
  },
39
41
  track: resolveShorthand(track, {
@@ -45,6 +47,9 @@ export var useSwitch = function (props, ref) {
45
47
  thumb: resolveShorthand(thumb, {
46
48
  required: true
47
49
  }),
50
+ activeRail: resolveShorthand(activeRail, {
51
+ required: true
52
+ }),
48
53
  input: resolveShorthand(input, {
49
54
  required: true,
50
55
  defaultProps: {
@@ -1 +1 @@
1
- {"version":3,"sources":["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,CAAC,MAAD,EAAS,OAAT,EAAkB,cAAlB,EAAkC,OAAlC,EAA2C,OAA3C,CAApD;AAEP;;AAEG;;AACH,OAAO,IAAM,SAAS,GAAG,UAAC,KAAD,EAAqB,GAArB,EAAgD;AAC/D,MAAA,KAAK,GAA8E,KAAK,CAAnF,KAAL;AAAA,MAAO,YAAY,GAAgE,KAAK,CAArE,YAAnB;AAAA,MAAqB,KAAK,GAAyD,KAAK,CAA9D,KAA1B;AAAA,MAA4B,KAAK,GAAkD,KAAK,CAAvD,KAAjC;AAAA,MAAmC,cAAc,GAAkC,KAAK,CAAvC,cAAjD;AAAA,MAAmD,OAAO,GAAyB,KAAK,CAA9B,OAA1D;AAAA,MAA4D,QAAQ,GAAe,KAAK,CAApB,QAApE;AAAA,MAAsE,QAAQ,GAAK,KAAK,CAAV,QAA9E;AACR,MAAM,KAAK,GAAgB;AACzB,IAAA,cAAc,EAAA,cADW;AAEzB,IAAA,OAAO,EAAA,OAFkB;AAGzB,IAAA,QAAQ,EAAA,QAHiB;AAIzB,IAAA,QAAQ,EAAA,QAJiB;AAKzB,IAAA,IAAI,EAAE,qBAAqB,CAAC,MAAD,EAAO,QAAA,CAAA,QAAA,CAAA;AAChC,MAAA,GAAG,EAAA;AAD6B,KAAA,EAE7B,KAF6B,CAAA,EAExB;AACR,MAAA,EAAE,EAAE,KAAK,CAAC,SAAD,EAAY,KAAK,CAAC,EAAlB;AADD,KAFwB,CAAP,CALF;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,KAAK,EAAE;AALG,KAVa;AAiBzB,IAAA,KAAK,EAAE,gBAAgB,CAAC,KAAD,EAAQ;AAAE,MAAA,QAAQ,EAAE;AAAZ,KAAR,CAjBE;AAkBzB,IAAA,YAAY,EAAE,gBAAgB,CAAC,YAAD,EAAe;AAAE,MAAA,QAAQ,EAAE;AAAZ,KAAf,CAlBL;AAmBzB,IAAA,KAAK,EAAE,gBAAgB,CAAC,KAAD,EAAQ;AAAE,MAAA,QAAQ,EAAE;AAAZ,KAAR,CAnBE;AAoBzB,IAAA,KAAK,EAAE,gBAAgB,CAAC,KAAD,EAAQ;AAC7B,MAAA,QAAQ,EAAE,IADmB;AAE7B,MAAA,YAAY,EAAE;AACZ,QAAA,IAAI,EAAE;AADM;AAFe,KAAR;AApBE,GAA3B;AA4BA,EAAA,cAAc,CAAC,KAAD,CAAd;AAEA,SAAO,KAAP;AACD,CAjCM","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useId } from '@fluentui/react-utilities';\nimport { useSwitchState } from './useSwitchState';\nimport type { SwitchProps, SwitchSlots, SwitchState } from './Switch.types';\n\n/**\n * Array of all shorthand properties listed in SwitchSlots\n */\nexport const switchShorthandProps: (keyof SwitchSlots)[] = ['root', 'track', 'thumbWrapper', 'thumb', 'input'];\n\n/**\n * Given user props, returns state and render function for a Switch.\n */\nexport const useSwitch = (props: SwitchProps, ref: React.Ref<HTMLElement>): SwitchState => {\n const { track, thumbWrapper, thumb, 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 input: 'input',\n },\n track: resolveShorthand(track, { required: true }),\n thumbWrapper: resolveShorthand(thumbWrapper, { required: true }),\n thumb: resolveShorthand(thumb, { 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":["../../../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;;AAEG;;AACH,OAAO,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,QAAQ,GAAK,KAAK,CAAV,QAA1F;AACR,MAAM,KAAK,GAAgB;AACzB,IAAA,cAAc,EAAA,cADW;AAEzB,IAAA,OAAO,EAAA,OAFkB;AAGzB,IAAA,QAAQ,EAAA,QAHiB;AAIzB,IAAA,QAAQ,EAAA,QAJiB;AAKzB,IAAA,IAAI,EAAE,qBAAqB,CAAC,MAAD,EAAO,QAAA,CAAA,QAAA,CAAA;AAChC,MAAA,GAAG,EAAA;AAD6B,KAAA,EAE7B,KAF6B,CAAA,EAExB;AACR,MAAA,EAAE,EAAE,KAAK,CAAC,SAAD,EAAY,KAAK,CAAC,EAAlB;AADD,KAFwB,CAAP,CALF;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,gBAAgB,CAAC,KAAD,EAAQ;AAAE,MAAA,QAAQ,EAAE;AAAZ,KAAR,CAlBE;AAmBzB,IAAA,YAAY,EAAE,gBAAgB,CAAC,YAAD,EAAe;AAAE,MAAA,QAAQ,EAAE;AAAZ,KAAf,CAnBL;AAoBzB,IAAA,KAAK,EAAE,gBAAgB,CAAC,KAAD,EAAQ;AAAE,MAAA,QAAQ,EAAE;AAAZ,KAAR,CApBE;AAqBzB,IAAA,UAAU,EAAE,gBAAgB,CAAC,UAAD,EAAa;AAAE,MAAA,QAAQ,EAAE;AAAZ,KAAb,CArBH;AAsBzB,IAAA,KAAK,EAAE,gBAAgB,CAAC,KAAD,EAAQ;AAC7B,MAAA,QAAQ,EAAE,IADmB;AAE7B,MAAA,YAAY,EAAE;AACZ,QAAA,IAAI,EAAE;AADM;AAFe,KAAR;AAtBE,GAA3B;AA8BA,EAAA,cAAc,CAAC,KAAD,CAAd;AAEA,SAAO,KAAP;AACD,CAnCM","sourceRoot":""}
@@ -1,6 +1,15 @@
1
1
  import * as React from 'react';
2
- import { useControllableState, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
3
- import { useFluent } from '@fluentui/react-shared-contexts';
2
+ import { clamp, useBoolean, useControllableState, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
3
+ import { useFluent } from '@fluentui/react-shared-contexts'; // TODO: This should be replaced with a useEvent hook
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+
6
+ var on = function (element, eventName, callback) {
7
+ element.addEventListener(eventName, callback);
8
+ return function () {
9
+ return element.removeEventListener(eventName, callback);
10
+ };
11
+ };
12
+
4
13
  export var useSwitchState = function (state) {
5
14
  var _a = state.defaultChecked,
6
15
  defaultChecked = _a === void 0 ? false : _a,
@@ -8,39 +17,136 @@ export var useSwitchState = function (state) {
8
17
  _b = state.disabled,
9
18
  disabled = _b === void 0 ? false : _b,
10
19
  onChange = state.onChange;
20
+ var _c = state.root,
21
+ onPointerDownCallback = _c.onPointerDown,
22
+ onKeyDownCallback = _c.onKeyDown;
11
23
  var dir = useFluent().dir;
12
24
  var inputRef = useMergedRefs(state.input.ref);
25
+ var railRef = React.useRef(null);
26
+ var internalState = React.useRef({
27
+ internalValue: checked ? checked : defaultChecked,
28
+ thumbIsDragging: false,
29
+ disposables: []
30
+ });
13
31
 
14
- var _c = useControllableState({
32
+ var _d = useControllableState({
15
33
  defaultState: defaultChecked,
16
34
  state: checked,
17
35
  initialState: false
18
36
  }),
19
- internalValue = _c[0],
20
- setInternalValue = _c[1];
37
+ currentValue = _d[0],
38
+ setCurrentValue = _d[1];
39
+
40
+ var _e = useBoolean(true),
41
+ thumbAnimation = _e[0],
42
+ _f = _e[1],
43
+ showThumbAnimation = _f.setTrue,
44
+ hideThumbAnimation = _f.setFalse;
45
+
46
+ var _g = React.useState(currentValue === true ? 100 : 0),
47
+ renderedPosition = _g[0],
48
+ setRenderedPosition = _g[1];
21
49
 
22
- var setChecked = React.useCallback(function (ev, incomingValue) {
50
+ var setChecked = useEventCallback(function (ev, incomingValue) {
51
+ ev.stopPropagation();
52
+ ev.preventDefault();
53
+ internalState.current.internalValue = incomingValue;
23
54
  onChange === null || onChange === void 0 ? void 0 : onChange(ev, {
24
55
  checked: incomingValue
25
56
  });
26
- setInternalValue(incomingValue);
27
- }, [onChange, setInternalValue]);
28
- var userOnChange = state.input.onChange;
29
- var onInputChange = useEventCallback(function (ev) {
30
- ev.stopPropagation();
31
- userOnChange === null || userOnChange === void 0 ? void 0 : userOnChange(ev);
32
- setChecked(ev, ev.currentTarget.checked);
57
+ setCurrentValue(incomingValue);
58
+ setRenderedPosition(undefined);
33
59
  });
60
+ var calculatePosition = React.useCallback(function (ev) {
61
+ var _a;
62
+
63
+ var currentBounds = (_a = railRef === null || railRef === void 0 ? void 0 : railRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
64
+ var railWidth = currentBounds.width;
65
+ var railPosition = dir === 'rtl' ? currentBounds.right : currentBounds.left;
66
+ var distance = dir === 'rtl' ? railPosition - ev.clientX : ev.clientX - railPosition;
67
+ return clamp(distance / railWidth * 100, 0, 100);
68
+ }, [dir]);
69
+ var onPointerMove = React.useCallback(function (ev) {
70
+ var incomingPosition = calculatePosition(ev);
71
+ internalState.current.thumbIsDragging = true;
72
+ hideThumbAnimation();
73
+ setRenderedPosition(incomingPosition); // If the Switch reaches a new position of 0% or 100%, update the state and fire change.
74
+
75
+ if (incomingPosition === 100 && internalState.current.internalValue !== true) {
76
+ setChecked(ev, true);
77
+ } else if (incomingPosition === 0 && internalState.current.internalValue !== false) {
78
+ setChecked(ev, false);
79
+ }
80
+ }, [calculatePosition, hideThumbAnimation, setChecked]);
81
+ var onPointerUp = React.useCallback(function (ev) {
82
+ internalState.current.disposables.forEach(function (dispose) {
83
+ return dispose();
84
+ });
85
+ internalState.current.disposables = [];
86
+ inputRef.current.focus();
87
+
88
+ if (internalState.current.thumbIsDragging) {
89
+ var roundedPosition = Math.round(calculatePosition(ev) / 100) * 100;
90
+ showThumbAnimation();
91
+
92
+ if (roundedPosition === 100) {
93
+ setChecked(ev, true);
94
+ } else if (roundedPosition === 0) {
95
+ setChecked(ev, false);
96
+ }
97
+ } else {
98
+ setChecked(ev, !internalState.current.internalValue);
99
+ }
100
+ }, [calculatePosition, inputRef, setChecked, showThumbAnimation]);
101
+ var onPointerDown = React.useCallback(function (ev) {
102
+ var _a;
103
+
104
+ var pointerId = ev.pointerId;
105
+ var target = ev.target;
106
+ onPointerDownCallback === null || onPointerDownCallback === void 0 ? void 0 : onPointerDownCallback(ev);
107
+ showThumbAnimation();
108
+ (_a = target.setPointerCapture) === null || _a === void 0 ? void 0 : _a.call(target, pointerId);
109
+ internalState.current.thumbIsDragging = false;
110
+ internalState.current.disposables.push(on(target, 'pointermove', onPointerMove), on(target, 'pointerup', onPointerUp), function () {
111
+ var _a;
112
+
113
+ (_a = target.releasePointerCapture) === null || _a === void 0 ? void 0 : _a.call(target, pointerId);
114
+ });
115
+ }, [onPointerDownCallback, onPointerMove, onPointerUp, showThumbAnimation]);
116
+ var onKeyDown = React.useCallback(function (ev) {
117
+ onKeyDownCallback === null || onKeyDownCallback === void 0 ? void 0 : onKeyDownCallback(ev);
118
+
119
+ if (ev.key === ' ') {
120
+ setChecked(ev, !internalState.current.internalValue);
121
+ }
122
+ }, [onKeyDownCallback, setChecked]);
123
+ var currentPosition = renderedPosition !== undefined ? renderedPosition : currentValue ? 100 : 0;
124
+ var rootStyles = {
125
+ '--switch-checked-opacity': currentPosition / 100,
126
+ '--switch-unchecked-opacity': (100 - currentPosition) / 100
127
+ };
34
128
  var thumbWrapperStyles = {
35
- transform: dir === 'rtl' ? internalValue ? 'translate(-100%)' : 'translate(0%)' : internalValue ? 'translate(100%)' : 'translate(0%)'
36
- }; // Input Props
129
+ transform: "translate(" + (dir === 'rtl' ? -currentPosition : currentPosition) + "%)",
130
+ transition: thumbAnimation ? 'transform .1s cubic-bezier(0.33, 0.0, 0.67, 1), opacity .1s cubic-bezier(0.33, 0.0, 0.67, 1)' : 'none'
131
+ }; // Root Props
132
+
133
+ state.root.style = rootStyles;
134
+
135
+ if (!disabled) {
136
+ state.root.onPointerDown = onPointerDown;
137
+ state.root.onKeyDown = onKeyDown;
138
+ } // Input Props
37
139
 
38
- state.input.onChange = onInputChange;
39
- state.input.checked = internalValue;
140
+
141
+ state.input.checked = currentValue;
40
142
  state.input.disabled = disabled;
41
- state.input.ref = inputRef; // thumbContainer Props
143
+ state.input.ref = inputRef;
144
+ state.input.readOnly = true;
145
+ state.input.role = 'switch'; // Thumb Container Props
146
+
147
+ state.thumbWrapper.style = thumbWrapperStyles; // Active Rail Props
42
148
 
43
- state.thumbWrapper.style = thumbWrapperStyles;
149
+ state.activeRail.ref = railRef;
44
150
  return state;
45
151
  };
46
152
  //# sourceMappingURL=useSwitchState.js.map