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

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 (56) hide show
  1. package/CHANGELOG.json +457 -1
  2. package/CHANGELOG.md +167 -31
  3. package/MIGRATION.md +89 -22
  4. package/Spec.md +179 -84
  5. package/dist/index.d.ts +107 -0
  6. package/{lib → dist}/tsdoc-metadata.json +0 -0
  7. package/lib/Switch.js.map +1 -1
  8. package/lib/components/Switch/Switch.js +1 -1
  9. package/lib/components/Switch/Switch.js.map +1 -1
  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.js +8 -6
  13. package/lib/components/Switch/renderSwitch.js.map +1 -1
  14. package/lib/components/Switch/useSwitch.js +63 -43
  15. package/lib/components/Switch/useSwitch.js.map +1 -1
  16. package/lib/components/Switch/useSwitchStyles.js +171 -269
  17. package/lib/components/Switch/useSwitchStyles.js.map +1 -1
  18. package/lib/index.js +2 -1
  19. package/lib/index.js.map +1 -1
  20. package/lib-commonjs/Switch.js.map +1 -1
  21. package/lib-commonjs/components/Switch/Switch.js +1 -1
  22. package/lib-commonjs/components/Switch/Switch.js.map +1 -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 +8 -6
  26. package/lib-commonjs/components/Switch/renderSwitch.js.map +1 -1
  27. package/lib-commonjs/components/Switch/useSwitch.js +65 -43
  28. package/lib-commonjs/components/Switch/useSwitch.js.map +1 -1
  29. package/lib-commonjs/components/Switch/useSwitchStyles.js +173 -271
  30. package/lib-commonjs/components/Switch/useSwitchStyles.js.map +1 -1
  31. package/lib-commonjs/index.js +39 -2
  32. package/lib-commonjs/index.js.map +1 -1
  33. package/package.json +19 -20
  34. package/dist/react-switch.d.ts +0 -89
  35. package/lib/Switch.d.ts +0 -1
  36. package/lib/components/Switch/Switch.d.ts +0 -6
  37. package/lib/components/Switch/Switch.types.d.ts +0 -59
  38. package/lib/components/Switch/index.d.ts +0 -5
  39. package/lib/components/Switch/renderSwitch.d.ts +0 -5
  40. package/lib/components/Switch/useSwitch.d.ts +0 -6
  41. package/lib/components/Switch/useSwitchState.d.ts +0 -2
  42. package/lib/components/Switch/useSwitchState.js +0 -144
  43. package/lib/components/Switch/useSwitchState.js.map +0 -1
  44. package/lib/components/Switch/useSwitchStyles.d.ts +0 -6
  45. package/lib/index.d.ts +0 -2
  46. package/lib-commonjs/Switch.d.ts +0 -1
  47. package/lib-commonjs/components/Switch/Switch.d.ts +0 -6
  48. package/lib-commonjs/components/Switch/Switch.types.d.ts +0 -59
  49. package/lib-commonjs/components/Switch/index.d.ts +0 -5
  50. package/lib-commonjs/components/Switch/renderSwitch.d.ts +0 -5
  51. package/lib-commonjs/components/Switch/useSwitch.d.ts +0 -6
  52. package/lib-commonjs/components/Switch/useSwitchState.d.ts +0 -2
  53. package/lib-commonjs/components/Switch/useSwitchState.js +0 -156
  54. package/lib-commonjs/components/Switch/useSwitchState.js.map +0 -1
  55. package/lib-commonjs/components/Switch/useSwitchStyles.d.ts +0 -6
  56. package/lib-commonjs/index.d.ts +0 -2
package/Spec.md CHANGED
@@ -1,134 +1,229 @@
1
1
  # @fluentui/react-switch Spec
2
2
 
