@fluentui/react-switch 0.0.0-nightly-20230317-1454.1 → 0.0.0-nightly-20230321-0440.1
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 +17 -17
- package/CHANGELOG.md +11 -11
- package/lib/Switch.js +1 -1
- package/lib/Switch.js.map +1 -1
- package/lib/SwitchField.js +1 -1
- package/lib/SwitchField.js.map +1 -1
- package/lib/components/Switch/Switch.js +6 -6
- package/lib/components/Switch/Switch.js.map +1 -1
- package/lib/components/Switch/Switch.types.js +1 -1
- package/lib/components/Switch/Switch.types.js.map +1 -1
- package/lib/components/Switch/index.js +5 -5
- package/lib/components/Switch/index.js.map +1 -1
- package/lib/components/Switch/renderSwitch.js +13 -3
- package/lib/components/Switch/renderSwitch.js.map +1 -1
- package/lib/components/Switch/useSwitch.js +17 -17
- package/lib/components/Switch/useSwitch.js.map +1 -1
- package/lib/components/Switch/useSwitchStyles.js +9 -9
- package/lib/components/Switch/useSwitchStyles.js.map +1 -1
- package/lib/components/SwitchField/SwitchField.js +3 -2
- package/lib/components/SwitchField/SwitchField.js.map +1 -1
- package/lib/components/SwitchField/index.js +1 -1
- package/lib/components/SwitchField/index.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib-commonjs/Switch.js +4 -5
- package/lib-commonjs/Switch.js.map +1 -1
- package/lib-commonjs/SwitchField.js +4 -5
- package/lib-commonjs/SwitchField.js.map +1 -1
- package/lib-commonjs/components/Switch/Switch.js +20 -19
- package/lib-commonjs/components/Switch/Switch.js.map +1 -1
- package/lib-commonjs/components/Switch/Switch.types.js +2 -5
- package/lib-commonjs/components/Switch/Switch.types.js.map +1 -1
- package/lib-commonjs/components/Switch/index.js +8 -9
- package/lib-commonjs/components/Switch/index.js.map +1 -1
- package/lib-commonjs/components/Switch/renderSwitch.js +29 -14
- package/lib-commonjs/components/Switch/renderSwitch.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitch.js +85 -76
- package/lib-commonjs/components/Switch/useSwitch.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitchStyles.js +89 -176
- package/lib-commonjs/components/Switch/useSwitchStyles.js.map +1 -1
- package/lib-commonjs/components/SwitchField/SwitchField.js +11 -17
- package/lib-commonjs/components/SwitchField/SwitchField.js.map +1 -1
- package/lib-commonjs/components/SwitchField/index.js +4 -5
- package/lib-commonjs/components/SwitchField/index.js.map +1 -1
- package/lib-commonjs/index.js +56 -23
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +12 -11
- package/.swcrc +0 -39
@@ -1,24 +1,25 @@
|
|
1
1
|
"use strict";
|
2
|
+
|
2
3
|
Object.defineProperty(exports, "__esModule", {
|
3
|
-
|
4
|
-
});
|
5
|
-
Object.defineProperty(exports, "Switch", {
|
6
|
-
enumerable: true,
|
7
|
-
get: ()=>Switch
|
4
|
+
value: true
|
8
5
|
});
|
9
|
-
|
10
|
-
const
|
11
|
-
const
|
12
|
-
const
|
13
|
-
const
|
14
|
-
const
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
exports.Switch = void 0;
|
7
|
+
const React = /*#__PURE__*/require("react");
|
8
|
+
const useSwitch_1 = /*#__PURE__*/require("./useSwitch");
|
9
|
+
const renderSwitch_1 = /*#__PURE__*/require("./renderSwitch");
|
10
|
+
const useSwitchStyles_1 = /*#__PURE__*/require("./useSwitchStyles");
|
11
|
+
const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
|
12
|
+
/**
|
13
|
+
* Switches enable users to trigger an option on or off through pressing the component.
|
14
|
+
*/
|
15
|
+
exports.Switch = /*#__PURE__*/React.forwardRef((props, ref) => {
|
16
|
+
const state = useSwitch_1.useSwitch_unstable(props, ref);
|
17
|
+
useSwitchStyles_1.useSwitchStyles_unstable(state);
|
18
|
+
const {
|
19
|
+
useSwitchStyles_unstable: useCustomStyles
|
20
|
+
} = react_shared_contexts_1.useCustomStyleHooks_unstable();
|
21
|
+
useCustomStyles(state);
|
22
|
+
return renderSwitch_1.renderSwitch_unstable(state);
|
21
23
|
});
|
22
|
-
Switch.displayName =
|
23
|
-
|
24
|
+
exports.Switch.displayName = 'Switch';
|
24
25
|
//# sourceMappingURL=Switch.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"names":["React","require","useSwitch_1","renderSwitch_1","useSwitchStyles_1","react_shared_contexts_1","exports","Switch","forwardRef","props","ref","state","useSwitch_unstable","useSwitchStyles_unstable","useCustomStyles","useCustomStyleHooks_unstable","renderSwitch_unstable","displayName"],"sources":["../../../../../../../../../packages/react-components/react-switch/src/components/Switch/Switch.tsx"],"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';\nimport { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts';\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 const { useSwitchStyles_unstable: useCustomStyles } = useCustomStyleHooks_unstable();\n useCustomStyles(state);\n\n return renderSwitch_unstable(state);\n});\n\nSwitch.displayName = 'Switch';\n"],"mappings":";;;;;;AAAA,MAAAA,KAAA,gBAAAC,OAAA;AACA,MAAAC,WAAA,gBAAAD,OAAA;AACA,MAAAE,cAAA,gBAAAF,OAAA;AACA,MAAAG,iBAAA,gBAAAH,OAAA;AAGA,MAAAI,uBAAA,gBAAAJ,OAAA;AAEA;;;AAGaK,OAAA,CAAAC,MAAM,gBAAqCP,KAAK,CAACQ,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAI;EACtF,MAAMC,KAAK,GAAGT,WAAA,CAAAU,kBAAkB,CAACH,KAAK,EAAEC,GAAG,CAAC;EAE5CN,iBAAA,CAAAS,wBAAwB,CAACF,KAAK,CAAC;EAE/B,MAAM;IAAEE,wBAAwB,EAAEC;EAAe,CAAE,GAAGT,uBAAA,CAAAU,4BAA4B,EAAE;EACpFD,eAAe,CAACH,KAAK,CAAC;EAEtB,OAAOR,cAAA,CAAAa,qBAAqB,CAACL,KAAK,CAAC;AACrC,CAAC,CAAC;AAEFL,OAAA,CAAAC,MAAM,CAACU,WAAW,GAAG,QAAQ"}
|
@@ -1,9 +1,6 @@
|
|
1
1
|
"use strict";
|
2
|
+
|
2
3
|
Object.defineProperty(exports, "__esModule", {
|
3
|
-
|
4
|
+
value: true
|
4
5
|
});
|
5
|
-
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
6
|
-
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
7
|
-
//# sourceMappingURL=Switch.types.js.map
|
8
|
-
|
9
6
|
//# sourceMappingURL=Switch.types.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"names":[],"sources":["../../../../../../../../../packages/react-components/react-switch/src/components/Switch/Switch.types.ts"],"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"],"mappings":""}
|
@@ -1,13 +1,12 @@
|
|
1
1
|
"use strict";
|
2
|
+
|
2
3
|
Object.defineProperty(exports, "__esModule", {
|
3
|
-
|
4
|
+
value: true
|
4
5
|
});
|
5
|
-
const
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
//# sourceMappingURL=index.js.map
|
12
|
-
|
6
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
7
|
+
tslib_1.__exportStar(require("./Switch"), exports);
|
8
|
+
tslib_1.__exportStar(require("./Switch.types"), exports);
|
9
|
+
tslib_1.__exportStar(require("./renderSwitch"), exports);
|
10
|
+
tslib_1.__exportStar(require("./useSwitch"), exports);
|
11
|
+
tslib_1.__exportStar(require("./useSwitchStyles"), exports);
|
13
12
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"names":["tslib_1","__exportStar","require","exports"],"sources":["../../../../../../../../../packages/react-components/react-switch/src/components/Switch/index.ts"],"sourcesContent":["export * from './Switch';\nexport * from './Switch.types';\nexport * from './renderSwitch';\nexport * from './useSwitch';\nexport * from './useSwitchStyles';\n"],"mappings":";;;;;;AAAAA,OAAA,CAAAC,YAAA,CAAAC,OAAA,cAAAC,OAAA;AACAH,OAAA,CAAAC,YAAA,CAAAC,OAAA,oBAAAC,OAAA;AACAH,OAAA,CAAAC,YAAA,CAAAC,OAAA,oBAAAC,OAAA;AACAH,OAAA,CAAAC,YAAA,CAAAC,OAAA,iBAAAC,OAAA;AACAH,OAAA,CAAAC,YAAA,CAAAC,OAAA,uBAAAC,OAAA"}
|
@@ -1,18 +1,33 @@
|
|
1
1
|
"use strict";
|
2
|
+
|
2
3
|
Object.defineProperty(exports, "__esModule", {
|
3
|
-
|
4
|
-
});
|
5
|
-
Object.defineProperty(exports, "renderSwitch_unstable", {
|
6
|
-
enumerable: true,
|
7
|
-
get: ()=>renderSwitch_unstable
|
4
|
+
value: true
|
8
5
|
});
|
9
|
-
|
10
|
-
const
|
11
|
-
const
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
exports.renderSwitch_unstable = void 0;
|
7
|
+
const React = /*#__PURE__*/require("react");
|
8
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
9
|
+
/**
|
10
|
+
* Render a Switch component by passing the state defined props to the appropriate slots.
|
11
|
+
*/
|
12
|
+
const renderSwitch_unstable = state => {
|
13
|
+
const {
|
14
|
+
slots,
|
15
|
+
slotProps
|
16
|
+
} = react_utilities_1.getSlots(state);
|
17
|
+
const {
|
18
|
+
labelPosition
|
19
|
+
} = state;
|
20
|
+
return React.createElement(slots.root, {
|
21
|
+
...slotProps.root
|
22
|
+
}, React.createElement(slots.input, {
|
23
|
+
...slotProps.input
|
24
|
+
}), labelPosition !== 'after' && slots.label && React.createElement(slots.label, {
|
25
|
+
...slotProps.label
|
26
|
+
}), React.createElement(slots.indicator, {
|
27
|
+
...slotProps.indicator
|
28
|
+
}), labelPosition === 'after' && slots.label && React.createElement(slots.label, {
|
29
|
+
...slotProps.label
|
30
|
+
}));
|
31
|
+
};
|
32
|
+
exports.renderSwitch_unstable = renderSwitch_unstable;
|
18
33
|
//# sourceMappingURL=renderSwitch.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"names":["React","require","react_utilities_1","renderSwitch_unstable","state","slots","slotProps","getSlots","labelPosition","createElement","root","input","label","indicator","exports"],"sources":["../../../../../../../../../packages/react-components/react-switch/src/components/Switch/renderSwitch.tsx"],"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"],"mappings":";;;;;;AAAA,MAAAA,KAAA,gBAAAC,OAAA;AACA,MAAAC,iBAAA,gBAAAD,OAAA;AAGA;;;AAGO,MAAME,qBAAqB,GAAIC,KAAkB,IAAI;EAC1D,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGJ,iBAAA,CAAAK,QAAQ,CAAcH,KAAK,CAAC;EACzD,MAAM;IAAEI;EAAa,CAAE,GAAGJ,KAAK;EAE/B,OACEJ,KAAA,CAAAS,aAAA,CAACJ,KAAK,CAACK,IAAI;IAAA,GAAKJ,SAAS,CAACI;EAAI,GAC5BV,KAAA,CAAAS,aAAA,CAACJ,KAAK,CAACM,KAAK;IAAA,GAAKL,SAAS,CAACK;EAAK,EAAI,EACnCH,aAAa,KAAK,OAAO,IAAIH,KAAK,CAACO,KAAK,IAAIZ,KAAA,CAAAS,aAAA,CAACJ,KAAK,CAACO,KAAK;IAAA,GAAKN,SAAS,CAACM;EAAK,EAAI,EACjFZ,KAAA,CAAAS,aAAA,CAACJ,KAAK,CAACQ,SAAS;IAAA,GAAKP,SAAS,CAACO;EAAS,EAAI,EAC3CL,aAAa,KAAK,OAAO,IAAIH,KAAK,CAACO,KAAK,IAAIZ,KAAA,CAAAS,aAAA,CAACJ,KAAK,CAACO,KAAK;IAAA,GAAKN,SAAS,CAACM;EAAK,EAAI,CACtE;AAEjB,CAAC;AAZYE,OAAA,CAAAX,qBAAqB,GAAAA,qBAAA"}
|
@@ -1,80 +1,89 @@
|
|
1
1
|
"use strict";
|
2
|
+
|
2
3
|
Object.defineProperty(exports, "__esModule", {
|
3
|
-
|
4
|
-
});
|
5
|
-
Object.defineProperty(exports, "useSwitch_unstable", {
|
6
|
-
enumerable: true,
|
7
|
-
get: ()=>useSwitch_unstable
|
4
|
+
value: true
|
8
5
|
});
|
9
|
-
|
10
|
-
const
|
11
|
-
const
|
12
|
-
const
|
13
|
-
const
|
14
|
-
const
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
6
|
+
exports.useSwitch_unstable = void 0;
|
7
|
+
const React = /*#__PURE__*/require("react");
|
8
|
+
const react_icons_1 = /*#__PURE__*/require("@fluentui/react-icons");
|
9
|
+
const react_label_1 = /*#__PURE__*/require("@fluentui/react-label");
|
10
|
+
const react_tabster_1 = /*#__PURE__*/require("@fluentui/react-tabster");
|
11
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
12
|
+
/**
|
13
|
+
* Create the state required to render Switch.
|
14
|
+
*
|
15
|
+
* The returned state can be modified with hooks such as useSwitchStyles_unstable,
|
16
|
+
* before being passed to renderSwitch_unstable.
|
17
|
+
*
|
18
|
+
* @param props - props from this instance of Switch
|
19
|
+
* @param ref - reference to `<input>` element of Switch
|
20
|
+
*/
|
21
|
+
const useSwitch_unstable = (props, ref) => {
|
22
|
+
const {
|
23
|
+
checked,
|
24
|
+
defaultChecked,
|
25
|
+
disabled,
|
26
|
+
labelPosition = 'after',
|
27
|
+
onChange,
|
28
|
+
required
|
29
|
+
} = props;
|
30
|
+
const nativeProps = react_utilities_1.getPartitionedNativeProps({
|
31
|
+
props,
|
32
|
+
primarySlotTagName: 'input',
|
33
|
+
excludedPropNames: ['checked', 'defaultChecked', 'onChange']
|
34
|
+
});
|
35
|
+
const id = react_utilities_1.useId('switch-', nativeProps.primary.id);
|
36
|
+
const root = react_utilities_1.resolveShorthand(props.root, {
|
37
|
+
defaultProps: {
|
38
|
+
ref: react_tabster_1.useFocusWithin(),
|
39
|
+
...nativeProps.root
|
40
|
+
},
|
41
|
+
required: true
|
42
|
+
});
|
43
|
+
const indicator = react_utilities_1.resolveShorthand(props.indicator, {
|
44
|
+
defaultProps: {
|
45
|
+
'aria-hidden': true,
|
46
|
+
children: React.createElement(react_icons_1.CircleFilled, null)
|
47
|
+
},
|
48
|
+
required: true
|
49
|
+
});
|
50
|
+
const input = react_utilities_1.resolveShorthand(props.input, {
|
51
|
+
defaultProps: {
|
52
|
+
checked,
|
53
|
+
defaultChecked,
|
54
|
+
id,
|
55
|
+
ref,
|
56
|
+
role: 'switch',
|
57
|
+
type: 'checkbox',
|
58
|
+
...nativeProps.primary
|
59
|
+
},
|
60
|
+
required: true
|
61
|
+
});
|
62
|
+
input.onChange = react_utilities_1.mergeCallbacks(input.onChange, ev => onChange === null || onChange === void 0 ? void 0 : onChange(ev, {
|
63
|
+
checked: ev.currentTarget.checked
|
64
|
+
}));
|
65
|
+
const label = react_utilities_1.resolveShorthand(props.label, {
|
66
|
+
defaultProps: {
|
67
|
+
disabled,
|
68
|
+
htmlFor: id,
|
69
|
+
required,
|
70
|
+
size: 'medium'
|
71
|
+
}
|
72
|
+
});
|
73
|
+
return {
|
74
|
+
labelPosition,
|
75
|
+
//Slots definition
|
76
|
+
components: {
|
77
|
+
root: 'div',
|
78
|
+
indicator: 'div',
|
79
|
+
input: 'input',
|
80
|
+
label: react_label_1.Label
|
81
|
+
},
|
82
|
+
root,
|
83
|
+
indicator,
|
84
|
+
input,
|
85
|
+
label
|
86
|
+
};
|
87
|
+
};
|
88
|
+
exports.useSwitch_unstable = useSwitch_unstable;
|
80
89
|
//# sourceMappingURL=useSwitch.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"names":["React","require","react_icons_1","react_label_1","react_tabster_1","react_utilities_1","useSwitch_unstable","props","ref","checked","defaultChecked","disabled","labelPosition","onChange","required","nativeProps","getPartitionedNativeProps","primarySlotTagName","excludedPropNames","id","useId","primary","root","resolveShorthand","defaultProps","useFocusWithin","indicator","children","createElement","CircleFilled","input","role","type","mergeCallbacks","ev","currentTarget","label","htmlFor","size","components","Label","exports"],"sources":["../../../../../../../../../packages/react-components/react-switch/src/components/Switch/useSwitch.tsx"],"sourcesContent":["import * as React from 'react';\nimport { CircleFilled } from '@fluentui/react-icons';\nimport { Label } from '@fluentui/react-label';\nimport { useFocusWithin } from '@fluentui/react-tabster';\nimport { getPartitionedNativeProps, mergeCallbacks, resolveShorthand, useId } 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: { ref: useFocusWithin<HTMLDivElement>(), ...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 = mergeCallbacks(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"],"mappings":";;;;;;AAAA,MAAAA,KAAA,gBAAAC,OAAA;AACA,MAAAC,aAAA,gBAAAD,OAAA;AACA,MAAAE,aAAA,gBAAAF,OAAA;AACA,MAAAG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