@fluentui/react-switch 9.0.0-nightly.f81b28ceb3.1 → 9.0.0-rc.11
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.
- package/CHANGELOG.json +695 -27
- package/CHANGELOG.md +221 -42
- package/MIGRATION.md +89 -22
- package/Spec.md +179 -84
- package/dist/index.d.ts +107 -0
- package/{lib → dist}/tsdoc-metadata.json +0 -0
- package/lib/Switch.js.map +1 -1
- package/lib/components/Switch/Switch.js +8 -8
- package/lib/components/Switch/Switch.js.map +1 -1
- package/lib/components/Switch/Switch.types.js.map +1 -1
- package/lib/components/Switch/index.js.map +1 -1
- package/lib/components/Switch/renderSwitch.js +15 -9
- package/lib/components/Switch/renderSwitch.js.map +1 -1
- package/lib/components/Switch/useSwitch.js +70 -54
- package/lib/components/Switch/useSwitch.js.map +1 -1
- package/lib/components/Switch/useSwitchStyles.js +156 -248
- package/lib/components/Switch/useSwitchStyles.js.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/Switch.js +1 -1
- package/lib-commonjs/Switch.js.map +1 -1
- package/lib-commonjs/components/Switch/Switch.js +9 -9
- package/lib-commonjs/components/Switch/Switch.js.map +1 -1
- package/lib-commonjs/components/Switch/Switch.types.js.map +1 -1
- package/lib-commonjs/components/Switch/index.js +1 -1
- package/lib-commonjs/components/Switch/index.js.map +1 -1
- package/lib-commonjs/components/Switch/renderSwitch.js +19 -15
- package/lib-commonjs/components/Switch/renderSwitch.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitch.js +73 -56
- package/lib-commonjs/components/Switch/useSwitch.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitchStyles.js +161 -252
- package/lib-commonjs/components/Switch/useSwitchStyles.js.map +1 -1
- package/lib-commonjs/index.js +39 -2
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +21 -27
- package/dist/react-switch.d.ts +0 -92
- package/lib/Switch.d.ts +0 -1
- package/lib/common/isConformant.d.ts +0 -4
- package/lib/common/isConformant.js +0 -12
- package/lib/common/isConformant.js.map +0 -1
- package/lib/components/Switch/Switch.d.ts +0 -6
- package/lib/components/Switch/Switch.types.d.ts +0 -58
- package/lib/components/Switch/index.d.ts +0 -5
- package/lib/components/Switch/renderSwitch.d.ts +0 -5
- package/lib/components/Switch/useSwitch.d.ts +0 -10
- package/lib/components/Switch/useSwitchState.d.ts +0 -2
- package/lib/components/Switch/useSwitchState.js +0 -152
- package/lib/components/Switch/useSwitchState.js.map +0 -1
- package/lib/components/Switch/useSwitchStyles.d.ts +0 -5
- package/lib/index.d.ts +0 -2
- package/lib-commonjs/Switch.d.ts +0 -1
- package/lib-commonjs/common/isConformant.d.ts +0 -4
- package/lib-commonjs/common/isConformant.js +0 -23
- package/lib-commonjs/common/isConformant.js.map +0 -1
- package/lib-commonjs/components/Switch/Switch.d.ts +0 -6
- package/lib-commonjs/components/Switch/Switch.types.d.ts +0 -58
- package/lib-commonjs/components/Switch/index.d.ts +0 -5
- package/lib-commonjs/components/Switch/renderSwitch.d.ts +0 -5
- package/lib-commonjs/components/Switch/useSwitch.d.ts +0 -10
- package/lib-commonjs/components/Switch/useSwitchState.d.ts +0 -2
- package/lib-commonjs/components/Switch/useSwitchState.js +0 -164
- package/lib-commonjs/components/Switch/useSwitchState.js.map +0 -1
- package/lib-commonjs/components/Switch/useSwitchStyles.d.ts +0 -5
- 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
|
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
|
-
|
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
|
-
|
22
|
+
### [Toggle in v8/Fabric](https://developer.microsoft.com/en-us/fluentui#/controls/web/toggle)
|
13
23
|
|
14
|
-
|
24
|
+
The v8 `Toggle` component
|
15
25
|
|
16
|
-
|
17
|
-
|
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
|
-
```
|
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
|
-
|
30
|
-
| -------------- | ------- | ------- | --------------------------------------------------------------------------- |
|
31
|
-
| checked | ✓ | ✓ | The value of the Switch. If `true` then the Switch will be enabled. |
|
32
|
-
| defaultChecked | ✓ | ✓ | The default value of the Switch. If `true` then the Switch will be enabled. |
|
33
|
-
| disabled | ✓ | ✓ | Whether the Switch should be disabled. |
|
34
|
-
| onChange | ✓ | ✓ | Callback to be called when the checked state value changes. |
|
110
|
+
### Switch Props
|
35
111
|
|
36
|
-
|
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
|
-
|
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
|
-
|
71
|
-
|
123
|
+
### Public
|
124
|
+
|
125
|
+
```tsx
|
126
|
+
<Switch checked={true} />
|
72
127
|
```
|
73
128
|
|
74
|
-
|
129
|
+
### Internal
|
75
130
|
|
76
|
-
```
|
131
|
+
```tsx
|
77
132
|
<slots.root {...slotProps.root}>
|
78
|
-
<slots.
|
79
|
-
<slots.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
154
|
+
_With label after the track thumb indicator:_
|
87
155
|
|
88
|
-
```
|
89
|
-
<div
|
90
|
-
<
|
91
|
-
<div
|
92
|
-
<
|
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
|
-
<
|
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
|
-
###
|
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
|
-
|
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
|
-
|
186
|
+
A hovered `Switch` changes styling to communicate that the user has placed a cursor above it.
|
113
187
|
|
114
|
-
|
188
|
+
#### Pressed state
|
115
189
|
|
116
|
-
|
190
|
+
A pressed `Switch` changes styling to communicate that the user is currently pressing it.
|
117
191
|
|
118
|
-
|
119
|
-
The expected keyboard shortcut for activating a Switch is the spacebar key.
|
192
|
+
#### Unchecked state
|
120
193
|
|
121
|
-
|
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
|
-
|
196
|
+
#### Checked state
|
125
197
|
|
126
|
-
|
198
|
+
A checked `Switch` has the thumb on the right (left in RTL) and styling to indicate that it is on.
|
127
199
|
|
128
|
-
###
|
200
|
+
### Interaction
|
129
201
|
|
130
|
-
|
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
|
-
|
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.
|
package/dist/index.d.ts
ADDED
@@ -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'>, '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":["
|
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,15 +1,15 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import {
|
2
|
+
import { useSwitch_unstable } from './useSwitch';
|
3
|
+
import { renderSwitch_unstable } from './renderSwitch';
|
4
|
+
import { useSwitchStyles_unstable } from './useSwitchStyles';
|
5
5
|
/**
|
6
|
-
*
|
6
|
+
* Switches enable users to trigger an option on or off through pressing the component.
|
7
7
|
*/
|
8
8
|
|
9
|
-
export
|
10
|
-
|
11
|
-
|
12
|
-
return
|
9
|
+
export const Switch = /*#__PURE__*/React.forwardRef((props, ref) => {
|
10
|
+
const state = useSwitch_unstable(props, ref);
|
11
|
+
useSwitchStyles_unstable(state);
|
12
|
+
return renderSwitch_unstable(state);
|
13
13
|
});
|
14
14
|
Switch.displayName = 'Switch';
|
15
15
|
//# sourceMappingURL=Switch.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
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":["
|
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<ComponentProps<Partial<SwitchSlots>, 'input'>, 'onChange'> & {\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":["
|
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,16 +1,22 @@
|
|
1
|
-
import { __assign } from "tslib";
|
2
1
|
import * as React from 'react';
|
3
2
|
import { getSlots } from '@fluentui/react-utilities';
|
4
|
-
import { switchShorthandProps } from './useSwitch';
|
5
3
|
/**
|
6
|
-
* Render the
|
4
|
+
* Render a Switch component by passing the state defined props to the appropriate slots.
|
7
5
|
*/
|
8
6
|
|
9
|
-
export
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
export const renderSwitch_unstable = state => {
|
8
|
+
const {
|
9
|
+
slots,
|
10
|
+
slotProps
|
11
|
+
} = getSlots(state);
|
12
|
+
const {
|
13
|
+
labelPosition
|
14
|
+
} = state;
|
15
|
+
return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
16
|
+
}, /*#__PURE__*/React.createElement(slots.input, { ...slotProps.input
|
17
|
+
}), labelPosition !== 'after' && slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
|
18
|
+
}), /*#__PURE__*/React.createElement(slots.indicator, { ...slotProps.indicator
|
19
|
+
}), labelPosition === 'after' && slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
|
20
|
+
}));
|
15
21
|
};
|
16
22
|
//# sourceMappingURL=renderSwitch.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
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/"}
|