3
+ **GitHub Epic issue** - [Switch Convergence #19409](https://github.com/microsoft/fluentui/issues/19409)
4
+
3
5
  ## Background
4
6
 
5
- Previously called Toggle in OUFR and Checkbox in Stardust, the Switch component
6
- introduces a quick way of switching between Boolean values by pressing the thumb.
7
+ Previously called `Toggle` in v8 and `Checkbox` in v0, the `Switch` component introduces a quick way of switching between on/off states by clicking/tapping the thumb.
7
8
 
8
9
  ## Prior Art
9
10
 
10
- Upon investigating other component libraries, it was decided to:
11
+ ### Open UI
12
+
13
+ The Open UI [Switch Research](https://open-ui.org/components/switch) page shows that the component is used in UI platforms across the web, with the `Switch` moniker being the most prominently used across major component libraries.
14
+
15
+ ### Comparison of v8 and v0
16
+
17
+ The existing components are:
18
+
19
+ - v8 - [Toggle](https://developer.microsoft.com/en-us/fluentui#/controls/web/toggle)
20
+ - v0 - [Checkbox](https://fluentsite.z22.web.core.windows.net/0.52.2/components/checkbox/definition)
11
21
 
12
- 1. Change the name to Switch
22
+ ### [Toggle in v8/Fabric](https://developer.microsoft.com/en-us/fluentui#/controls/web/toggle)
13
23
 
14
- Amongst other major component libraries (`Material UI`, `Ant Design`, `Evergreen`, and `Fast`) Switch appears to be a more prominently used name.
24
+ The v8 `Toggle` component
15
25
 
16
- [Open UI](https://open-ui.org/components/switch)
17
- [Epic Issue](https://github.com/microsoft/fluentui/issues/19409)
26
+ supports both `indeterminate` and `checked` states. In this case, an input tag is used and its opacity is set to 0. This allows for the logic to be performed by the native element while a div is rendered to show the styled checkbox.
27
+
28
+ Example
29
+
30
+ ```tsx
31
+ <Checkbox
32
+ label="Indeterminate checkbox (controlled)"
33
+ indeterminate={isIndeterminate}
34
+ checked={isChecked}
35
+ onChange={onChange}
36
+ />
37
+ ```
38
+
39
+ Component props:
40
+
41
+ | Prop | Description |
42
+ | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
43
+ | `ariaLabel` | Text for screen-reader to announce as the name of the toggle. |
44
+ | `as` | Render the root element as another type. |
45
+ | `checked` | Checked state of the toggle. If you are maintaining state yourself, use this property. Otherwise use `defaultChecked`. |
46
+ | `componentRef` | Optional callback to access the IToggle interface. Use this instead of ref for accessing the public methods and properties of the component. |
47
+ | `defaultChecked` | Initial state of the toggle. If you want the toggle to maintain its own state, use this. Otherwise use `checked`. |
48
+ | `disabled` | Optional disabled flag. |
49
+ | `inlineLabel` | Whether the label (not the onText/offText) should bbe positioned inline with the toggle control. |
50
+ | `label` | A label for the toggle. |
51
+ | `offText` | Text to display when toggle is OFF. |
52
+ | `onChange` | Callback issued when the value changes. |
53
+ | `onText` | Text to display when toggle is ON. |
54
+ | `role` | Whether to use the 'switch' role (ARIA 1.1) or the 'checkbox' role (ARIA 1.0). |
55
+ | `styles` | Optional styles for the component. |
56
+ | `theme` | Theme provided by HOC. |
57
+
58
+ ### [Checkbox in v0/Northstar](https://fluentsite.z22.web.core.windows.net/0.56.0/components/checkbox/definition)
59
+
60
+ The v0 `Checkbox` component
61
+
62
+ supports a mixed state, which is the same as indeterminate in v8. It is rendered as a `div` with `role="checkbox"` and does not use the native input element.
63
+
64
+ ```tsx
65
+ // string
66
+ <Checkbox label="Make my profile visible" />
67
+
68
+ // jsx
69
+ <Checkbox
70
+ label={
71
+ <span>
72
+ Long labels will wrap and the indicator <br /> should remain top-aligned.
73
+ </span>
74
+ }
75
+ />
76
+ ```
77
+
78
+ Component props:
79
+
80
+ | Prop | Description |
81
+ | ---------------- | ------------------------------------------------------------------ |
82
+ | `accessibility` | Accessibility behavior if overridden by the user. |
83
+ | `as` | Render as given string or component. |
84
+ | `checked` | Checkbox's checked state. |
85
+ | `className` | Additional styles. |
86
+ | `defaultChecked` | Whether the checkbox should be set to checked by default. |
87
+ | `design` | ... |
88
+ | `disabled` | Whether the checkbox is disabled or not. |
89
+ | `indicator` | Checkbox's icon indicator. |
90
+ | `label` | Label text or jsx to be rendered in the label. |
91
+ | `labelPosition` | Whether the label is rendered on left or right (`start` or `end`). |
92
+ | `onChange` | Event handler to be called after checked state has changed. |
93
+ | `onClick` | Event handler to be called after the checkbox is clicked. |
94
+ | `styles` | Additional styles. |
95
+ | `toggle` | Render a toggle style checkbox with on and off choices. |
96
+ | `variables` | Additional styles. |
18
97
 
19
98
  ## Sample Code
20
99
 
21
- ```jsx=
100
+ ```tsx
22
101
  <Switch checked />
23
102
  <Switch checked disabled/>
24
103
  <Switch checked onChange={onChange}/>
25
104
  ```
26
105
 
106
+ https://github.com/microsoft/fluentui/blob/master/packages/react-checkbox/src/components/Checkbox/Checkbox.types.ts
107
+
27
108
  ## API
28
109
 
29
- | Name | V0 | V8 | Description |
30
- | -------------- | ------- | ------- | --------------------------------------------------------------------------- |
31
- | checked | &check; | &check; | The value of the Switch. If `true` then the Switch will be enabled. |
32
- | defaultChecked | &check; | &check; | The default value of the Switch. If `true` then the Switch will be enabled. |
33
- | disabled | &check; | &check; | Whether the Switch should be disabled. |
34
- | onChange | &check; | &check; | Callback to be called when the checked state value changes. |
110
+ ### Switch Props
35
111
 
36
- ## Migration
37
-
38
- <img src="https://img.shields.io/badge/Used%20in-v0-orange" alt="drawing" width="100"/>
39
-
40
- | Name | Description | Reason |
41
- | ------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------ |
42
- | indicator | A checkbox's indicator icon can be customized. | Toggle will have a slot for the thumb. |
43
- | label | A checkbox can render a label next to its indicator. | To be decided on how it is handled |
44
- | labelPosition | Determines whether the label should be positioned before or after the Switch. | To be decided on how it is handled |
45
- | onClick | Called after a checkbox is clicked. | The native input element handles onClick. |
46
- | toggle | A checkbox can be formatted to show an "on or off" choice. | Toggle is separated from checkbox due to vast styling differences. |
47
-
48
- <img src="https://img.shields.io/badge/Used%20in-v8-blue" alt="drawing" width="120"/>
49
-
50
- | Name | Description | Reason |
51
- | ------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------- |
52
- | componentRef | Optional callback to access the IToggle interface. | Not used in converged components |
53
- | label | A label for the toggle. | To be decided on how it is handled. |
54
- | labelPosition | Determines whether the label should be positioned before or after the Switch. | To be decided on how it is handled |
55
- | onText | Text to display when toggle is ON. | To be decided. |
56
- | offText | Text to display when toggle is OFF. | To be decided. |
57
- | ariaLabel | Text for screen-reader to announce as the name of the toggle. | Toggle has a hidden input element. |
58
- | onAriaLabel | @deprecated Use `ariaLabel` for name, and let the metadata convey state | deprecated |
59
- | offAriaLabel | @deprecated Use `ariaLabel` for name, and let the metadata convey state | deprecated |
60
- | inlineLabel | Whether the label (not the onText/offText) should be positioned inline with the toggle control. | It can be manually styled |
61
- | onChanged | @deprecated Use `onChange` instead. | deprecated |
62
- | theme | Theme provided by HOC. | Not used in converged components |
63
- | styles | Optional styles for the component. | Not used in converged components |
64
- | role | Whether to use the 'switch' role (ARIA 1.1) or the 'checkbox' role (ARIA 1.0). | Toggle has a hidden input element. |
112
+ See [Switch.types.ts](https://github.com/microsoft/fluentui/blob/master/packages/react-switch/src/components/Switch/Switch.types.ts).
65
113
 
66
114
  ## Structure
67
115
 
68
- - _**Public**_
116
+ ### Slots
117
+
118
+ - `root` - The outer `<div>` wrapping the `indicator`, `input` and `label` to provide the correct layout styling.
119
+ - `indicator` - The track and the thumb sliding over it indicating the on and off status of the Switch.
120
+ - `input` - The visually hidden `<input type="checkbox">` that handles the `Switch`'s functionality. This is the **primary** slot: it receives all of the native props passed to the `Switch` component. It has opacity 0 and overlaps the entire `root` slot, for hit testing.
121
+ - `label` - (optional) The `<label>` describing this `Switch`.
69
122
 
70
- ```jsx=
71
- <Switch checked={true}/>
123
+ ### Public
124
+
125
+ ```tsx
126
+ <Switch checked={true} />
72
127
  ```
73
128
 
74
- - _**Internal**_
129
+ ### Internal
75
130
 
76
- ```jsx=
131
+ ```tsx
77
132
  <slots.root {...slotProps.root}>
78
- <slots.track {...slotProps.track} />
79
- <slots.thumbWrapper {...slotProps.thumbWrapper}>
80
- <slots.thumb {...slotProps.thumb} />
81
- </slots.thumbWrapper>
82
- <input type="checkbox" />
83
- </slots.root>;
133
+ <slots.input {...slotProps.input} />
134
+ {labelPosition !== 'after' && slots.label && <slots.label {...slotProps.label} />}
135
+ <slots.indicator {...slotProps.indicator} />
136
+ {labelPosition === 'after' && slots.label && <slots.label {...slotProps.label} />}
137
+ </slots.root>
138
+ ```
139
+
140
+ ### DOM
141
+
142
+ _With label before the track thumb indicator:_
143
+
144
+ ```tsx
145
+ <div class="fui-Switch">
146
+ <input class="fui-Switch__input" id="switch-1" role="switch" type="checkbox" />
147
+ <label class="fui-Switch__label" for="switch-1" />
148
+ <div aria-hidden="true" class="fui-Switch__indicator">
149
+ <CircleFilled />
150
+ </div>
151
+ </div>
84
152
  ```
85
153
 
86
- - _**DOM**_
154
+ _With label after the track thumb indicator:_
87
155
 
88
- ```jsx=
89
- <div className="fui-Switch">
90
- <div className="fui-Switch-track" />
91
- <div className="fui-Switch-thumbWrapper">
92
- <div className="fui-Switch-thumb" />
156
+ ```tsx
157
+ <div class="fui-Switch">
158
+ <input class="fui-Switch__input" id="switch-1" role="switch" type="checkbox" />
159
+ <div aria-hidden="true" class="fui-Switch__indicator">
160
+ <CircleFilled />
93
161
  </div>
94
- <input type="checkbox" />
95
- </div>;
162
+ <label class="fui-Switch__label" for="switch-1" />
163
+ </div>
96
164
  ```
97
165
 
166
+ ## Migration
167
+
168
+ See [MIGRATION.md](MIGRATION.md).
169
+
98
170
  ## Behaviors
99
171
 
100
- ### Component States
172
+ ### States
173
+
174
+ The following section describes the different states in which a `Switch` can be throughout the course of interaction with it.
175
+
176
+ #### Enabled state
177
+
178
+ An enabled `Switch` communicates interaction by having styling that invites the user to click/tap on it to toggle between on/off states.
179
+
180
+ #### Disabled state
181
+
182
+ A disabled `Switch` is non-interactive, ignoring all events and never updating its value. It does not allow focus and changes its styling to indicates this lack of interaction.
101
183
 
102
- - **Disabled**
103
- - When disabled, all events are ignored, and the Switch's value never updates.
104
- - Does not allow focus.
105
- - The cursor changes to `not-allowed`.
106
- - **Checked**
107
- - Switch is off when the “thumb” is indicated on the left.
108
- - Switch is on when the thumb is indicated on the right.
109
- - This is switched in RTL.
110
- - When toggling switches on and off, the on state should change using the checked state appearance styles.
184
+ #### Hovered state
111
185
 
112
- ### Hover
186
+ A hovered `Switch` changes styling to communicate that the user has placed a cursor above it.
113
187
 
114
- The cursor changes to the hand icon. The outline of the Switch and thumb should also darken. This helps reinforce that the area is interactive.
188
+ #### Pressed state
115
189
 
116
- ### Keyboard
190
+ A pressed `Switch` changes styling to communicate that the user is currently pressing it.
117
191
 
118
- Since the Switch is an interactive component, it must be focusable and keyboard accessible.
119
- The expected keyboard shortcut for activating a Switch is the spacebar key.
192
+ #### Unchecked state
120
193
 
121
- 1. Use the spacebar to switch off
122
- 2. Use the spacebar to switch on
194
+ An unchecked `Switch` has the thumb on the left (right in RTL) and styling to indicate that it is off.
123
195
 
124
- ### Cursor
196
+ #### Checked state
125
197
 
126
- Clicking triggers toggling the state change. The thumb animates from right to left [on > off] and left to right [off > on]
198
+ A checked `Switch` has the thumb on the right (left in RTL) and styling to indicate that it is on.
127
199
 
128
- ### Touch
200
+ ### Interaction
129
201
 
130
- Touch follows the same behavior as the cursor.
202
+ ### Keyboard interaction
203
+
204
+ The following is a set of keys that interact with the `Switch` component:
205
+
206
+ | Key | Description |
207
+ | ------- | ------------------------------- |
208
+ | `Space` | Switches between on/off states. |
209
+
210
+ ### Cursor interaction
211
+
212
+ - `click`: Triggers a toggle between on and off values. The thumb animates from left to right [off > on] and right to left [on > off] to reflect this change (the directions are reversed in RTL).
213
+
214
+ ### Touch interaction
215
+
216
+ The same behavior as above is traslated for touch events.
131
217
 
132
218
  ## Accessibility
133
219
 
134
- Accessibility will be handled by the hidden `<input type="checkbox" />` element and follows the same pattern.
220
+ ### Relevant documents
221
+
222
+ - [WAI-ARIA 1.1 Spec](https://www.w3.org/TR/wai-aria-1.1/#switch)
223
+ - [WAI-ARIA 1.2 Spec](https://www.w3.org/TR/wai-aria-1.2/#switch)
224
+ - [WAI-ARIA 1.2 Authoring Practices](https://www.w3.org/TR/wai-aria-practices-1.2/#switch)
225
+
226
+ ### Expected behavior
227
+
228
+ - Switch uses a standard HTML `<input type="checkbox">` with `role="switch"` set and does not require any additional handling for aria on the input element.
229
+ - The track and thumb indicator has `aria-hidden="true"` as it is a purely visual representation of the state of the underlying input.
@@ -0,0 +1,107 @@
1
+ import type { ComponentProps } from '@fluentui/react-utilities';
2
+ import type { ComponentState } from '@fluentui/react-utilities';
3
+ import type { ForwardRefComponent } from '@fluentui/react-utilities';
4
+ import { Label } from '@fluentui/react-label';
5
+ import * as React_2 from 'react';
6
+ import type { Slot } from '@fluentui/react-utilities';
7
+ import type { SlotClassNames } from '@fluentui/react-utilities';
8
+
9
+ /**
10
+ * Render a Switch component by passing the state defined props to the appropriate slots.
11
+ */
12
+ export declare const renderSwitch_unstable: (state: SwitchState) => JSX.Element;
13
+
14
+ /**
15
+ * Switches enable users to trigger an option on or off through pressing the component.
16
+ */
17
+ export declare const Switch: ForwardRefComponent<SwitchProps>;
18
+
19
+ /**
20
+ * @deprecated Use `switchClassNames.root` instead.
21
+ */
22
+ export declare const switchClassName: string;
23
+
24
+ export declare const switchClassNames: SlotClassNames<SwitchSlots>;
25
+
26
+ export declare type SwitchOnChangeData = {
27
+ checked: boolean;
28
+ };
29
+
30
+ /**
31
+ * Switch Props
32
+ */
33
+ export declare type SwitchProps = Omit<ComponentProps<Partial<SwitchSlots>, 'input'>, 'checked' | 'defaultChecked' | 'onChange'> & {
34
+ /**
35
+ * Defines the controlled checked state of the Switch.
36
+ * If passed, Switch ignores the `defaultChecked` property.
37
+ * 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
38
+ * correct value based on handling `onChange` events and re-rendering.
39
+ *
40
+ * @default false
41
+ */
42
+ checked?: boolean;
43
+ /**
44
+ * Defines whether the Switch is initially in a checked state or not when rendered.
45
+ *
46
+ * @default false
47
+ */
48
+ defaultChecked?: boolean;
49
+ /**
50
+ * The position of the label relative to the Switch.
51
+ *
52
+ * @default after
53
+ */
54
+ labelPosition?: 'above' | 'after' | 'before';
55
+ /**
56
+ * Callback to be called when the checked state value changes.
57
+ */
58
+ onChange?: (ev: React_2.ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => void;
59
+ };
60
+
61
+ export declare type SwitchSlots = {
62
+ /**
63
+ * The root element of the Switch.
64
+ *
65
+ * The root slot receives the `className` and `style` specified directly on the `<Switch>` tag.
66
+ * All other native props will be applied to the primary slot: `input`.
67
+ */
68
+ root: NonNullable<Slot<'div'>>;
69
+ /**
70
+ * The track and the thumb sliding over it indicating the on and off status of the Switch.
71
+ */
72
+ indicator: NonNullable<Slot<'div'>>;
73
+ /**
74
+ * Hidden input that handles the Switch's functionality.
75
+ *
76
+ * This is the PRIMARY slot: all native properties specified directly on the `<Switch>` tag will be applied to this
77
+ * slot, except `className` and `style`, which remain on the root slot.
78
+ */
79
+ input: NonNullable<Slot<'input'>>;
80
+ /**
81
+ * The Switch's label.
82
+ */
83
+ label?: Slot<typeof Label>;
84
+ };
85
+
86
+ /**
87
+ * State used in rendering Switch
88
+ */
89
+ export declare type SwitchState = ComponentState<SwitchSlots> & Required<Pick<SwitchProps, 'labelPosition'>>;
90
+
91
+ /**
92
+ * Create the state required to render Switch.
93
+ *
94
+ * The returned state can be modified with hooks such as useSwitchStyles_unstable,
95
+ * before being passed to renderSwitch_unstable.
96
+ *
97
+ * @param props - props from this instance of Switch
98
+ * @param ref - reference to `<input>` element of Switch
99
+ */
100
+ export declare const useSwitch_unstable: (props: SwitchProps, ref: React_2.Ref<HTMLInputElement>) => SwitchState;
101
+
102
+ /**
103
+ * Apply styling to the Switch slots based on the state
104
+ */
105
+ export declare const useSwitchStyles_unstable: (state: SwitchState) => SwitchState;
106
+
107
+ export { }
File without changes
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"]}
@@ -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 +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\nexport type SwitchOnChangeData = {\n checked: boolean;\n};\n\n/**\n * Switch Props\n */\nexport type SwitchProps = Omit<\n ComponentProps<Partial<SwitchSlots>, 'input'>,\n 'checked' | 'defaultChecked' | 'onChange'\n> & {\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 *\n * @default false\n */\n checked?: boolean;\n\n /**\n * Defines whether the Switch is initially in a checked state or not when rendered.\n *\n * @default false\n */\n defaultChecked?: 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 /**\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> & Required<Pick<SwitchProps, 'labelPosition'>>;\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,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,59 +1,79 @@
1
- import { getNativeElementProps, resolveShorthand, useId } from '@fluentui/react-utilities';
2
- 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';
3
5
  /**
4
- * Given user props, returns state and render function for a Switch.
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
5
13
  */
6
14
 
7
15
  export const useSwitch_unstable = (props, ref) => {
8
16
  const {
9
- track,
10
- thumbWrapper,
11
- thumb,
12
- activeRail,
13
- input,
14
- defaultChecked,
15
17
  checked,
16
- disabled,
17
- onChange
18
- } = props;
19
- const state = {
20
18
  defaultChecked,
21
- checked,
22
19
  disabled,
20
+ labelPosition = 'after',
23
21
  onChange,
24
- root: getNativeElementProps('span', {
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,
25
46
  ref,
26
- ...props,
27
- id: useId('switch-', props.id)
28
- }),
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
29
67
  components: {
30
68
  root: 'div',
31
- track: 'div',
32
- thumbWrapper: 'div',
33
- thumb: 'div',
34
- activeRail: 'div',
35
- input: 'input'
69
+ indicator: 'div',
70
+ input: 'input',
71
+ label: Label
36
72
  },
37
- track: resolveShorthand(track, {
38
- required: true
39
- }),
40
- thumbWrapper: resolveShorthand(thumbWrapper, {
41
- required: true
42
- }),
43
- thumb: resolveShorthand(thumb, {
44
- required: true
45
- }),
46
- activeRail: resolveShorthand(activeRail, {
47
- required: true
48
- }),
49
- input: resolveShorthand(input, {
50
- required: true,
51
- defaultProps: {
52
- type: 'checkbox'
53
- }
54
- })
73
+ root,
74
+ indicator,
75
+ input,
76
+ label
55
77
  };
56
- useSwitchState(state);
57
- return state;
58
78
  };
59
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,MAAM,kBAAkB,GAAG,CAAC,KAAD,EAAqB,GAArB,KAAiE;AACjG,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA,YAAT;AAAuB,IAAA,KAAvB;AAA8B,IAAA,UAA9B;AAA0C,IAAA,KAA1C;AAAiD,IAAA,cAAjD;AAAiE,IAAA,OAAjE;AAA0E,IAAA,QAA1E;AAAoF,IAAA;AAApF,MAAiG,KAAvG;AACA,QAAM,KAAK,GAAgB;AACzB,IAAA,cADyB;AAEzB,IAAA,OAFyB;AAGzB,IAAA,QAHyB;AAIzB,IAAA,QAJyB;AAKzB,IAAA,IAAI,EAAE,qBAAqB,CAAC,MAAD,EAAS;AAClC,MAAA,GADkC;AAElC,SAAG,KAF+B;AAGlC,MAAA,EAAE,EAAE,KAAK,CAAC,SAAD,EAAY,KAAK,CAAC,EAAlB;AAHyB,KAAT,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
+ {"version":3,"sources":["components/Switch/useSwitch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,YAAT,QAA6B,uBAA7B;AACA,SAAS,KAAT,QAAsB,uBAAtB;AACA,SAAS,yBAAT,EAAoC,gBAApC,EAAsD,KAAtD,EAA6D,uBAA7D,QAA4F,2BAA5F;AAGA;;;;;;;;AAQG;;AACH,OAAO,MAAM,kBAAkB,GAAG,CAAC,KAAD,EAAqB,GAArB,KAAsE;AACtG,QAAM;AAAE,IAAA,OAAF;AAAW,IAAA,cAAX;AAA2B,IAAA,QAA3B;AAAqC,IAAA,aAAa,GAAG,OAArD;AAA8D,IAAA,QAA9D;AAAwE,IAAA;AAAxE,MAAqF,KAA3F;AAEA,QAAM,WAAW,GAAG,yBAAyB,CAAC;AAC5C,IAAA,KAD4C;AAE5C,IAAA,kBAAkB,EAAE,OAFwB;AAG5C,IAAA,iBAAiB,EAAE,CAAC,SAAD,EAAY,gBAAZ,EAA8B,UAA9B;AAHyB,GAAD,CAA7C;AAMA,QAAM,EAAE,GAAG,KAAK,CAAC,SAAD,EAAY,WAAW,CAAC,OAAZ,CAAoB,EAAhC,CAAhB;AAEA,QAAM,IAAI,GAAG,gBAAgB,CAAC,KAAK,CAAC,IAAP,EAAa;AACxC,IAAA,YAAY,EAAE,WAAW,CAAC,IADc;AAExC,IAAA,QAAQ,EAAE;AAF8B,GAAb,CAA7B;AAKA,QAAM,SAAS,GAAG,gBAAgB,CAAC,KAAK,CAAC,SAAP,EAAkB;AAClD,IAAA,YAAY,EAAE;AACZ,qBAAe,IADH;AAEZ,MAAA,QAAQ,eAAE,KAAA,CAAA,aAAA,CAAC,YAAD,EAAa,IAAb;AAFE,KADoC;AAKlD,IAAA,QAAQ,EAAE;AALwC,GAAlB,CAAlC;AAQA,QAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAP,EAAc;AAC1C,IAAA,YAAY,EAAE;AACZ,MAAA,OADY;AAEZ,MAAA,cAFY;AAGZ,MAAA,EAHY;AAIZ,MAAA,GAJY;AAKZ,MAAA,IAAI,EAAE,QALM;AAMZ,MAAA,IAAI,EAAE,UANM;AAOZ,SAAG,WAAW,CAAC;AAPH,KAD4B;AAU1C,IAAA,QAAQ,EAAE;AAVgC,GAAd,CAA9B;AAYA,EAAA,KAAK,CAAC,QAAN,GAAiB,uBAAuB,CAAC,KAAK,CAAC,QAAP,EAAiB,EAAE,IAAI,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAQ,KAAA,CAAR,GAAA,QAAQ,CAAG,EAAH,EAAO;AAAE,IAAA,OAAO,EAAE,EAAE,CAAC,aAAH,CAAiB;AAA5B,GAAP,CAA/B,CAAxC;AAEA,QAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAP,EAAc;AAC1C,IAAA,YAAY,EAAE;AACZ,MAAA,QADY;AAEZ,MAAA,OAAO,EAAE,EAFG;AAGZ,MAAA,QAHY;AAIZ,MAAA,IAAI,EAAE;AAJM;AAD4B,GAAd,CAA9B;AASA,SAAO;AACL,IAAA,aADK;AAGL;AACA,IAAA,UAAU,EAAE;AACV,MAAA,IAAI,EAAE,KADI;AAEV,MAAA,SAAS,EAAE,KAFD;AAGV,MAAA,KAAK,EAAE,OAHG;AAIV,MAAA,KAAK,EAAE;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/"}