@fluentui/react-switch 9.0.0-rc.3 → 9.0.0-rc.6
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 +168 -1
- package/CHANGELOG.md +47 -2
- package/MIGRATION.md +89 -22
- package/Spec.md +179 -84
- package/dist/react-switch.d.ts +59 -40
- package/lib/components/Switch/Switch.d.ts +1 -1
- package/lib/components/Switch/Switch.js +1 -1
- package/lib/components/Switch/Switch.js.map +1 -1
- package/lib/components/Switch/Switch.types.d.ts +41 -35
- package/lib/components/Switch/Switch.types.js.map +1 -1
- package/lib/components/Switch/renderSwitch.d.ts +1 -1
- package/lib/components/Switch/renderSwitch.js +8 -6
- package/lib/components/Switch/renderSwitch.js.map +1 -1
- package/lib/components/Switch/useSwitch.d.ts +8 -2
- package/lib/components/Switch/useSwitch.js +63 -43
- package/lib/components/Switch/useSwitch.js.map +1 -1
- package/lib/components/Switch/useSwitchStyles.d.ts +7 -2
- package/lib/components/Switch/useSwitchStyles.js +165 -266
- package/lib/components/Switch/useSwitchStyles.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/components/Switch/Switch.d.ts +1 -1
- package/lib-commonjs/components/Switch/Switch.js +1 -1
- package/lib-commonjs/components/Switch/Switch.js.map +1 -1
- package/lib-commonjs/components/Switch/Switch.types.d.ts +41 -35
- package/lib-commonjs/components/Switch/renderSwitch.d.ts +1 -1
- package/lib-commonjs/components/Switch/renderSwitch.js +8 -6
- package/lib-commonjs/components/Switch/renderSwitch.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitch.d.ts +8 -2
- package/lib-commonjs/components/Switch/useSwitch.js +65 -43
- package/lib-commonjs/components/Switch/useSwitch.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitchStyles.d.ts +7 -2
- package/lib-commonjs/components/Switch/useSwitchStyles.js +167 -268
- package/lib-commonjs/components/Switch/useSwitchStyles.js.map +1 -1
- package/lib-commonjs/index.d.ts +2 -2
- package/lib-commonjs/index.js +39 -2
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +16 -17
- package/lib/components/Switch/useSwitchState.d.ts +0 -2
- package/lib/components/Switch/useSwitchState.js +0 -144
- package/lib/components/Switch/useSwitchState.js.map +0 -1
- package/lib-commonjs/components/Switch/useSwitchState.d.ts +0 -2
- package/lib-commonjs/components/Switch/useSwitchState.js +0 -156
- package/lib-commonjs/components/Switch/useSwitchState.js.map +0 -1
@@ -1,59 +1,65 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
+
import { Label } from '@fluentui/react-label';
|
2
3
|
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
|
3
4
|
export declare type SwitchSlots = {
|
4
5
|
/**
|
5
|
-
* The root of the Switch.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
* The bar indicating the status of the Switch.
|
10
|
-
*/
|
11
|
-
track: NonNullable<Slot<'div'>>;
|
12
|
-
/**
|
13
|
-
* The wrapper around the thumb. It is used as the active area for the thumb to position itself.
|
6
|
+
* The root element of the Switch.
|
7
|
+
*
|
8
|
+
* The root slot receives the `className` and `style` specified directly on the `<Switch>` tag.
|
9
|
+
* All other native props will be applied to the primary slot: `input`.
|
14
10
|
*/
|
15
|
-
|
11
|
+
root: NonNullable<Slot<'div'>>;
|
16
12
|
/**
|
17
|
-
* The
|
13
|
+
* The track and the thumb sliding over it indicating the on and off status of the Switch.
|
18
14
|
*/
|
19
|
-
|
15
|
+
indicator: NonNullable<Slot<'div'>>;
|
20
16
|
/**
|
21
|
-
*
|
17
|
+
* Hidden input that handles the Switch's functionality.
|
18
|
+
*
|
19
|
+
* This is the PRIMARY slot: all native properties specified directly on the `<Switch>` tag will be applied to this
|
20
|
+
* slot, except `className` and `style`, which remain on the root slot.
|
22
21
|
*/
|
23
22
|
input: NonNullable<Slot<'input'>>;
|
24
23
|
/**
|
25
|
-
* The
|
24
|
+
* The Switch's label.
|
26
25
|
*/
|
27
|
-
|
26
|
+
label?: Slot<typeof Label>;
|
28
27
|
};
|
29
|
-
|
28
|
+
declare type SwitchCommons = {
|
30
29
|
/**
|
31
|
-
*
|
32
|
-
*
|
33
|
-
*
|
30
|
+
* Defines the controlled checked state of the Switch.
|
31
|
+
* If passed, Switch ignores the `defaultChecked` property.
|
32
|
+
* This should only be used if the checked state is to be controlled at a higher level and there is a plan to pass the
|
33
|
+
* correct value based on handling `onChange` events and re-rendering.
|
34
34
|
* @default false
|
35
35
|
*/
|
36
|
-
defaultChecked?: boolean;
|
37
|
-
/**
|
38
|
-
* The current value for a controlled Switch. If `true` then the Switch will be enabled.
|
39
|
-
* Mutually exclusive with `defaultChecked` prop.
|
40
|
-
*/
|
41
36
|
checked?: boolean;
|
42
37
|
/**
|
43
|
-
*
|
38
|
+
* The position of the label relative to the Switch.
|
44
39
|
*
|
40
|
+
* @default after
|
41
|
+
*/
|
42
|
+
labelPosition: 'above' | 'after' | 'before';
|
43
|
+
};
|
44
|
+
export declare type SwitchOnChangeData = {
|
45
|
+
checked: boolean;
|
46
|
+
};
|
47
|
+
/**
|
48
|
+
* Switch Props
|
49
|
+
*/
|
50
|
+
export declare type SwitchProps = Omit<ComponentProps<Partial<SwitchSlots>, 'input'>, 'onChange'> & Partial<SwitchCommons> & {
|
51
|
+
/**
|
52
|
+
* Defines whether the Switch is initially in a checked state or not when rendered.
|
45
53
|
* @default false
|
46
54
|
*/
|
47
|
-
|
55
|
+
defaultChecked?: boolean;
|
48
56
|
/**
|
49
|
-
* Callback to be called when the
|
57
|
+
* Callback to be called when the checked state value changes.
|
50
58
|
*/
|
51
|
-
onChange?: (ev: React.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
export interface SwitchState extends ComponentState<SwitchSlots>, SwitchCommons {
|
58
|
-
}
|
59
|
+
onChange?: (ev: React.ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => void;
|
60
|
+
};
|
61
|
+
/**
|
62
|
+
* State used in rendering Switch
|
63
|
+
*/
|
64
|
+
export declare type SwitchState = ComponentState<SwitchSlots> & SwitchCommons;
|
59
65
|
export {};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { SwitchState } from './Switch.types';
|
2
2
|
/**
|
3
|
-
* Render the
|
3
|
+
* Render a Switch component by passing the state defined props to the appropriate slots.
|
4
4
|
*/
|
5
5
|
export declare const renderSwitch_unstable: (state: SwitchState) => JSX.Element;
|
@@ -9,7 +9,7 @@ const React = /*#__PURE__*/require("react");
|
|
9
9
|
|
10
10
|
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
11
11
|
/**
|
12
|
-
* Render the
|
12
|
+
* Render a Switch component by passing the state defined props to the appropriate slots.
|
13
13
|
*/
|
14
14
|
|
15
15
|
|
@@ -18,12 +18,14 @@ const renderSwitch_unstable = state => {
|
|
18
18
|
slots,
|
19
19
|
slotProps
|
20
20
|
} = react_utilities_1.getSlots(state);
|
21
|
+
const {
|
22
|
+
labelPosition
|
23
|
+
} = state;
|
21
24
|
return React.createElement(slots.root, { ...slotProps.root
|
22
|
-
}, React.createElement(slots.
|
23
|
-
}), React.createElement(slots.
|
24
|
-
}, React.createElement(slots.
|
25
|
-
})
|
26
|
-
}), React.createElement(slots.activeRail, { ...slotProps.activeRail
|
25
|
+
}, React.createElement(slots.input, { ...slotProps.input
|
26
|
+
}), labelPosition !== 'after' && slots.label && React.createElement(slots.label, { ...slotProps.label
|
27
|
+
}), React.createElement(slots.indicator, { ...slotProps.indicator
|
28
|
+
}), labelPosition === 'after' && slots.label && React.createElement(slots.label, { ...slotProps.label
|
27
29
|
}));
|
28
30
|
};
|
29
31
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["components/Switch/renderSwitch.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA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C,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CAJ/C,CADF;AAQD,CAZM;;AAAM,OAAA,CAAA,qBAAA,GAAqB,qBAArB","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { SwitchState, SwitchSlots } from './Switch.types';\n\n/**\n * Render a Switch component by passing the state defined props to the appropriate slots.\n */\nexport const renderSwitch_unstable = (state: SwitchState) => {\n const { slots, slotProps } = getSlots<SwitchSlots>(state);\n const { labelPosition } = state;\n\n return (\n <slots.root {...slotProps.root}>\n <slots.input {...slotProps.input} />\n {labelPosition !== 'after' && slots.label && <slots.label {...slotProps.label} />}\n <slots.indicator {...slotProps.indicator} />\n {labelPosition === 'after' && slots.label && <slots.label {...slotProps.label} />}\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -1,6 +1,12 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import type { SwitchProps, SwitchState } from './Switch.types';
|
3
3
|
/**
|
4
|
-
*
|
4
|
+
* Create the state required to render Switch.
|
5
|
+
*
|
6
|
+
* The returned state can be modified with hooks such as useSwitchStyles_unstable,
|
7
|
+
* before being passed to renderSwitch_unstable.
|
8
|
+
*
|
9
|
+
* @param props - props from this instance of Switch
|
10
|
+
* @param ref - reference to `<input>` element of Switch
|
5
11
|
*/
|
6
|
-
export declare const useSwitch_unstable: (props: SwitchProps, ref: React.Ref<
|
12
|
+
export declare const useSwitch_unstable: (props: SwitchProps, ref: React.Ref<HTMLInputElement>) => SwitchState;
|
@@ -5,65 +5,87 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.useSwitch_unstable = void 0;
|
7
7
|
|
8
|
-
const
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
|
+
|
10
|
+
const react_icons_1 = /*#__PURE__*/require("@fluentui/react-icons");
|
9
11
|
|
10
|
-
const
|
12
|
+
const react_label_1 = /*#__PURE__*/require("@fluentui/react-label");
|
13
|
+
|
14
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
11
15
|
/**
|
12
|
-
*
|
16
|
+
* Create the state required to render Switch.
|
17
|
+
*
|
18
|
+
* The returned state can be modified with hooks such as useSwitchStyles_unstable,
|
19
|
+
* before being passed to renderSwitch_unstable.
|
20
|
+
*
|
21
|
+
* @param props - props from this instance of Switch
|
22
|
+
* @param ref - reference to `<input>` element of Switch
|
13
23
|
*/
|
14
24
|
|
15
25
|
|
16
26
|
const useSwitch_unstable = (props, ref) => {
|
17
27
|
const {
|
18
|
-
track,
|
19
|
-
thumbWrapper,
|
20
|
-
thumb,
|
21
|
-
activeRail,
|
22
|
-
input,
|
23
|
-
defaultChecked,
|
24
28
|
checked,
|
25
|
-
disabled,
|
26
|
-
onChange
|
27
|
-
} = props;
|
28
|
-
const state = {
|
29
29
|
defaultChecked,
|
30
|
-
checked,
|
31
30
|
disabled,
|
31
|
+
labelPosition = 'after',
|
32
32
|
onChange,
|
33
|
-
|
33
|
+
required
|
34
|
+
} = props;
|
35
|
+
const nativeProps = react_utilities_1.getPartitionedNativeProps({
|
36
|
+
props,
|
37
|
+
primarySlotTagName: 'input',
|
38
|
+
excludedPropNames: ['checked', 'defaultChecked', 'onChange']
|
39
|
+
});
|
40
|
+
const id = react_utilities_1.useId('switch-', nativeProps.primary.id);
|
41
|
+
const root = react_utilities_1.resolveShorthand(props.root, {
|
42
|
+
defaultProps: nativeProps.root,
|
43
|
+
required: true
|
44
|
+
});
|
45
|
+
const indicator = react_utilities_1.resolveShorthand(props.indicator, {
|
46
|
+
defaultProps: {
|
47
|
+
'aria-hidden': true,
|
48
|
+
children: React.createElement(react_icons_1.CircleFilled, null)
|
49
|
+
},
|
50
|
+
required: true
|
51
|
+
});
|
52
|
+
const input = react_utilities_1.resolveShorthand(props.input, {
|
53
|
+
defaultProps: {
|
54
|
+
checked,
|
55
|
+
defaultChecked,
|
56
|
+
id,
|
34
57
|
ref,
|
35
|
-
|
36
|
-
|
37
|
-
|
58
|
+
role: 'switch',
|
59
|
+
type: 'checkbox',
|
60
|
+
...nativeProps.primary
|
61
|
+
},
|
62
|
+
required: true
|
63
|
+
});
|
64
|
+
input.onChange = react_utilities_1.useMergedEventCallbacks(input.onChange, ev => onChange === null || onChange === void 0 ? void 0 : onChange(ev, {
|
65
|
+
checked: ev.currentTarget.checked
|
66
|
+
}));
|
67
|
+
const label = react_utilities_1.resolveShorthand(props.label, {
|
68
|
+
defaultProps: {
|
69
|
+
disabled,
|
70
|
+
htmlFor: id,
|
71
|
+
required,
|
72
|
+
size: 'medium'
|
73
|
+
}
|
74
|
+
});
|
75
|
+
return {
|
76
|
+
labelPosition,
|
77
|
+
//Slots definition
|
38
78
|
components: {
|
39
79
|
root: 'div',
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
activeRail: 'div',
|
44
|
-
input: 'input'
|
80
|
+
indicator: 'div',
|
81
|
+
input: 'input',
|
82
|
+
label: react_label_1.Label
|
45
83
|
},
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
required: true
|
51
|
-
}),
|
52
|
-
thumb: react_utilities_1.resolveShorthand(thumb, {
|
53
|
-
required: true
|
54
|
-
}),
|
55
|
-
activeRail: react_utilities_1.resolveShorthand(activeRail, {
|
56
|
-
required: true
|
57
|
-
}),
|
58
|
-
input: react_utilities_1.resolveShorthand(input, {
|
59
|
-
required: true,
|
60
|
-
defaultProps: {
|
61
|
-
type: 'checkbox'
|
62
|
-
}
|
63
|
-
})
|
84
|
+
root,
|
85
|
+
indicator,
|
86
|
+
input,
|
87
|
+
label
|
64
88
|
};
|
65
|
-
useSwitchState_1.useSwitchState(state);
|
66
|
-
return state;
|
67
89
|
};
|
68
90
|
|
69
91
|
exports.useSwitch_unstable = useSwitch_unstable;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["components/Switch/useSwitch.
|
1
|
+
{"version":3,"sources":["components/Switch/useSwitch.tsx"],"names":[],"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AAC,KAAvB,EAA8B;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,GAA9B,CAAd;AAYA,EAAA,KAAK,CAAC,QAAN,GAAiB,iBAAA,CAAA,uBAAA,CAAwB,KAAK,CAAC,QAA9B,EAAwC,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,CAAtD,CAAjB;AAEA,QAAM,KAAK,GAAG,iBAAA,CAAA,gBAAA,CAAiB,KAAK,CAAC,KAAvB,EAA8B;AAC1C,IAAA,YAAY,EAAE;AACZ,MAAA,QADY;AAEZ,MAAA,OAAO,EAAE,EAFG;AAGZ,MAAA,QAHY;AAIZ,MAAA,IAAI,EAAE;AAJM;AAD4B,GAA9B,CAAd;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,aAAA,CAAA;AAJG,KAJP;AAWL,IAAA,IAXK;AAYL,IAAA,SAZK;AAaL,IAAA,KAbK;AAcL,IAAA;AAdK,GAAP;AAgBD,CA/DM;;AAAM,OAAA,CAAA,kBAAA,GAAkB,kBAAlB","sourcesContent":["import * as React from 'react';\nimport { CircleFilled } from '@fluentui/react-icons';\nimport { Label } from '@fluentui/react-label';\nimport { getPartitionedNativeProps, resolveShorthand, useId, useMergedEventCallbacks } from '@fluentui/react-utilities';\nimport type { SwitchProps, SwitchState } from './Switch.types';\n\n/**\n * Create the state required to render Switch.\n *\n * The returned state can be modified with hooks such as useSwitchStyles_unstable,\n * before being passed to renderSwitch_unstable.\n *\n * @param props - props from this instance of Switch\n * @param ref - reference to `<input>` element of Switch\n */\nexport const useSwitch_unstable = (props: SwitchProps, ref: React.Ref<HTMLInputElement>): SwitchState => {\n const { checked, defaultChecked, disabled, labelPosition = 'after', onChange, required } = props;\n\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['checked', 'defaultChecked', 'onChange'],\n });\n\n const id = useId('switch-', nativeProps.primary.id);\n\n const root = resolveShorthand(props.root, {\n defaultProps: nativeProps.root,\n required: true,\n });\n\n const indicator = resolveShorthand(props.indicator, {\n defaultProps: {\n 'aria-hidden': true,\n children: <CircleFilled />,\n },\n required: true,\n });\n\n const input = resolveShorthand(props.input, {\n defaultProps: {\n checked,\n defaultChecked,\n id,\n ref,\n role: 'switch',\n type: 'checkbox',\n ...nativeProps.primary,\n },\n required: true,\n });\n input.onChange = useMergedEventCallbacks(input.onChange, ev => onChange?.(ev, { checked: ev.currentTarget.checked }));\n\n const label = resolveShorthand(props.label, {\n defaultProps: {\n disabled,\n htmlFor: id,\n required,\n size: 'medium',\n },\n });\n\n return {\n labelPosition,\n\n //Slots definition\n components: {\n root: 'div',\n indicator: 'div',\n input: 'input',\n label: Label,\n },\n\n root,\n indicator,\n input,\n label,\n };\n};\n"],"sourceRoot":"../src/"}
|
@@ -1,5 +1,10 @@
|
|
1
|
-
import type {
|
2
|
-
|
1
|
+
import type { SlotClassNames } from '@fluentui/react-utilities';
|
2
|
+
import type { SwitchSlots, SwitchState } from './Switch.types';
|
3
|
+
export declare const switchClassNames: SlotClassNames<SwitchSlots>;
|
4
|
+
/**
|
5
|
+
* @deprecated Use `switchClassNames.root` instead.
|
6
|
+
*/
|
7
|
+
export declare const switchClassName: string;
|
3
8
|
/**
|
4
9
|
* Apply styling to the Switch slots based on the state
|
5
10
|
*/
|