@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.
- package/CHANGELOG.json +457 -1
- package/CHANGELOG.md +167 -31
- 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 +1 -1
- 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 +8 -6
- package/lib/components/Switch/renderSwitch.js.map +1 -1
- package/lib/components/Switch/useSwitch.js +63 -43
- package/lib/components/Switch/useSwitch.js.map +1 -1
- package/lib/components/Switch/useSwitchStyles.js +171 -269
- 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.map +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.js.map +1 -1
- package/lib-commonjs/components/Switch/index.js.map +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.js +65 -43
- package/lib-commonjs/components/Switch/useSwitch.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitchStyles.js +173 -271
- 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 +19 -20
- package/dist/react-switch.d.ts +0 -89
- package/lib/Switch.d.ts +0 -1
- package/lib/components/Switch/Switch.d.ts +0 -6
- package/lib/components/Switch/Switch.types.d.ts +0 -59
- 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 -6
- 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/components/Switch/useSwitchStyles.d.ts +0 -6
- package/lib/index.d.ts +0 -2
- package/lib-commonjs/Switch.d.ts +0 -1
- package/lib-commonjs/components/Switch/Switch.d.ts +0 -6
- package/lib-commonjs/components/Switch/Switch.types.d.ts +0 -59
- 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 -6
- 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
- package/lib-commonjs/components/Switch/useSwitchStyles.d.ts +0 -6
- package/lib-commonjs/index.d.ts +0 -2
@@ -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":["
|
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,CAAA;AAGA;;AAEG;;;AACI,MAAM,qBAAqB,GAAI,KAAD,IAAuB;AAC1D,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,iBAAA,CAAA,QAAA,CAAsB,KAAtB,CAA7B;AACA,QAAM;AAAE,IAAA;AAAF,MAAoB,KAA1B;AAEA,SACE,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,IAA4C,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,IAA4C,KAAA,CAAA,aAAA,CAAC,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/"}
|
@@ -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":["
|
1
|
+
{"version":3,"sources":["components/Switch/useSwitch.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,aAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;;AACA,MAAA,aAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAGA;;;;;;;;AAQG;;;AACI,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,iBAAA,CAAA,yBAAA,CAA0B;AAC5C,IAAA,KAD4C;AAE5C,IAAA,kBAAkB,EAAE,OAFwB;AAG5C,IAAA,iBAAi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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/"}
|