@fluentui/react-switch 9.7.1 → 9.7.3
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.md +29 -2
- package/dist/index.d.ts +1 -1
- package/lib/components/Switch/Switch.types.js +3 -1
- package/lib/components/Switch/Switch.types.js.map +1 -1
- package/lib/components/Switch/useSwitch.js +20 -7
- package/lib/components/Switch/useSwitch.js.map +1 -1
- package/lib/components/Switch/useSwitchStyles.styles.js +4 -0
- package/lib/components/Switch/useSwitchStyles.styles.js.map +1 -1
- package/lib/components/Switch/useSwitchStyles.styles.raw.js +4 -0
- package/lib/components/Switch/useSwitchStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/Switch/Switch.types.js +3 -3
- package/lib-commonjs/components/Switch/Switch.types.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitch.js +20 -7
- package/lib-commonjs/components/Switch/useSwitch.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitchStyles.styles.js +4 -0
- package/lib-commonjs/components/Switch/useSwitchStyles.styles.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitchStyles.styles.raw.js +4 -0
- package/lib-commonjs/components/Switch/useSwitchStyles.styles.raw.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-switch
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 26 May 2026 09:33:27 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.7.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.7.3)
|
|
8
|
+
|
|
9
|
+
Tue, 26 May 2026 09:33:27 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.7.2..@fluentui/react-switch_v9.7.3)
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- Bump @fluentui/react-field to v9.5.2 ([PR #36246](https://github.com/microsoft/fluentui/pull/36246) by beachball)
|
|
15
|
+
- Bump @fluentui/react-jsx-runtime to v9.4.3 ([PR #36246](https://github.com/microsoft/fluentui/pull/36246) by beachball)
|
|
16
|
+
- Bump @fluentui/react-label to v9.4.2 ([PR #36246](https://github.com/microsoft/fluentui/pull/36246) by beachball)
|
|
17
|
+
- Bump @fluentui/react-tabster to v9.26.15 ([PR #36246](https://github.com/microsoft/fluentui/pull/36246) by beachball)
|
|
18
|
+
- Bump @fluentui/react-utilities to v9.26.4 ([PR #36246](https://github.com/microsoft/fluentui/pull/36246) by beachball)
|
|
19
|
+
|
|
20
|
+
## [9.7.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.7.2)
|
|
21
|
+
|
|
22
|
+
Thu, 23 Apr 2026 14:21:07 GMT
|
|
23
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.7.1..@fluentui/react-switch_v9.7.2)
|
|
24
|
+
|
|
25
|
+
### Patches
|
|
26
|
+
|
|
27
|
+
- fix: update Switch component to conditionally render CircleFilled in indicator ([PR #35972](https://github.com/microsoft/fluentui/pull/35972) by dmytrokirpa@microsoft.com)
|
|
28
|
+
- Bump @fluentui/react-field to v9.5.1 ([PR #36035](https://github.com/microsoft/fluentui/pull/36035) by beachball)
|
|
29
|
+
- Bump @fluentui/react-jsx-runtime to v9.4.2 ([PR #36035](https://github.com/microsoft/fluentui/pull/36035) by beachball)
|
|
30
|
+
- Bump @fluentui/react-label to v9.4.1 ([PR #36035](https://github.com/microsoft/fluentui/pull/36035) by beachball)
|
|
31
|
+
- Bump @fluentui/react-tabster to v9.26.14 ([PR #36035](https://github.com/microsoft/fluentui/pull/36035) by beachball)
|
|
32
|
+
- Bump @fluentui/react-utilities to v9.26.3 ([PR #36035](https://github.com/microsoft/fluentui/pull/36035) by beachball)
|
|
33
|
+
|
|
7
34
|
## [9.7.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-switch_v9.7.1)
|
|
8
35
|
|
|
9
|
-
Wed, 01 Apr 2026 15:
|
|
36
|
+
Wed, 01 Apr 2026 15:52:43 GMT
|
|
10
37
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-switch_v9.7.0..@fluentui/react-switch_v9.7.1)
|
|
11
38
|
|
|
12
39
|
### Patches
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ComponentProps } from '@fluentui/react-utilities';
|
|
|
2
2
|
import type { ComponentState } from '@fluentui/react-utilities';
|
|
3
3
|
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
|
4
4
|
import type { JSXElement } from '@fluentui/react-utilities';
|
|
5
|
-
import { Label } from '@fluentui/react-label';
|
|
5
|
+
import type { Label } from '@fluentui/react-label';
|
|
6
6
|
import * as React_2 from 'react';
|
|
7
7
|
import type { Slot } from '@fluentui/react-utilities';
|
|
8
8
|
import type { SlotClassNames } from '@fluentui/react-utilities';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../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' | 'size'\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 * When set, allows the Switch to be focusable even when it has been disabled. This is used in scenarios where it is\n * important to keep a consistent tab order for screen reader and keyboard users.\n *\n * @default false\n */\n disabledFocusable?: 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 * The size of the Switch.\n *\n * @default 'medium'\n */\n size?: 'small' | 'medium';\n\n /**\n * Callback to be called when the checked state value changes.\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback\n onChange?: (ev: React.ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => void;\n};\n\n/**\n * Switch base props, excluding design-related props like size\n */\nexport type SwitchBaseProps = Omit<SwitchProps, 'size'>;\n\n/**\n * State used in rendering Switch\n */\nexport type SwitchState = ComponentState<SwitchSlots> &\n Required<Pick<SwitchProps, 'disabledFocusable' | 'labelPosition' | 'size'>>;\n\n/**\n * Switch base state, excluding design-related state like size\n */\nexport type SwitchBaseState = Omit<SwitchState, 'size'>;\n"],"names":[
|
|
1
|
+
{"version":3,"sources":["../src/components/Switch/Switch.types.ts"],"sourcesContent":["import type * as React from 'react';\nimport type { 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' | 'size'\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 * When set, allows the Switch to be focusable even when it has been disabled. This is used in scenarios where it is\n * important to keep a consistent tab order for screen reader and keyboard users.\n *\n * @default false\n */\n disabledFocusable?: 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 * The size of the Switch.\n *\n * @default 'medium'\n */\n size?: 'small' | 'medium';\n\n /**\n * Callback to be called when the checked state value changes.\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback\n onChange?: (ev: React.ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => void;\n};\n\n/**\n * Switch base props, excluding design-related props like size\n */\nexport type SwitchBaseProps = Omit<SwitchProps, 'size'>;\n\n/**\n * State used in rendering Switch\n */\nexport type SwitchState = ComponentState<SwitchSlots> &\n Required<Pick<SwitchProps, 'disabledFocusable' | 'labelPosition' | 'size'>>;\n\n/**\n * Switch base state, excluding design-related state like size\n */\nexport type SwitchBaseState = Omit<SwitchState, 'size'>;\n"],"names":[],"mappings":"AAoGA;;CAEC,GACD,WAAwD"}
|
|
@@ -14,11 +14,26 @@ import { getPartitionedNativeProps, mergeCallbacks, useId, slot } from '@fluentu
|
|
|
14
14
|
* @param props - props from this instance of Switch
|
|
15
15
|
* @param ref - reference to `<input>` element of Switch
|
|
16
16
|
*/ export const useSwitch_unstable = (props, ref)=>{
|
|
17
|
+
var _baseState_indicator;
|
|
17
18
|
const { size = 'medium', ...baseProps } = props;
|
|
18
19
|
const baseState = useSwitchBase_unstable(baseProps, ref);
|
|
20
|
+
var _children;
|
|
21
|
+
(_children = (_baseState_indicator = baseState.indicator).children) !== null && _children !== void 0 ? _children : _baseState_indicator.children = /*#__PURE__*/ React.createElement(CircleFilled, null);
|
|
19
22
|
return {
|
|
20
23
|
...baseState,
|
|
21
|
-
|
|
24
|
+
components: {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
26
|
+
...baseState.components,
|
|
27
|
+
label: Label
|
|
28
|
+
},
|
|
29
|
+
size,
|
|
30
|
+
label: slot.optional(props.label, {
|
|
31
|
+
defaultProps: {
|
|
32
|
+
size: 'medium',
|
|
33
|
+
...baseState.label
|
|
34
|
+
},
|
|
35
|
+
elementType: Label
|
|
36
|
+
})
|
|
22
37
|
};
|
|
23
38
|
};
|
|
24
39
|
/**
|
|
@@ -53,8 +68,7 @@ import { getPartitionedNativeProps, mergeCallbacks, useId, slot } from '@fluentu
|
|
|
53
68
|
});
|
|
54
69
|
const indicator = slot.always(props.indicator, {
|
|
55
70
|
defaultProps: {
|
|
56
|
-
'aria-hidden': true
|
|
57
|
-
children: /*#__PURE__*/ React.createElement(CircleFilled, null)
|
|
71
|
+
'aria-hidden': true
|
|
58
72
|
},
|
|
59
73
|
elementType: 'div'
|
|
60
74
|
});
|
|
@@ -91,10 +105,9 @@ import { getPartitionedNativeProps, mergeCallbacks, useId, slot } from '@fluentu
|
|
|
91
105
|
defaultProps: {
|
|
92
106
|
disabled: disabled || disabledFocusable,
|
|
93
107
|
htmlFor: id,
|
|
94
|
-
required
|
|
95
|
-
size: 'medium'
|
|
108
|
+
required
|
|
96
109
|
},
|
|
97
|
-
elementType:
|
|
110
|
+
elementType: 'label'
|
|
98
111
|
});
|
|
99
112
|
return {
|
|
100
113
|
disabledFocusable,
|
|
@@ -103,7 +116,7 @@ import { getPartitionedNativeProps, mergeCallbacks, useId, slot } from '@fluentu
|
|
|
103
116
|
root: 'div',
|
|
104
117
|
indicator: 'div',
|
|
105
118
|
input: 'input',
|
|
106
|
-
label:
|
|
119
|
+
label: 'label'
|
|
107
120
|
},
|
|
108
121
|
root,
|
|
109
122
|
indicator,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Switch/useSwitch.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { CircleFilled } from '@fluentui/react-icons';\nimport { Label } from '@fluentui/react-label';\nimport { useFocusWithin } from '@fluentui/react-tabster';\nimport { getPartitionedNativeProps, mergeCallbacks, useId, slot } from '@fluentui/react-utilities';\nimport type { SwitchProps, SwitchState, SwitchBaseProps, SwitchBaseState } 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 { size = 'medium', ...baseProps } = props;\n\n const baseState = useSwitchBase_unstable(baseProps, ref);\n\n return {\n ...baseState,\n size,\n };\n};\n\n/**\n * Base hook for Switch component, manages state and structure common to all variants of Switch\n *\n * @param props - base props from this instance of Switch\n * @param ref - reference to `<input>` element of Switch\n */\nexport const useSwitchBase_unstable = (props: SwitchBaseProps, ref?: React.Ref<HTMLInputElement>): SwitchBaseState => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });\n\n const {\n checked,\n defaultChecked,\n disabled,\n disabledFocusable = false,\n labelPosition = 'after',\n onChange,\n required,\n } = props;\n\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['checked', 'defaultChecked', 'onChange', 'disabledFocusable'],\n });\n\n const id = useId('switch-', nativeProps.primary.id);\n\n const root = slot.always(props.root, {\n defaultProps: { ref: useFocusWithin<HTMLDivElement>(), ...nativeProps.root },\n elementType: 'div',\n });\n const indicator = slot.always(props.indicator, {\n defaultProps: { 'aria-hidden': true
|
|
1
|
+
{"version":3,"sources":["../src/components/Switch/useSwitch.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { CircleFilled } from '@fluentui/react-icons';\nimport { Label } from '@fluentui/react-label';\nimport { useFocusWithin } from '@fluentui/react-tabster';\nimport { getPartitionedNativeProps, mergeCallbacks, useId, slot } from '@fluentui/react-utilities';\nimport type { SwitchProps, SwitchState, SwitchBaseProps, SwitchBaseState } 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 { size = 'medium', ...baseProps } = props;\n\n const baseState = useSwitchBase_unstable(baseProps, ref);\n\n baseState.indicator.children ??= <CircleFilled />;\n\n return {\n ...baseState,\n components: {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n ...baseState.components,\n label: Label,\n },\n size,\n label: slot.optional(props.label, {\n defaultProps: { size: 'medium', ...baseState.label },\n elementType: Label,\n }),\n };\n};\n\n/**\n * Base hook for Switch component, manages state and structure common to all variants of Switch\n *\n * @param props - base props from this instance of Switch\n * @param ref - reference to `<input>` element of Switch\n */\nexport const useSwitchBase_unstable = (props: SwitchBaseProps, ref?: React.Ref<HTMLInputElement>): SwitchBaseState => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });\n\n const {\n checked,\n defaultChecked,\n disabled,\n disabledFocusable = false,\n labelPosition = 'after',\n onChange,\n required,\n } = props;\n\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['checked', 'defaultChecked', 'onChange', 'disabledFocusable'],\n });\n\n const id = useId('switch-', nativeProps.primary.id);\n\n const root = slot.always(props.root, {\n defaultProps: { ref: useFocusWithin<HTMLDivElement>(), ...nativeProps.root },\n elementType: 'div',\n });\n const indicator = slot.always(props.indicator, {\n defaultProps: { 'aria-hidden': true },\n elementType: 'div',\n });\n const input = slot.always(props.input, {\n defaultProps: {\n checked,\n defaultChecked,\n id,\n ref,\n role: 'switch',\n type: 'checkbox',\n ...nativeProps.primary,\n disabled: disabled && !disabledFocusable,\n ...(disabledFocusable && { 'aria-disabled': true }),\n },\n elementType: 'input',\n });\n input.onChange = mergeCallbacks(input.onChange, ev => onChange?.(ev, { checked: ev.currentTarget.checked }));\n input.onClick = mergeCallbacks(input.onClick, ev => {\n if (disabledFocusable) {\n ev.preventDefault();\n }\n });\n input.onKeyDown = mergeCallbacks(input.onKeyDown, ev => {\n if (disabledFocusable && (ev.key === ' ' || ev.key === 'Enter')) {\n ev.preventDefault();\n }\n });\n const label = slot.optional(props.label, {\n defaultProps: { disabled: disabled || disabledFocusable, htmlFor: id, required },\n elementType: 'label',\n });\n return {\n disabledFocusable,\n labelPosition,\n components: { root: 'div', indicator: 'div', input: 'input', label: 'label' },\n\n root,\n indicator,\n input,\n label,\n };\n};\n"],"names":["React","useFieldControlProps_unstable","CircleFilled","Label","useFocusWithin","getPartitionedNativeProps","mergeCallbacks","useId","slot","useSwitch_unstable","props","ref","baseState","size","baseProps","useSwitchBase_unstable","indicator","children","components","label","optional","defaultProps","elementType","supportsLabelFor","supportsRequired","checked","defaultChecked","disabled","disabledFocusable","labelPosition","onChange","required","nativeProps","primarySlotTagName","excludedPropNames","id","primary","root","always","input","role","type","ev","currentTarget","onClick","preventDefault","onKeyDown","key","htmlFor"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,6BAA6B,QAAQ,wBAAwB;AACtE,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,KAAK,QAAQ,wBAAwB;AAC9C,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,yBAAyB,EAAEC,cAAc,EAAEC,KAAK,EAAEC,IAAI,QAAQ,4BAA4B;AAGnG;;;;;;;;CAQC,GACD,OAAO,MAAMC,qBAAqB,CAACC,OAAoBC;QAKrDC;IAJA,MAAM,EAAEC,OAAO,QAAQ,EAAE,GAAGC,WAAW,GAAGJ;IAE1C,MAAME,YAAYG,uBAAuBD,WAAWH;;IAEpDC,cAAAA,uBAAAA,UAAUI,SAAS,EAACC,yDAApBL,qBAAoBK,yBAAa,oBAACf;IAElC,OAAO;QACL,GAAGU,SAAS;QACZM,YAAY;YACV,4DAA4D;YAC5D,GAAGN,UAAUM,UAAU;YACvBC,OAAOhB;QACT;QACAU;QACAM,OAAOX,KAAKY,QAAQ,CAACV,MAAMS,KAAK,EAAE;YAChCE,cAAc;gBAAER,MAAM;gBAAU,GAAGD,UAAUO,KAAK;YAAC;YACnDG,aAAanB;QACf;IACF;AACF,EAAE;AAEF;;;;;CAKC,GACD,OAAO,MAAMY,yBAAyB,CAACL,OAAwBC;IAC7D,+CAA+C;IAC/CD,QAAQT,8BAA8BS,OAAO;QAAEa,kBAAkB;QAAMC,kBAAkB;IAAK;IAE9F,MAAM,EACJC,OAAO,EACPC,cAAc,EACdC,QAAQ,EACRC,oBAAoB,KAAK,EACzBC,gBAAgB,OAAO,EACvBC,QAAQ,EACRC,QA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YAAEM,UAAUA,YAAYC;YAAmBoB,SAASb;YAAIJ;QAAS;QAC/ET,aAAa;IACf;IACA,OAAO;QACLM;QACAC;QACAX,YAAY;YAAEmB,MAAM;YAAOrB,WAAW;YAAOuB,OAAO;YAASpB,OAAO;QAAQ;QAE5EkB;QACArB;QACAuB;QACApB;IACF;AACF,EAAE"}
|
|
@@ -127,10 +127,14 @@ export const useSwitchStyles_unstable = state => {
|
|
|
127
127
|
labelPosition,
|
|
128
128
|
size
|
|
129
129
|
} = state;
|
|
130
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
130
131
|
state.root.className = mergeClasses(switchClassNames.root, rootBaseClassName, labelPosition === 'above' && rootStyles.vertical, state.root.className);
|
|
132
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
131
133
|
state.indicator.className = mergeClasses(switchClassNames.indicator, indicatorBaseClassName, label && labelPosition === 'above' && indicatorStyles.labelAbove, size === 'small' && indicatorStyles.sizeSmall, state.indicator.className);
|
|
134
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
132
135
|
state.input.className = mergeClasses(switchClassNames.input, inputBaseClassName, label && inputStyles[labelPosition], size === 'small' && inputStyles.sizeSmall, state.input.className);
|
|
133
136
|
if (state.label) {
|
|
137
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
134
138
|
state.label.className = mergeClasses(switchClassNames.label, labelStyles.base, labelStyles[labelPosition], size === 'small' && labelStyles.sizeSmall, state.label.className);
|
|
135
139
|
}
|
|
136
140
|
return state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createFocusOutlineStyle","tokens","__resetStyles","__styles","mergeClasses","switchClassNames","root","indicator","input","label","switchClassName","spaceBetweenThumbAndTrack","trackHeightMedium","trackWidthMedium","thumbSizeMedium","trackHeightSmall","trackWidthSmall","thumbSizeSmall","useRootBaseClassName","r","s","useRootStyles","vertical","Beiy3e4","d","useIndicatorBaseClassName","useIndicatorStyles","labelAbove","B6of3ja","sizeSmall","Be2twd7","Bqenvij","a9b677","useInputBaseClassName","useInputStyles","before","j35jbq","Bhzewxz","after","oyh7mz","above","B5kzvoi","oedwrj","useLabelStyles","base","Bceei9c","jrapky","Byoj8tv","uwmqm3","z189sj","z8tnut","B0ocmuz","Bg96gwp","p","useSwitchStyles_unstable","state","rootBaseClassName","rootStyles","indicatorBaseClassName","indicatorStyles","inputBaseClassName","inputStyles","labelStyles","labelPosition","size","className"],"sources":["useSwitchStyles.styles.js"],"sourcesContent":["'use client';\nimport { createFocusOutlineStyle } from '@fluentui/react-tabster';\nimport { tokens } from '@fluentui/react-theme';\nimport { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';\nexport const switchClassNames = {\n root: 'fui-Switch',\n indicator: 'fui-Switch__indicator',\n input: 'fui-Switch__input',\n label: 'fui-Switch__label'\n};\n/**\n * @deprecated Use `switchClassNames.root` instead.\n */ export const switchClassName = switchClassNames.root;\n// Thumb and track sizes used by the component.\nconst spaceBetweenThumbAndTrack = 2;\n// Medium size dimensions\nconst trackHeightMedium = 20;\nconst trackWidthMedium = 40;\nconst thumbSizeMedium = trackHeightMedium - spaceBetweenThumbAndTrack;\n// Small size dimensions (from design mockup)\nconst trackHeightSmall = 16;\nconst trackWidthSmall = 32;\nconst thumbSizeSmall = trackHeightSmall - spaceBetweenThumbAndTrack;\nconst useRootBaseClassName = makeResetStyles({\n alignItems: 'flex-start',\n boxSizing: 'border-box',\n display: 'inline-flex',\n position: 'relative',\n ...createFocusOutlineStyle({\n style: {},\n selector: 'focus-within'\n })\n});\nconst useRootStyles = makeStyles({\n vertical: {\n flexDirection: 'column'\n }\n});\nconst useIndicatorBaseClassName = makeResetStyles({\n borderRadius: tokens.borderRadiusCircular,\n border: '1px solid',\n lineHeight: 0,\n boxSizing: 'border-box',\n fill: 'currentColor',\n flexShrink: 0,\n fontSize: `${thumbSizeMedium}px`,\n height: `${trackHeightMedium}px`,\n margin: tokens.spacingVerticalS + ' ' + tokens.spacingHorizontalS,\n pointerEvents: 'none',\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'background, border, color',\n width: `${trackWidthMedium}px`,\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms'\n },\n '@media (forced-colors: active)': {\n color: 'CanvasText',\n '> i': {\n forcedColorAdjust: 'none'\n }\n },\n '> *': {\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'transform',\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms'\n }\n }\n});\nconst useIndicatorStyles = makeStyles({\n labelAbove: {\n marginTop: 0\n },\n sizeSmall: {\n fontSize: `${thumbSizeSmall}px`,\n height: `${trackHeightSmall}px`,\n width: `${trackWidthSmall}px`\n }\n});\nconst useInputBaseClassName = makeResetStyles({\n boxSizing: 'border-box',\n cursor: 'pointer',\n height: '100%',\n margin: 0,\n opacity: 0,\n position: 'absolute',\n // Calculate the width of the hidden input by taking into account the size of the indicator + the padding around it.\n // This is done so that clicking on that \"empty space\" still toggles the switch.\n width: `calc(${trackWidthMedium}px + 2 * ${tokens.spacingHorizontalS})`,\n // Checked (both enabled and disabled)\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthMedium - thumbSizeMedium - spaceBetweenThumbAndTrack}px)`\n }\n }\n },\n // Disabled (both checked and unchecked)\n ':disabled, &[aria-disabled=\"true\"]': {\n cursor: 'default',\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralForegroundDisabled\n },\n [`& ~ .${switchClassNames.label}`]: {\n cursor: 'default',\n color: tokens.colorNeutralForegroundDisabled\n }\n },\n // Enabled and unchecked\n ':enabled:not(:checked):not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessible,\n borderColor: tokens.colorNeutralStrokeAccessible\n },\n [`& ~ .${switchClassNames.label}`]: {\n color: tokens.colorNeutralForeground1\n },\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessibleHover,\n borderColor: tokens.colorNeutralStrokeAccessibleHover\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessiblePressed,\n borderColor: tokens.colorNeutralStrokeAccessiblePressed\n }\n }\n },\n // Enabled and checked\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackground,\n color: tokens.colorNeutralForegroundInverted,\n borderColor: tokens.colorTransparentStroke\n },\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundHover,\n borderColor: tokens.colorTransparentStrokeInteractive\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundPressed,\n borderColor: tokens.colorTransparentStrokeInteractive\n }\n }\n },\n // Disabled and unchecked\n ':disabled:not(:checked), &[aria-disabled=\"true\"]:not(:checked)': {\n [`& ~ .${switchClassNames.indicator}`]: {\n borderColor: tokens.colorNeutralStrokeDisabled\n }\n },\n // Disabled and checked\n ':disabled:checked, &[aria-disabled=\"true\"]:checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorNeutralBackgroundDisabled,\n borderColor: tokens.colorTransparentStrokeDisabled\n }\n },\n '@media (forced-colors: active)': {\n ':disabled, &[aria-disabled=\"true\"]': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: 'GrayText',\n borderColor: 'GrayText'\n },\n [`& ~ .${switchClassNames.label}`]: {\n color: 'GrayText'\n }\n },\n ':hover': {\n color: 'CanvasText'\n },\n ':hover:active': {\n color: 'CanvasText'\n },\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n },\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n }\n }\n});\nconst useInputStyles = makeStyles({\n before: {\n right: 0,\n top: 0\n },\n after: {\n left: 0,\n top: 0\n },\n above: {\n bottom: 0,\n height: `calc(${trackHeightMedium}px + ${tokens.spacingVerticalS})`,\n width: '100%'\n },\n sizeSmall: {\n width: `calc(${trackWidthSmall}px + 2 * ${tokens.spacingHorizontalS})`,\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthSmall - thumbSizeSmall - spaceBetweenThumbAndTrack}px)`\n }\n }\n }\n }\n});\n// Can't use makeResetStyles here because Label is a component that may itself use makeResetStyles.\nconst useLabelStyles = makeStyles({\n base: {\n cursor: 'pointer',\n // Use a (negative) margin to account for the difference between the track's height and the label's line height.\n // This prevents the label from expanding the height of the switch, but preserves line height if the label wraps.\n marginBottom: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n marginTop: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalS}`\n },\n sizeSmall: {\n fontSize: tokens.fontSizeBase200,\n lineHeight: tokens.lineHeightBase200,\n marginBottom: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n marginTop: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`\n },\n above: {\n paddingTop: tokens.spacingVerticalXS,\n paddingBottom: tokens.spacingVerticalXS,\n width: '100%'\n },\n after: {\n paddingLeft: tokens.spacingHorizontalXS\n },\n before: {\n paddingRight: tokens.spacingHorizontalXS\n }\n});\n/**\n * Apply styling to the Switch slots based on the state\n */ export const useSwitchStyles_unstable = (state)=>{\n 'use no memo';\n const rootBaseClassName = useRootBaseClassName();\n const rootStyles = useRootStyles();\n const indicatorBaseClassName = useIndicatorBaseClassName();\n const indicatorStyles = useIndicatorStyles();\n const inputBaseClassName = useInputBaseClassName();\n const inputStyles = useInputStyles();\n const labelStyles = useLabelStyles();\n const { label, labelPosition, size } = state;\n state.root.className = mergeClasses(switchClassNames.root, rootBaseClassName, labelPosition === 'above' && rootStyles.vertical, state.root.className);\n state.indicator.className = mergeClasses(switchClassNames.indicator, indicatorBaseClassName, label && labelPosition === 'above' && indicatorStyles.labelAbove, size === 'small' && indicatorStyles.sizeSmall, state.indicator.className);\n state.input.className = mergeClasses(switchClassNames.input, inputBaseClassName, label && inputStyles[labelPosition], size === 'small' && inputStyles.sizeSmall, state.input.className);\n if (state.label) {\n state.label.className = mergeClasses(switchClassNames.label, labelStyles.base, labelStyles[labelPosition], size === 'small' && labelStyles.sizeSmall, state.label.className);\n }\n return state;\n};\n"],"mappings":"AAAA,YAAY;;AACZ,SAASA,uBAAuB,QAAQ,yBAAyB;AACjE,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SAAAC,aAAA,EAAAC,QAAA,EAAsCC,YAAY,QAAQ,gBAAgB;AAC1E,OAAO,MAAMC,gBAAgB,GAAG;EAC5BC,IAAI,EAAE,YAAY;EAClBC,SAAS,EAAE,uBAAuB;EAClCC,KAAK,EAAE,mBAAmB;EAC1BC,KAAK,EAAE;AACX,CAAC;AACD;AACA;AACA;AAAI,OAAO,MAAMC,eAAe,GAAGL,gBAAgB,CAACC,IAAI;AACxD;AACA,MAAMK,yBAAyB,GAAG,CAAC;AACnC;AACA,MAAMC,iBAAiB,GAAG,EAAE;AAC5B,MAAMC,gBAAgB,GAAG,EAAE;AAC3B,MAAMC,eAAe,GAAGF,iBAAiB,GAAGD,yBAAyB;AACrE;AACA,MAAMI,gBAAgB,GAAG,EAAE;AAC3B,MAAMC,eAAe,GAAG,EAAE;AAC1B,MAAMC,cAAc,GAAGF,gBAAgB,GAAGJ,yBAAyB;AACnE,MAAMO,o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8C,KAAK,CAAC9C,KAAK,CAACwD,SAAS,GAAG7D,YAAY,CAACC,gBAAgB,CAACI,KAAK,EAAEqD,WAAW,CAAClB,IAAI,EAAEkB,WAAW,CAACC,aAAa,CAAC,EAAEC,IAAI,KAAK,OAAO,IAAIF,WAAW,CAACjC,SAAS,EAAE0B,KAAK,CAAC9C,KAAK,CAACwD,SAAS,CAAC;EAChL;EACA,OAAOV,KAAK;AAChB,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["createFocusOutlineStyle","tokens","__resetStyles","__styles","mergeClasses","switchClassNames","root","indicator","input","label","switchClassName","spaceBetweenThumbAndTrack","trackHeightMedium","trackWidthMedium","thumbSizeMedium","trackHeightSmall","trackWidthSmall","thumbSizeSmall","useRootBaseClassName","r","s","useRootStyles","vertical","Beiy3e4","d","useIndicatorBaseClassName","useIndicatorStyles","labelAbove","B6of3ja","sizeSmall","Be2twd7","Bqenvij","a9b677","useInputBaseClassName","useInputStyles","before","j35jbq","Bhzewxz","after","oyh7mz","above","B5kzvoi","oedwrj","useLabelStyles","base","Bceei9c","jrapky","Byoj8tv","uwmqm3","z189sj","z8tnut","B0ocmuz","Bg96gwp","p","useSwitchStyles_unstable","state","rootBaseClassName","rootStyles","indicatorBaseClassName","indicatorStyles","inputBaseClassName","inputStyles","labelStyles","labelPosition","size","className"],"sources":["useSwitchStyles.styles.js"],"sourcesContent":["'use client';\nimport { createFocusOutlineStyle } from '@fluentui/react-tabster';\nimport { tokens } from '@fluentui/react-theme';\nimport { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';\nexport const switchClassNames = {\n root: 'fui-Switch',\n indicator: 'fui-Switch__indicator',\n input: 'fui-Switch__input',\n label: 'fui-Switch__label'\n};\n/**\n * @deprecated Use `switchClassNames.root` instead.\n */ export const switchClassName = switchClassNames.root;\n// Thumb and track sizes used by the component.\nconst spaceBetweenThumbAndTrack = 2;\n// Medium size dimensions\nconst trackHeightMedium = 20;\nconst trackWidthMedium = 40;\nconst thumbSizeMedium = trackHeightMedium - spaceBetweenThumbAndTrack;\n// Small size dimensions (from design mockup)\nconst trackHeightSmall = 16;\nconst trackWidthSmall = 32;\nconst thumbSizeSmall = trackHeightSmall - spaceBetweenThumbAndTrack;\nconst useRootBaseClassName = makeResetStyles({\n alignItems: 'flex-start',\n boxSizing: 'border-box',\n display: 'inline-flex',\n position: 'relative',\n ...createFocusOutlineStyle({\n style: {},\n selector: 'focus-within'\n })\n});\nconst useRootStyles = makeStyles({\n vertical: {\n flexDirection: 'column'\n }\n});\nconst useIndicatorBaseClassName = makeResetStyles({\n borderRadius: tokens.borderRadiusCircular,\n border: '1px solid',\n lineHeight: 0,\n boxSizing: 'border-box',\n fill: 'currentColor',\n flexShrink: 0,\n fontSize: `${thumbSizeMedium}px`,\n height: `${trackHeightMedium}px`,\n margin: tokens.spacingVerticalS + ' ' + tokens.spacingHorizontalS,\n pointerEvents: 'none',\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'background, border, color',\n width: `${trackWidthMedium}px`,\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms'\n },\n '@media (forced-colors: active)': {\n color: 'CanvasText',\n '> i': {\n forcedColorAdjust: 'none'\n }\n },\n '> *': {\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'transform',\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms'\n }\n }\n});\nconst useIndicatorStyles = makeStyles({\n labelAbove: {\n marginTop: 0\n },\n sizeSmall: {\n fontSize: `${thumbSizeSmall}px`,\n height: `${trackHeightSmall}px`,\n width: `${trackWidthSmall}px`\n }\n});\nconst useInputBaseClassName = makeResetStyles({\n boxSizing: 'border-box',\n cursor: 'pointer',\n height: '100%',\n margin: 0,\n opacity: 0,\n position: 'absolute',\n // Calculate the width of the hidden input by taking into account the size of the indicator + the padding around it.\n // This is done so that clicking on that \"empty space\" still toggles the switch.\n width: `calc(${trackWidthMedium}px + 2 * ${tokens.spacingHorizontalS})`,\n // Checked (both enabled and disabled)\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthMedium - thumbSizeMedium - spaceBetweenThumbAndTrack}px)`\n }\n }\n },\n // Disabled (both checked and unchecked)\n ':disabled, &[aria-disabled=\"true\"]': {\n cursor: 'default',\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralForegroundDisabled\n },\n [`& ~ .${switchClassNames.label}`]: {\n cursor: 'default',\n color: tokens.colorNeutralForegroundDisabled\n }\n },\n // Enabled and unchecked\n ':enabled:not(:checked):not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessible,\n borderColor: tokens.colorNeutralStrokeAccessible\n },\n [`& ~ .${switchClassNames.label}`]: {\n color: tokens.colorNeutralForeground1\n },\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessibleHover,\n borderColor: tokens.colorNeutralStrokeAccessibleHover\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessiblePressed,\n borderColor: tokens.colorNeutralStrokeAccessiblePressed\n }\n }\n },\n // Enabled and checked\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackground,\n color: tokens.colorNeutralForegroundInverted,\n borderColor: tokens.colorTransparentStroke\n },\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundHover,\n borderColor: tokens.colorTransparentStrokeInteractive\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundPressed,\n borderColor: tokens.colorTransparentStrokeInteractive\n }\n }\n },\n // Disabled and unchecked\n ':disabled:not(:checked), &[aria-disabled=\"true\"]:not(:checked)': {\n [`& ~ .${switchClassNames.indicator}`]: {\n borderColor: tokens.colorNeutralStrokeDisabled\n }\n },\n // Disabled and checked\n ':disabled:checked, &[aria-disabled=\"true\"]:checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorNeutralBackgroundDisabled,\n borderColor: tokens.colorTransparentStrokeDisabled\n }\n },\n '@media (forced-colors: active)': {\n ':disabled, &[aria-disabled=\"true\"]': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: 'GrayText',\n borderColor: 'GrayText'\n },\n [`& ~ .${switchClassNames.label}`]: {\n color: 'GrayText'\n }\n },\n ':hover': {\n color: 'CanvasText'\n },\n ':hover:active': {\n color: 'CanvasText'\n },\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n },\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n }\n }\n});\nconst useInputStyles = makeStyles({\n before: {\n right: 0,\n top: 0\n },\n after: {\n left: 0,\n top: 0\n },\n above: {\n bottom: 0,\n height: `calc(${trackHeightMedium}px + ${tokens.spacingVerticalS})`,\n width: '100%'\n },\n sizeSmall: {\n width: `calc(${trackWidthSmall}px + 2 * ${tokens.spacingHorizontalS})`,\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthSmall - thumbSizeSmall - spaceBetweenThumbAndTrack}px)`\n }\n }\n }\n }\n});\n// Can't use makeResetStyles here because Label is a component that may itself use makeResetStyles.\nconst useLabelStyles = makeStyles({\n base: {\n cursor: 'pointer',\n // Use a (negative) margin to account for the difference between the track's height and the label's line height.\n // This prevents the label from expanding the height of the switch, but preserves line height if the label wraps.\n marginBottom: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n marginTop: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalS}`\n },\n sizeSmall: {\n fontSize: tokens.fontSizeBase200,\n lineHeight: tokens.lineHeightBase200,\n marginBottom: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n marginTop: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`\n },\n above: {\n paddingTop: tokens.spacingVerticalXS,\n paddingBottom: tokens.spacingVerticalXS,\n width: '100%'\n },\n after: {\n paddingLeft: tokens.spacingHorizontalXS\n },\n before: {\n paddingRight: tokens.spacingHorizontalXS\n }\n});\n/**\n * Apply styling to the Switch slots based on the state\n */ export const useSwitchStyles_unstable = (state)=>{\n 'use no memo';\n const rootBaseClassName = useRootBaseClassName();\n const rootStyles = useRootStyles();\n const indicatorBaseClassName = useIndicatorBaseClassName();\n const indicatorStyles = useIndicatorStyles();\n const inputBaseClassName = useInputBaseClassName();\n const inputStyles = useInputStyles();\n const labelStyles = useLabelStyles();\n const { label, labelPosition, size } = state;\n // eslint-disable-next-line react-hooks/immutability\n state.root.className = mergeClasses(switchClassNames.root, rootBaseClassName, labelPosition === 'above' && rootStyles.vertical, state.root.className);\n // eslint-disable-next-line react-hooks/immutability\n state.indicator.className = mergeClasses(switchClassNames.indicator, indicatorBaseClassName, label && labelPosition === 'above' && indicatorStyles.labelAbove, size === 'small' && indicatorStyles.sizeSmall, state.indicator.className);\n // eslint-disable-next-line react-hooks/immutability\n state.input.className = mergeClasses(switchClassNames.input, inputBaseClassName, label && inputStyles[labelPosition], size === 'small' && inputStyles.sizeSmall, state.input.className);\n if (state.label) {\n // eslint-disable-next-line react-hooks/immutability\n state.label.className = mergeClasses(switchClassNames.label, labelStyles.base, labelStyles[labelPosition], size === 'small' && labelStyles.sizeSmall, state.label.className);\n }\n return state;\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,IAAI,EAAEkD,iBAAiB,EAAEO,aAAa,KAAK,OAAO,IAAIN,UAAU,CAACnC,QAAQ,EAAEiC,KAAK,CAACjD,IAAI,CAAC2D,SAAS,CAAC;EACrJ;EACAV,KAAK,CAAChD,SAAS,CAAC0D,SAAS,GAAG7D,YAAY,CAACC,gBAAgB,CAACE,SAAS,EAAEmD,sBAAsB,EAAEjD,KAAK,IAAIsD,aAAa,KAAK,OAAO,IAAIJ,eAAe,CAAChC,UAAU,EAAEqC,IAAI,KAAK,OAAO,IAAIL,eAAe,CAAC9B,SAAS,EAAE0B,KAAK,CAAChD,SAAS,CAAC0D,SAAS,CAAC;EACxO;EACAV,KAAK,CAAC/C,KAAK,CAACyD,SAAS,GAAG7D,YAAY,CAACC,gBAAgB,CAACG,KAAK,EAAEoD,kBAAkB,EAAEnD,KAAK,IAAIoD,WAAW,CAACE,aAAa,CAAC,EAAEC,IAAI,KAAK,OAAO,IAAIH,WAAW,CAAChC,SAAS,EAAE0B,KAAK,CAAC/C,KAAK,CAACyD,SAAS,CAAC;EACvL,IAAIV,KAAK,CAAC9C,KAAK,EAAE;IACb;IACA8C,KAAK,CAAC9C,KAAK,CAACwD,SAAS,GAAG7D,YAAY,CAACC,gBAAgB,CAACI,KAAK,EAAEqD,WAAW,CAAClB,IAAI,EAAEkB,WAAW,CAACC,aAAa,CAAC,EAAEC,IAAI,KAAK,OAAO,IAAIF,WAAW,CAACjC,SAAS,EAAE0B,KAAK,CAAC9C,KAAK,CAACwD,SAAS,CAAC;EAChL;EACA,OAAOV,KAAK;AAChB,CAAC","ignoreList":[]}
|
|
@@ -264,10 +264,14 @@ const useLabelStyles = makeStyles({
|
|
|
264
264
|
const inputStyles = useInputStyles();
|
|
265
265
|
const labelStyles = useLabelStyles();
|
|
266
266
|
const { label, labelPosition, size } = state;
|
|
267
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
267
268
|
state.root.className = mergeClasses(switchClassNames.root, rootBaseClassName, labelPosition === 'above' && rootStyles.vertical, state.root.className);
|
|
269
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
268
270
|
state.indicator.className = mergeClasses(switchClassNames.indicator, indicatorBaseClassName, label && labelPosition === 'above' && indicatorStyles.labelAbove, size === 'small' && indicatorStyles.sizeSmall, state.indicator.className);
|
|
271
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
269
272
|
state.input.className = mergeClasses(switchClassNames.input, inputBaseClassName, label && inputStyles[labelPosition], size === 'small' && inputStyles.sizeSmall, state.input.className);
|
|
270
273
|
if (state.label) {
|
|
274
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
271
275
|
state.label.className = mergeClasses(switchClassNames.label, labelStyles.base, labelStyles[labelPosition], size === 'small' && labelStyles.sizeSmall, state.label.className);
|
|
272
276
|
}
|
|
273
277
|
return state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Switch/useSwitchStyles.styles.ts"],"sourcesContent":["'use client';\n\nimport { createFocusOutlineStyle } from '@fluentui/react-tabster';\nimport { tokens } from '@fluentui/react-theme';\nimport { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport type { SwitchSlots, SwitchState } from './Switch.types';\n\nexport const switchClassNames: SlotClassNames<SwitchSlots> = {\n root: 'fui-Switch',\n indicator: 'fui-Switch__indicator',\n input: 'fui-Switch__input',\n label: 'fui-Switch__label',\n};\n\n/**\n * @deprecated Use `switchClassNames.root` instead.\n */\nexport const switchClassName = switchClassNames.root;\n\n// Thumb and track sizes used by the component.\nconst spaceBetweenThumbAndTrack = 2;\n// Medium size dimensions\nconst trackHeightMedium = 20;\nconst trackWidthMedium = 40;\nconst thumbSizeMedium = trackHeightMedium - spaceBetweenThumbAndTrack;\n// Small size dimensions (from design mockup)\nconst trackHeightSmall = 16;\nconst trackWidthSmall = 32;\nconst thumbSizeSmall = trackHeightSmall - spaceBetweenThumbAndTrack;\n\nconst useRootBaseClassName = makeResetStyles({\n alignItems: 'flex-start',\n boxSizing: 'border-box',\n display: 'inline-flex',\n position: 'relative',\n\n ...createFocusOutlineStyle({ style: {}, selector: 'focus-within' }),\n});\n\nconst useRootStyles = makeStyles({\n vertical: {\n flexDirection: 'column',\n },\n});\n\nconst useIndicatorBaseClassName = makeResetStyles({\n borderRadius: tokens.borderRadiusCircular,\n border: '1px solid',\n lineHeight: 0,\n boxSizing: 'border-box',\n fill: 'currentColor',\n flexShrink: 0,\n fontSize: `${thumbSizeMedium}px`,\n height: `${trackHeightMedium}px`,\n margin: tokens.spacingVerticalS + ' ' + tokens.spacingHorizontalS,\n pointerEvents: 'none',\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'background, border, color',\n width: `${trackWidthMedium}px`,\n\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms',\n },\n\n '@media (forced-colors: active)': {\n color: 'CanvasText',\n '> i': {\n forcedColorAdjust: 'none',\n },\n },\n\n '> *': {\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'transform',\n\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms',\n },\n },\n});\n\nconst useIndicatorStyles = makeStyles({\n labelAbove: {\n marginTop: 0,\n },\n sizeSmall: {\n fontSize: `${thumbSizeSmall}px`,\n height: `${trackHeightSmall}px`,\n width: `${trackWidthSmall}px`,\n },\n});\n\nconst useInputBaseClassName = makeResetStyles({\n boxSizing: 'border-box',\n cursor: 'pointer',\n height: '100%',\n margin: 0,\n opacity: 0,\n position: 'absolute',\n\n // Calculate the width of the hidden input by taking into account the size of the indicator + the padding around it.\n // This is done so that clicking on that \"empty space\" still toggles the switch.\n width: `calc(${trackWidthMedium}px + 2 * ${tokens.spacingHorizontalS})`,\n\n // Checked (both enabled and disabled)\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthMedium - thumbSizeMedium - spaceBetweenThumbAndTrack}px)`,\n },\n },\n },\n\n // Disabled (both checked and unchecked)\n ':disabled, &[aria-disabled=\"true\"]': {\n cursor: 'default',\n\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralForegroundDisabled,\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n cursor: 'default',\n color: tokens.colorNeutralForegroundDisabled,\n },\n },\n\n // Enabled and unchecked\n ':enabled:not(:checked):not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessible,\n borderColor: tokens.colorNeutralStrokeAccessible,\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n color: tokens.colorNeutralForeground1,\n },\n\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessibleHover,\n borderColor: tokens.colorNeutralStrokeAccessibleHover,\n },\n },\n\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessiblePressed,\n borderColor: tokens.colorNeutralStrokeAccessiblePressed,\n },\n },\n },\n\n // Enabled and checked\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackground,\n color: tokens.colorNeutralForegroundInverted,\n borderColor: tokens.colorTransparentStroke,\n },\n\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundHover,\n borderColor: tokens.colorTransparentStrokeInteractive,\n },\n },\n\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundPressed,\n borderColor: tokens.colorTransparentStrokeInteractive,\n },\n },\n },\n\n // Disabled and unchecked\n ':disabled:not(:checked), &[aria-disabled=\"true\"]:not(:checked)': {\n [`& ~ .${switchClassNames.indicator}`]: {\n borderColor: tokens.colorNeutralStrokeDisabled,\n },\n },\n\n // Disabled and checked\n ':disabled:checked, &[aria-disabled=\"true\"]:checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorNeutralBackgroundDisabled,\n borderColor: tokens.colorTransparentStrokeDisabled,\n },\n },\n\n '@media (forced-colors: active)': {\n ':disabled, &[aria-disabled=\"true\"]': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: 'GrayText',\n borderColor: 'GrayText',\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n color: 'GrayText',\n },\n },\n ':hover': {\n color: 'CanvasText',\n },\n ':hover:active': {\n color: 'CanvasText',\n },\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n },\n});\n\nconst useInputStyles = makeStyles({\n before: {\n right: 0,\n top: 0,\n },\n after: {\n left: 0,\n top: 0,\n },\n above: {\n bottom: 0,\n height: `calc(${trackHeightMedium}px + ${tokens.spacingVerticalS})`,\n width: '100%',\n },\n sizeSmall: {\n width: `calc(${trackWidthSmall}px + 2 * ${tokens.spacingHorizontalS})`,\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthSmall - thumbSizeSmall - spaceBetweenThumbAndTrack}px)`,\n },\n },\n },\n },\n});\n\n// Can't use makeResetStyles here because Label is a component that may itself use makeResetStyles.\nconst useLabelStyles = makeStyles({\n base: {\n cursor: 'pointer',\n\n // Use a (negative) margin to account for the difference between the track's height and the label's line height.\n // This prevents the label from expanding the height of the switch, but preserves line height if the label wraps.\n marginBottom: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n marginTop: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalS}`,\n },\n sizeSmall: {\n fontSize: tokens.fontSizeBase200,\n lineHeight: tokens.lineHeightBase200,\n marginBottom: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n marginTop: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n },\n above: {\n paddingTop: tokens.spacingVerticalXS,\n paddingBottom: tokens.spacingVerticalXS,\n width: '100%',\n },\n after: {\n paddingLeft: tokens.spacingHorizontalXS,\n },\n before: {\n paddingRight: tokens.spacingHorizontalXS,\n },\n});\n\n/**\n * Apply styling to the Switch slots based on the state\n */\nexport const useSwitchStyles_unstable = (state: SwitchState): SwitchState => {\n 'use no memo';\n\n const rootBaseClassName = useRootBaseClassName();\n const rootStyles = useRootStyles();\n const indicatorBaseClassName = useIndicatorBaseClassName();\n const indicatorStyles = useIndicatorStyles();\n const inputBaseClassName = useInputBaseClassName();\n const inputStyles = useInputStyles();\n const labelStyles = useLabelStyles();\n\n const { label, labelPosition, size } = state;\n\n state.root.className = mergeClasses(\n switchClassNames.root,\n rootBaseClassName,\n labelPosition === 'above' && rootStyles.vertical,\n state.root.className,\n );\n\n state.indicator.className = mergeClasses(\n switchClassNames.indicator,\n indicatorBaseClassName,\n label && labelPosition === 'above' && indicatorStyles.labelAbove,\n size === 'small' && indicatorStyles.sizeSmall,\n state.indicator.className,\n );\n\n state.input.className = mergeClasses(\n switchClassNames.input,\n inputBaseClassName,\n label && inputStyles[labelPosition],\n size === 'small' && inputStyles.sizeSmall,\n state.input.className,\n );\n\n if (state.label) {\n state.label.className = mergeClasses(\n switchClassNames.label,\n labelStyles.base,\n labelStyles[labelPosition],\n size === 'small' && labelStyles.sizeSmall,\n state.label.className,\n );\n }\n\n return state;\n};\n"],"names":["createFocusOutlineStyle","tokens","makeResetStyles","makeStyles","mergeClasses","switchClassNames","root","indicator","input","label","switchClassName","spaceBetweenThumbAndTrack","trackHeightMedium","trackWidthMedium","thumbSizeMedium","trackHeightSmall","trackWidthSmall","thumbSizeSmall","useRootBaseClassName","alignItems","boxSizing","display","position","style","selector","useRootStyles","vertical","flexDirection","useIndicatorBaseClassName","borderRadius","borderRadiusCircular","border","lineHeight","fill","flexShrink","fontSize","height","margin","spacingVerticalS","spacingHorizontalS","pointerEvents","transitionDuration","durationNormal","transitionTimingFunction","curveEasyEase","transitionProperty","width","color","forcedColorAdjust","useIndicatorStyles","labelAbove","marginTop","sizeSmall","useInputBaseClassName","cursor","opacity","transform","colorNeutralForegroundDisabled","colorNeutralStrokeAccessible","borderColor","colorNeutralForeground1","colorNeutralStrokeAccessibleHover","colorNeutralStrokeAccessiblePressed","backgroundColor","colorCompoundBrandBackground","colorNeutralForegroundInverted","colorTransparentStroke","colorCompoundBrandBackgroundHover","colorTransparentStrokeInteractive","colorCompoundBrandBackgroundPressed","colorNeutralStrokeDisabled","colorNeutralBackgroundDisabled","colorTransparentStrokeDisabled","useInputStyles","before","right","top","after","left","above","bottom","useLabelStyles","base","marginBottom","lineHeightBase300","padding","fontSizeBase200","lineHeightBase200","paddingTop","spacingVerticalXS","paddingBottom","paddingLeft","spacingHorizontalXS","paddingRight","useSwitchStyles_unstable","state","rootBaseClassName","rootStyles","indicatorBaseClassName","indicatorStyles","inputBaseClassName","inputStyles","labelStyles","labelPosition","size","className"],"mappings":"AAAA;AAEA,SAASA,uBAAuB,QAAQ,0BAA0B;AAClE,SAASC,MAAM,QAAQ,wBAAwB;AAC/C,SAASC,eAAe,EAAEC,UAAU,EAAEC,YAAY,QAAQ,iBAAiB;AAI3E,OAAO,MAAMC,mBAAgD;IAC3DC,MAAM;IACNC,WAAW;IACXC,OAAO;IACPC,OAAO;AACT,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMC,kBAAkBL,iBAAiBC,IAAI,CAAC;AAErD,+CAA+C;AAC/C,MAAMK,4BAA4B;AAClC,yBAAyB;AACzB,MAAMC,oBAAoB;AAC1B,M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,oBACA3F,SAAS4F,WAAW,CAACE,cAAc,EACnCC,SAAS,WAAWH,YAAYjD,SAAS,EACzC2C,MAAMvF,KAAK,CAACiG,SAAS;IAGvB,IAAIV,MAAMtF,KAAK,EAAE;QACfsF,MAAMtF,KAAK,CAACgG,SAAS,GAAGrG,aACtBC,iBAAiBI,KAAK,EACtB6F,YAAYpB,IAAI,EAChBoB,WAAW,CAACC,cAAc,EAC1BC,SAAS,WAAWF,YAAYlD,SAAS,EACzC2C,MAAMtF,KAAK,CAACgG,SAAS;IAEzB;IAEA,OAAOV;AACT,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../src/components/Switch/useSwitchStyles.styles.ts"],"sourcesContent":["'use client';\n\nimport { createFocusOutlineStyle } from '@fluentui/react-tabster';\nimport { tokens } from '@fluentui/react-theme';\nimport { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport type { SwitchSlots, SwitchState } from './Switch.types';\n\nexport const switchClassNames: SlotClassNames<SwitchSlots> = {\n root: 'fui-Switch',\n indicator: 'fui-Switch__indicator',\n input: 'fui-Switch__input',\n label: 'fui-Switch__label',\n};\n\n/**\n * @deprecated Use `switchClassNames.root` instead.\n */\nexport const switchClassName = switchClassNames.root;\n\n// Thumb and track sizes used by the component.\nconst spaceBetweenThumbAndTrack = 2;\n// Medium size dimensions\nconst trackHeightMedium = 20;\nconst trackWidthMedium = 40;\nconst thumbSizeMedium = trackHeightMedium - spaceBetweenThumbAndTrack;\n// Small size dimensions (from design mockup)\nconst trackHeightSmall = 16;\nconst trackWidthSmall = 32;\nconst thumbSizeSmall = trackHeightSmall - spaceBetweenThumbAndTrack;\n\nconst useRootBaseClassName = makeResetStyles({\n alignItems: 'flex-start',\n boxSizing: 'border-box',\n display: 'inline-flex',\n position: 'relative',\n\n ...createFocusOutlineStyle({ style: {}, selector: 'focus-within' }),\n});\n\nconst useRootStyles = makeStyles({\n vertical: {\n flexDirection: 'column',\n },\n});\n\nconst useIndicatorBaseClassName = makeResetStyles({\n borderRadius: tokens.borderRadiusCircular,\n border: '1px solid',\n lineHeight: 0,\n boxSizing: 'border-box',\n fill: 'currentColor',\n flexShrink: 0,\n fontSize: `${thumbSizeMedium}px`,\n height: `${trackHeightMedium}px`,\n margin: tokens.spacingVerticalS + ' ' + tokens.spacingHorizontalS,\n pointerEvents: 'none',\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'background, border, color',\n width: `${trackWidthMedium}px`,\n\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms',\n },\n\n '@media (forced-colors: active)': {\n color: 'CanvasText',\n '> i': {\n forcedColorAdjust: 'none',\n },\n },\n\n '> *': {\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'transform',\n\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms',\n },\n },\n});\n\nconst useIndicatorStyles = makeStyles({\n labelAbove: {\n marginTop: 0,\n },\n sizeSmall: {\n fontSize: `${thumbSizeSmall}px`,\n height: `${trackHeightSmall}px`,\n width: `${trackWidthSmall}px`,\n },\n});\n\nconst useInputBaseClassName = makeResetStyles({\n boxSizing: 'border-box',\n cursor: 'pointer',\n height: '100%',\n margin: 0,\n opacity: 0,\n position: 'absolute',\n\n // Calculate the width of the hidden input by taking into account the size of the indicator + the padding around it.\n // This is done so that clicking on that \"empty space\" still toggles the switch.\n width: `calc(${trackWidthMedium}px + 2 * ${tokens.spacingHorizontalS})`,\n\n // Checked (both enabled and disabled)\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthMedium - thumbSizeMedium - spaceBetweenThumbAndTrack}px)`,\n },\n },\n },\n\n // Disabled (both checked and unchecked)\n ':disabled, &[aria-disabled=\"true\"]': {\n cursor: 'default',\n\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralForegroundDisabled,\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n cursor: 'default',\n color: tokens.colorNeutralForegroundDisabled,\n },\n },\n\n // Enabled and unchecked\n ':enabled:not(:checked):not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessible,\n borderColor: tokens.colorNeutralStrokeAccessible,\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n color: tokens.colorNeutralForeground1,\n },\n\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessibleHover,\n borderColor: tokens.colorNeutralStrokeAccessibleHover,\n },\n },\n\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessiblePressed,\n borderColor: tokens.colorNeutralStrokeAccessiblePressed,\n },\n },\n },\n\n // Enabled and checked\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackground,\n color: tokens.colorNeutralForegroundInverted,\n borderColor: tokens.colorTransparentStroke,\n },\n\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundHover,\n borderColor: tokens.colorTransparentStrokeInteractive,\n },\n },\n\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundPressed,\n borderColor: tokens.colorTransparentStrokeInteractive,\n },\n },\n },\n\n // Disabled and unchecked\n ':disabled:not(:checked), &[aria-disabled=\"true\"]:not(:checked)': {\n [`& ~ .${switchClassNames.indicator}`]: {\n borderColor: tokens.colorNeutralStrokeDisabled,\n },\n },\n\n // Disabled and checked\n ':disabled:checked, &[aria-disabled=\"true\"]:checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorNeutralBackgroundDisabled,\n borderColor: tokens.colorTransparentStrokeDisabled,\n },\n },\n\n '@media (forced-colors: active)': {\n ':disabled, &[aria-disabled=\"true\"]': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: 'GrayText',\n borderColor: 'GrayText',\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n color: 'GrayText',\n },\n },\n ':hover': {\n color: 'CanvasText',\n },\n ':hover:active': {\n color: 'CanvasText',\n },\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n },\n});\n\nconst useInputStyles = makeStyles({\n before: {\n right: 0,\n top: 0,\n },\n after: {\n left: 0,\n top: 0,\n },\n above: {\n bottom: 0,\n height: `calc(${trackHeightMedium}px + ${tokens.spacingVerticalS})`,\n width: '100%',\n },\n sizeSmall: {\n width: `calc(${trackWidthSmall}px + 2 * ${tokens.spacingHorizontalS})`,\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthSmall - thumbSizeSmall - spaceBetweenThumbAndTrack}px)`,\n },\n },\n },\n },\n});\n\n// Can't use makeResetStyles here because Label is a component that may itself use makeResetStyles.\nconst useLabelStyles = makeStyles({\n base: {\n cursor: 'pointer',\n\n // Use a (negative) margin to account for the difference between the track's height and the label's line height.\n // This prevents the label from expanding the height of the switch, but preserves line height if the label wraps.\n marginBottom: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n marginTop: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalS}`,\n },\n sizeSmall: {\n fontSize: tokens.fontSizeBase200,\n lineHeight: tokens.lineHeightBase200,\n marginBottom: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n marginTop: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n },\n above: {\n paddingTop: tokens.spacingVerticalXS,\n paddingBottom: tokens.spacingVerticalXS,\n width: '100%',\n },\n after: {\n paddingLeft: tokens.spacingHorizontalXS,\n },\n before: {\n paddingRight: tokens.spacingHorizontalXS,\n },\n});\n\n/**\n * Apply styling to the Switch slots based on the state\n */\nexport const useSwitchStyles_unstable = (state: SwitchState): SwitchState => {\n 'use no memo';\n\n const rootBaseClassName = useRootBaseClassName();\n const rootStyles = useRootStyles();\n const indicatorBaseClassName = useIndicatorBaseClassName();\n const indicatorStyles = useIndicatorStyles();\n const inputBaseClassName = useInputBaseClassName();\n const inputStyles = useInputStyles();\n const labelStyles = useLabelStyles();\n\n const { label, labelPosition, size } = state;\n\n // eslint-disable-next-line react-hooks/immutability\n state.root.className = mergeClasses(\n switchClassNames.root,\n rootBaseClassName,\n labelPosition === 'above' && rootStyles.vertical,\n state.root.className,\n );\n\n // eslint-disable-next-line react-hooks/immutability\n state.indicator.className = mergeClasses(\n switchClassNames.indicator,\n indicatorBaseClassName,\n label && labelPosition === 'above' && indicatorStyles.labelAbove,\n size === 'small' && indicatorStyles.sizeSmall,\n state.indicator.className,\n );\n\n // eslint-disable-next-line react-hooks/immutability\n state.input.className = mergeClasses(\n switchClassNames.input,\n inputBaseClassName,\n label && inputStyles[labelPosition],\n size === 'small' && inputStyles.sizeSmall,\n state.input.className,\n );\n\n if (state.label) {\n // eslint-disable-next-line react-hooks/immutability\n state.label.className = mergeClasses(\n switchClassNames.label,\n labelStyles.base,\n labelStyles[labelPosition],\n size === 'small' && labelStyles.sizeSmall,\n state.label.className,\n );\n }\n\n return state;\n};\n"],"names":["createFocusOutlineStyle","tokens","makeResetStyles","makeStyles","mergeClasses","switchClassNames","root","indicator","input","label","switchClassName","spaceBetweenThumbAndTrack","trackHeightMedium","trackWidthMedium","thumbSizeMedium","trackHeightSmall","trackWidthSmall","thumbSizeSmall","useRootBaseClassName","alignItems","boxSizing","display","position","style","selector","useRootStyles","vertical","flexDirection","useIndicatorBaseClassName","borderRadius","borderRadiusCircular","border","lineHeight","fill","flexShrink","fontSize","height","margin","spacingVerticalS","spacingHorizontalS","pointerEvents","transitionDuration","durationNormal","transitionTimingFunction","curveEasyEase","transitionProperty","width","color","forcedColorAdjust","useIndicatorStyles","labelAbove","marginTop","sizeSmall","useInputBaseClassName","cursor","opacity","transform","colorNeutralForegroundDisabled","colorNeutralStrokeAccessible","borderColor","colorNeutralForeground1","colorNeutralStrokeAccessibleHover","colorNeutralStrokeAccessiblePressed","backgroundColor","colorCompoundBrandBackground","colorNeutralForegroundInverted","colorTransparentStroke","colorCompoundBrandBackgroundHover","colorTransparentStrokeInteractive","colorCompoundBrandBackgroundPressed","colorNeutralStrokeDisabled","colorNeutralBackgroundDisabled","colorTransparentStrokeDisabled","useInputStyles","before","right","top","after","left","above","bottom","useLabelStyles","base","marginBottom","lineHeightBase300","padding","fontSizeBase200","lineHeightBase200","paddingTop","spacingVerticalXS","paddingBottom","paddingLeft","spacingHorizontalXS","paddingRight","useSwitchStyles_unstable","state","rootBaseClassName","rootStyles","indicatorBaseClassName","indicatorStyles","inputBaseClassName","inputStyles","labelStyles","labelPosition","size","className"],"mappings":"AAAA;AAEA,SAASA,uBAAuB,QAAQ,0BAA0B;AAClE,SAASC,MAAM,QAAQ,wBAAwB;AAC/C,SAASC,eAAe,EAAEC,UAAU,EAAEC,YAAY,QAAQ,iBAAiB;AAI3E,OAAO,MAAMC,mBAAgD;IAC3DC,MAAM;IACNC,WAAW;IACXC,OAAO;IACPC,OAAO;AACT,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMC,kBAAkBL,iBAAiBC,IAAI,CAAC;AAErD,+CAA+C;AAC/C,MAAMK,4BAA4B;AAClC,yBAAyB;AACzB,MAAMC,oBAAoB;AAC1B,MAAMC,mBAAmB;AACzB,MAAMC,kBAAkBF,oBAAoBD;AA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3F,SAAS4F,WAAW,CAACE,cAAc,EACnCC,SAAS,WAAWH,YAAYjD,SAAS,EACzC2C,MAAMvF,KAAK,CAACiG,SAAS;IAGvB,IAAIV,MAAMtF,KAAK,EAAE;QACf,oDAAoD;QACpDsF,MAAMtF,KAAK,CAACgG,SAAS,GAAGrG,aACtBC,iBAAiBI,KAAK,EACtB6F,YAAYpB,IAAI,EAChBoB,WAAW,CAACC,cAAc,EAC1BC,SAAS,WAAWF,YAAYlD,SAAS,EACzC2C,MAAMtF,KAAK,CAACgG,SAAS;IAEzB;IAEA,OAAOV;AACT,EAAE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Switch base state, excluding design-related state like size
|
|
3
|
+
*/ "use strict";
|
|
2
4
|
Object.defineProperty(exports, "__esModule", {
|
|
3
5
|
value: true
|
|
4
6
|
});
|
|
5
|
-
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
6
|
-
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../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' | 'size'\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 * When set, allows the Switch to be focusable even when it has been disabled. This is used in scenarios where it is\n * important to keep a consistent tab order for screen reader and keyboard users.\n *\n * @default false\n */\n disabledFocusable?: 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 * The size of the Switch.\n *\n * @default 'medium'\n */\n size?: 'small' | 'medium';\n\n /**\n * Callback to be called when the checked state value changes.\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback\n onChange?: (ev: React.ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => void;\n};\n\n/**\n * Switch base props, excluding design-related props like size\n */\nexport type SwitchBaseProps = Omit<SwitchProps, 'size'>;\n\n/**\n * State used in rendering Switch\n */\nexport type SwitchState = ComponentState<SwitchSlots> &\n Required<Pick<SwitchProps, 'disabledFocusable' | 'labelPosition' | 'size'>>;\n\n/**\n * Switch base state, excluding design-related state like size\n */\nexport type SwitchBaseState = Omit<SwitchState, 'size'>;\n"],"names":[
|
|
1
|
+
{"version":3,"sources":["../src/components/Switch/Switch.types.ts"],"sourcesContent":["import type * as React from 'react';\nimport type { 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' | 'size'\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 * When set, allows the Switch to be focusable even when it has been disabled. This is used in scenarios where it is\n * important to keep a consistent tab order for screen reader and keyboard users.\n *\n * @default false\n */\n disabledFocusable?: 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 * The size of the Switch.\n *\n * @default 'medium'\n */\n size?: 'small' | 'medium';\n\n /**\n * Callback to be called when the checked state value changes.\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback\n onChange?: (ev: React.ChangeEvent<HTMLInputElement>, data: SwitchOnChangeData) => void;\n};\n\n/**\n * Switch base props, excluding design-related props like size\n */\nexport type SwitchBaseProps = Omit<SwitchProps, 'size'>;\n\n/**\n * State used in rendering Switch\n */\nexport type SwitchState = ComponentState<SwitchSlots> &\n Required<Pick<SwitchProps, 'disabledFocusable' | 'labelPosition' | 'size'>>;\n\n/**\n * Switch base state, excluding design-related state like size\n */\nexport type SwitchBaseState = Omit<SwitchState, 'size'>;\n"],"names":[],"mappings":"AAoGA;;CAEC,GACD,WAAwD"}
|
|
@@ -25,11 +25,26 @@ const _reactlabel = require("@fluentui/react-label");
|
|
|
25
25
|
const _reacttabster = require("@fluentui/react-tabster");
|
|
26
26
|
const _reactutilities = require("@fluentui/react-utilities");
|
|
27
27
|
const useSwitch_unstable = (props, ref)=>{
|
|
28
|
+
var _baseState_indicator;
|
|
28
29
|
const { size = 'medium', ...baseProps } = props;
|
|
29
30
|
const baseState = useSwitchBase_unstable(baseProps, ref);
|
|
31
|
+
var _children;
|
|
32
|
+
(_children = (_baseState_indicator = baseState.indicator).children) !== null && _children !== void 0 ? _children : _baseState_indicator.children = /*#__PURE__*/ _react.createElement(_reacticons.CircleFilled, null);
|
|
30
33
|
return {
|
|
31
34
|
...baseState,
|
|
32
|
-
|
|
35
|
+
components: {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
37
|
+
...baseState.components,
|
|
38
|
+
label: _reactlabel.Label
|
|
39
|
+
},
|
|
40
|
+
size,
|
|
41
|
+
label: _reactutilities.slot.optional(props.label, {
|
|
42
|
+
defaultProps: {
|
|
43
|
+
size: 'medium',
|
|
44
|
+
...baseState.label
|
|
45
|
+
},
|
|
46
|
+
elementType: _reactlabel.Label
|
|
47
|
+
})
|
|
33
48
|
};
|
|
34
49
|
};
|
|
35
50
|
const useSwitchBase_unstable = (props, ref)=>{
|
|
@@ -59,8 +74,7 @@ const useSwitchBase_unstable = (props, ref)=>{
|
|
|
59
74
|
});
|
|
60
75
|
const indicator = _reactutilities.slot.always(props.indicator, {
|
|
61
76
|
defaultProps: {
|
|
62
|
-
'aria-hidden': true
|
|
63
|
-
children: /*#__PURE__*/ _react.createElement(_reacticons.CircleFilled, null)
|
|
77
|
+
'aria-hidden': true
|
|
64
78
|
},
|
|
65
79
|
elementType: 'div'
|
|
66
80
|
});
|
|
@@ -97,10 +111,9 @@ const useSwitchBase_unstable = (props, ref)=>{
|
|
|
97
111
|
defaultProps: {
|
|
98
112
|
disabled: disabled || disabledFocusable,
|
|
99
113
|
htmlFor: id,
|
|
100
|
-
required
|
|
101
|
-
size: 'medium'
|
|
114
|
+
required
|
|
102
115
|
},
|
|
103
|
-
elementType:
|
|
116
|
+
elementType: 'label'
|
|
104
117
|
});
|
|
105
118
|
return {
|
|
106
119
|
disabledFocusable,
|
|
@@ -109,7 +122,7 @@ const useSwitchBase_unstable = (props, ref)=>{
|
|
|
109
122
|
root: 'div',
|
|
110
123
|
indicator: 'div',
|
|
111
124
|
input: 'input',
|
|
112
|
-
label:
|
|
125
|
+
label: 'label'
|
|
113
126
|
},
|
|
114
127
|
root,
|
|
115
128
|
indicator,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Switch/useSwitch.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { CircleFilled } from '@fluentui/react-icons';\nimport { Label } from '@fluentui/react-label';\nimport { useFocusWithin } from '@fluentui/react-tabster';\nimport { getPartitionedNativeProps, mergeCallbacks, useId, slot } from '@fluentui/react-utilities';\nimport type { SwitchProps, SwitchState, SwitchBaseProps, SwitchBaseState } 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 { size = 'medium', ...baseProps } = props;\n\n const baseState = useSwitchBase_unstable(baseProps, ref);\n\n return {\n ...baseState,\n size,\n };\n};\n\n/**\n * Base hook for Switch component, manages state and structure common to all variants of Switch\n *\n * @param props - base props from this instance of Switch\n * @param ref - reference to `<input>` element of Switch\n */\nexport const useSwitchBase_unstable = (props: SwitchBaseProps, ref?: React.Ref<HTMLInputElement>): SwitchBaseState => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });\n\n const {\n checked,\n defaultChecked,\n disabled,\n disabledFocusable = false,\n labelPosition = 'after',\n onChange,\n required,\n } = props;\n\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['checked', 'defaultChecked', 'onChange', 'disabledFocusable'],\n });\n\n const id = useId('switch-', nativeProps.primary.id);\n\n const root = slot.always(props.root, {\n defaultProps: { ref: useFocusWithin<HTMLDivElement>(), ...nativeProps.root },\n elementType: 'div',\n });\n const indicator = slot.always(props.indicator, {\n defaultProps: { 'aria-hidden': true
|
|
1
|
+
{"version":3,"sources":["../src/components/Switch/useSwitch.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { CircleFilled } from '@fluentui/react-icons';\nimport { Label } from '@fluentui/react-label';\nimport { useFocusWithin } from '@fluentui/react-tabster';\nimport { getPartitionedNativeProps, mergeCallbacks, useId, slot } from '@fluentui/react-utilities';\nimport type { SwitchProps, SwitchState, SwitchBaseProps, SwitchBaseState } 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 { size = 'medium', ...baseProps } = props;\n\n const baseState = useSwitchBase_unstable(baseProps, ref);\n\n baseState.indicator.children ??= <CircleFilled />;\n\n return {\n ...baseState,\n components: {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n ...baseState.components,\n label: Label,\n },\n size,\n label: slot.optional(props.label, {\n defaultProps: { size: 'medium', ...baseState.label },\n elementType: Label,\n }),\n };\n};\n\n/**\n * Base hook for Switch component, manages state and structure common to all variants of Switch\n *\n * @param props - base props from this instance of Switch\n * @param ref - reference to `<input>` element of Switch\n */\nexport const useSwitchBase_unstable = (props: SwitchBaseProps, ref?: React.Ref<HTMLInputElement>): SwitchBaseState => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });\n\n const {\n checked,\n defaultChecked,\n disabled,\n disabledFocusable = false,\n labelPosition = 'after',\n onChange,\n required,\n } = props;\n\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['checked', 'defaultChecked', 'onChange', 'disabledFocusable'],\n });\n\n const id = useId('switch-', nativeProps.primary.id);\n\n const root = slot.always(props.root, {\n defaultProps: { ref: useFocusWithin<HTMLDivElement>(), ...nativeProps.root },\n elementType: 'div',\n });\n const indicator = slot.always(props.indicator, {\n defaultProps: { 'aria-hidden': true },\n elementType: 'div',\n });\n const input = slot.always(props.input, {\n defaultProps: {\n checked,\n defaultChecked,\n id,\n ref,\n role: 'switch',\n type: 'checkbox',\n ...nativeProps.primary,\n disabled: disabled && !disabledFocusable,\n ...(disabledFocusable && { 'aria-disabled': true }),\n },\n elementType: 'input',\n });\n input.onChange = mergeCallbacks(input.onChange, ev => onChange?.(ev, { checked: ev.currentTarget.checked }));\n input.onClick = mergeCallbacks(input.onClick, ev => {\n if (disabledFocusable) {\n ev.preventDefault();\n }\n });\n input.onKeyDown = mergeCallbacks(input.onKeyDown, ev => {\n if (disabledFocusable && (ev.key === ' ' || ev.key === 'Enter')) {\n ev.preventDefault();\n }\n });\n const label = slot.optional(props.label, {\n defaultProps: { disabled: disabled || disabledFocusable, htmlFor: id, required },\n elementType: 'label',\n });\n return {\n disabledFocusable,\n labelPosition,\n components: { root: 'div', indicator: 'div', input: 'input', label: 'label' },\n\n root,\n indicator,\n input,\n label,\n };\n};\n"],"names":["React","useFieldControlProps_unstable","CircleFilled","Label","useFocusWithin","getPartitionedNativeProps","mergeCallbacks","useId","slot","useSwitch_unstable","props","ref","baseState","size","baseProps","useSwitchBase_unstable","indicator","children","components","label","optional","defaultProps","elementType","supportsLabelFor","supportsRequired","checked","defaultChecked","disabled","disabledFocusable","labelPosition","onChange","required","nativeProps","primarySlotTagName","excludedPropNames","id","primary","root","always","input","role","type","ev","currentTarget","onClick","preventDefault","onKeyDown","key","htmlFor"],"mappings":"AAAA;;;;;;;;;;;;IA+Cae,sBAAAA;;;sBA5BAN;;;;;iEAjBU,QAAQ;4BACe,wBAAwB;4BACzC,wBAAwB;4BAC/B,wBAAwB;8BACf,0BAA0B;gCACc,4BAA4B;AAY5F,MAAMA,qBAAqB,CAACC,OAAoBC;QAKrDC;IAJA,MAAM,EAAEC,OAAO,QAAQ,EAAE,GAAGC,WAAW,GAAGJ;IAE1C,MAAME,YAAYG,uBAAuBD,WAAWH;;IAEpDC,CAAAA,YAAAA,CAAAA,uBAAAA,UAAUI,SAAAA,AAAS,EAACC,QAAAA,MAAAA,QAAAA,cAAAA,KAAAA,IAAAA,YAApBL,qBAAoBK,QAAAA,GAAAA,WAAAA,GAAa,OAAA,aAAA,CAACf,wBAAAA,EAAAA;IAElC,OAAO;QACL,GAAGU,SAAS;QACZM,YAAY;YACV,4DAA4D;YAC5D,GAAGN,UAAUM,UAAU;YACvBC,OAAOhB,iBAAAA;QACT;QACAU;QACAM,OAAOX,oBAAAA,CAAKY,QAAQ,CAACV,MAAMS,KAAK,EAAE;YAChCE,cAAc;gBAAER,MAAM;gBAAU,GAAGD,UAAUO,KAAK;YAAC;YACnDG,aAAanB,iBAAAA;QACf;IACF;AACF,EAAE;AAQK,+BAA+B,CAACO,OAAwBC;IAC7D,+CAA+C;IAC/CD,QAAQT,6CAAAA,EAA8BS,OAAO;QAAEa,kBAAkB;QAAMC,kBAAkB;IAAK;IAE9F,MAAM,EACJC,OAAO,EACPC,cAAc,EACdC,QAAQ,EACRC,oBAAoB,KAAK,EACzBC,gBAAgB,OAAO,EACvBC,QAAQ,EACRC,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CAAM,EAAI;YAC/DL,GAAGG,cAAc;QACnB;IACF;IACA,MAAM1B,QAAQX,oBAAAA,CAAKY,QAAQ,CAACV,MAAMS,KAAK,EAAE;QACvCE,cAAc;YAAEM,UAAUA,YAAYC;YAAmBoB,SAASb;YAAIJ;QAAS;QAC/ET,aAAa;IACf;IACA,OAAO;QACLM;QACAC;QACAX,YAAY;YAAEmB,MAAM;YAAOrB,WAAW;YAAOuB,OAAO;YAASpB,OAAO;QAAQ;QAE5EkB;QACArB;QACAuB;QACApB;IACF;AACF,EAAE"}
|
|
@@ -236,10 +236,14 @@ const useSwitchStyles_unstable = (state)=>{
|
|
|
236
236
|
const inputStyles = useInputStyles();
|
|
237
237
|
const labelStyles = useLabelStyles();
|
|
238
238
|
const { label, labelPosition, size } = state;
|
|
239
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
239
240
|
state.root.className = (0, _react.mergeClasses)(switchClassNames.root, rootBaseClassName, labelPosition === 'above' && rootStyles.vertical, state.root.className);
|
|
241
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
240
242
|
state.indicator.className = (0, _react.mergeClasses)(switchClassNames.indicator, indicatorBaseClassName, label && labelPosition === 'above' && indicatorStyles.labelAbove, size === 'small' && indicatorStyles.sizeSmall, state.indicator.className);
|
|
243
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
241
244
|
state.input.className = (0, _react.mergeClasses)(switchClassNames.input, inputBaseClassName, label && inputStyles[labelPosition], size === 'small' && inputStyles.sizeSmall, state.input.className);
|
|
242
245
|
if (state.label) {
|
|
246
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
243
247
|
state.label.className = (0, _react.mergeClasses)(switchClassNames.label, labelStyles.base, labelStyles[labelPosition], size === 'small' && labelStyles.sizeSmall, state.label.className);
|
|
244
248
|
}
|
|
245
249
|
return state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useSwitchStyles.styles.js"],"sourcesContent":["'use client';\nimport { createFocusOutlineStyle } from '@fluentui/react-tabster';\nimport { tokens } from '@fluentui/react-theme';\nimport { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';\nexport const switchClassNames = {\n root: 'fui-Switch',\n indicator: 'fui-Switch__indicator',\n input: 'fui-Switch__input',\n label: 'fui-Switch__label'\n};\n/**\n * @deprecated Use `switchClassNames.root` instead.\n */ export const switchClassName = switchClassNames.root;\n// Thumb and track sizes used by the component.\nconst spaceBetweenThumbAndTrack = 2;\n// Medium size dimensions\nconst trackHeightMedium = 20;\nconst trackWidthMedium = 40;\nconst thumbSizeMedium = trackHeightMedium - spaceBetweenThumbAndTrack;\n// Small size dimensions (from design mockup)\nconst trackHeightSmall = 16;\nconst trackWidthSmall = 32;\nconst thumbSizeSmall = trackHeightSmall - spaceBetweenThumbAndTrack;\nconst useRootBaseClassName = makeResetStyles({\n alignItems: 'flex-start',\n boxSizing: 'border-box',\n display: 'inline-flex',\n position: 'relative',\n ...createFocusOutlineStyle({\n style: {},\n selector: 'focus-within'\n })\n});\nconst useRootStyles = makeStyles({\n vertical: {\n flexDirection: 'column'\n }\n});\nconst useIndicatorBaseClassName = makeResetStyles({\n borderRadius: tokens.borderRadiusCircular,\n border: '1px solid',\n lineHeight: 0,\n boxSizing: 'border-box',\n fill: 'currentColor',\n flexShrink: 0,\n fontSize: `${thumbSizeMedium}px`,\n height: `${trackHeightMedium}px`,\n margin: tokens.spacingVerticalS + ' ' + tokens.spacingHorizontalS,\n pointerEvents: 'none',\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'background, border, color',\n width: `${trackWidthMedium}px`,\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms'\n },\n '@media (forced-colors: active)': {\n color: 'CanvasText',\n '> i': {\n forcedColorAdjust: 'none'\n }\n },\n '> *': {\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'transform',\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms'\n }\n }\n});\nconst useIndicatorStyles = makeStyles({\n labelAbove: {\n marginTop: 0\n },\n sizeSmall: {\n fontSize: `${thumbSizeSmall}px`,\n height: `${trackHeightSmall}px`,\n width: `${trackWidthSmall}px`\n }\n});\nconst useInputBaseClassName = makeResetStyles({\n boxSizing: 'border-box',\n cursor: 'pointer',\n height: '100%',\n margin: 0,\n opacity: 0,\n position: 'absolute',\n // Calculate the width of the hidden input by taking into account the size of the indicator + the padding around it.\n // This is done so that clicking on that \"empty space\" still toggles the switch.\n width: `calc(${trackWidthMedium}px + 2 * ${tokens.spacingHorizontalS})`,\n // Checked (both enabled and disabled)\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthMedium - thumbSizeMedium - spaceBetweenThumbAndTrack}px)`\n }\n }\n },\n // Disabled (both checked and unchecked)\n ':disabled, &[aria-disabled=\"true\"]': {\n cursor: 'default',\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralForegroundDisabled\n },\n [`& ~ .${switchClassNames.label}`]: {\n cursor: 'default',\n color: tokens.colorNeutralForegroundDisabled\n }\n },\n // Enabled and unchecked\n ':enabled:not(:checked):not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessible,\n borderColor: tokens.colorNeutralStrokeAccessible\n },\n [`& ~ .${switchClassNames.label}`]: {\n color: tokens.colorNeutralForeground1\n },\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessibleHover,\n borderColor: tokens.colorNeutralStrokeAccessibleHover\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessiblePressed,\n borderColor: tokens.colorNeutralStrokeAccessiblePressed\n }\n }\n },\n // Enabled and checked\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackground,\n color: tokens.colorNeutralForegroundInverted,\n borderColor: tokens.colorTransparentStroke\n },\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundHover,\n borderColor: tokens.colorTransparentStrokeInteractive\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundPressed,\n borderColor: tokens.colorTransparentStrokeInteractive\n }\n }\n },\n // Disabled and unchecked\n ':disabled:not(:checked), &[aria-disabled=\"true\"]:not(:checked)': {\n [`& ~ .${switchClassNames.indicator}`]: {\n borderColor: tokens.colorNeutralStrokeDisabled\n }\n },\n // Disabled and checked\n ':disabled:checked, &[aria-disabled=\"true\"]:checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorNeutralBackgroundDisabled,\n borderColor: tokens.colorTransparentStrokeDisabled\n }\n },\n '@media (forced-colors: active)': {\n ':disabled, &[aria-disabled=\"true\"]': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: 'GrayText',\n borderColor: 'GrayText'\n },\n [`& ~ .${switchClassNames.label}`]: {\n color: 'GrayText'\n }\n },\n ':hover': {\n color: 'CanvasText'\n },\n ':hover:active': {\n color: 'CanvasText'\n },\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n },\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n }\n }\n});\nconst useInputStyles = makeStyles({\n before: {\n right: 0,\n top: 0\n },\n after: {\n left: 0,\n top: 0\n },\n above: {\n bottom: 0,\n height: `calc(${trackHeightMedium}px + ${tokens.spacingVerticalS})`,\n width: '100%'\n },\n sizeSmall: {\n width: `calc(${trackWidthSmall}px + 2 * ${tokens.spacingHorizontalS})`,\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthSmall - thumbSizeSmall - spaceBetweenThumbAndTrack}px)`\n }\n }\n }\n }\n});\n// Can't use makeResetStyles here because Label is a component that may itself use makeResetStyles.\nconst useLabelStyles = makeStyles({\n base: {\n cursor: 'pointer',\n // Use a (negative) margin to account for the difference between the track's height and the label's line height.\n // This prevents the label from expanding the height of the switch, but preserves line height if the label wraps.\n marginBottom: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n marginTop: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalS}`\n },\n sizeSmall: {\n fontSize: tokens.fontSizeBase200,\n lineHeight: tokens.lineHeightBase200,\n marginBottom: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n marginTop: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`\n },\n above: {\n paddingTop: tokens.spacingVerticalXS,\n paddingBottom: tokens.spacingVerticalXS,\n width: '100%'\n },\n after: {\n paddingLeft: tokens.spacingHorizontalXS\n },\n before: {\n paddingRight: tokens.spacingHorizontalXS\n }\n});\n/**\n * Apply styling to the Switch slots based on the state\n */ export const useSwitchStyles_unstable = (state)=>{\n 'use no memo';\n const rootBaseClassName = useRootBaseClassName();\n const rootStyles = useRootStyles();\n const indicatorBaseClassName = useIndicatorBaseClassName();\n const indicatorStyles = useIndicatorStyles();\n const inputBaseClassName = useInputBaseClassName();\n const inputStyles = useInputStyles();\n const labelStyles = useLabelStyles();\n const { label, labelPosition, size } = state;\n state.root.className = mergeClasses(switchClassNames.root, rootBaseClassName, labelPosition === 'above' && rootStyles.vertical, state.root.className);\n state.indicator.className = mergeClasses(switchClassNames.indicator, indicatorBaseClassName, label && labelPosition === 'above' && indicatorStyles.labelAbove, size === 'small' && indicatorStyles.sizeSmall, state.indicator.className);\n state.input.className = mergeClasses(switchClassNames.input, inputBaseClassName, label && inputStyles[labelPosition], size === 'small' && inputStyles.sizeSmall, state.input.className);\n if (state.label) {\n state.label.className = mergeClasses(switchClassNames.label, labelStyles.base, labelStyles[labelPosition], size === 'small' && labelStyles.sizeSmall, state.label.className);\n }\n return state;\n};\n"],"names":["createFocusOutlineStyle","tokens","__resetStyles","__styles","mergeClasses","switchClassNames","root","indicator","input","label","switchClassName","spaceBetweenThumbAndTrack","trackHeightMedium","trackWidthMedium","thumbSizeMedium","trackHeightSmall","trackWidthSmall","thumbSizeSmall","useRootBaseClassName","r","s","useRootStyles","vertical","Beiy3e4","d","useIndicatorBaseClassName","useIndicatorStyles","labelAbove","B6of3ja","sizeSmall","Be2twd7","Bqenvij","a9b677","useInputBaseClassName","useInputStyles","before","j35jbq","Bhzewxz","after","oyh7mz","above","B5kzvoi","oedwrj","useLabelStyles","base","Bceei9c","jrapky","Byoj8tv","uwmqm3","z189sj","z8tnut","B0ocmuz","Bg96gwp","p","useSwitchStyles_unstable","state","rootBaseClassName","rootStyles","indicatorBaseClassName","indicatorStyles","inputBaseClassName","inputStyles","labelStyles","labelPosition","size","className"],"mappings":"AAAA,YAAY;;;;;;;;;;;;IAYKU,eAAe;;;IARnBL,gBAAgB;;;IA4PZiD,wBAAwB;;;;uBA7PiB,gBAAgB;AACnE,yBAAyB;IAC5BhD,IAAI,EAAE,YAAY;IAClBC,SAAS,EAAE,uBAAuB;IAClCC,KAAK,EAAE,mBAAmB;IAC1BC,KAAK,EAAE;AACX,CAAC;AAGU,wBAAwBJ,gBAAgB,CAACC,IAAI;AACxD,+CAAA;AACA,MAAMK,yBAAyB,GAAG,CAAC;AACnC,yBAAA;AACA,MAAMC,iBAAiB,GAAG,EAAE;AAC5B,MAAMC,gBAAgB,GAAG,EAAE;AAC3B,MAAMC,eAAe,GAAGF,iBAAiB,GAAGD,yBAAyB;AACrE,6CAAA;AACA,M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C,KAAK,CAAC9C,KAAK,CAACwD,SAAS,GAAG7D,uBAAY,EAACC,gBAAgB,CAACI,KAAK,EAAEqD,WAAW,CAAClB,IAAI,EAAEkB,WAAW,CAACC,aAAa,CAAC,EAAEC,IAAI,KAAK,OAAO,IAAIF,WAAW,CAACjC,SAAS,EAAE0B,KAAK,CAAC9C,KAAK,CAACwD,SAAS,CAAC;IAChL;IACA,OAAOV,KAAK;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"sources":["useSwitchStyles.styles.js"],"sourcesContent":["'use client';\nimport { createFocusOutlineStyle } from '@fluentui/react-tabster';\nimport { tokens } from '@fluentui/react-theme';\nimport { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';\nexport const switchClassNames = {\n root: 'fui-Switch',\n indicator: 'fui-Switch__indicator',\n input: 'fui-Switch__input',\n label: 'fui-Switch__label'\n};\n/**\n * @deprecated Use `switchClassNames.root` instead.\n */ export const switchClassName = switchClassNames.root;\n// Thumb and track sizes used by the component.\nconst spaceBetweenThumbAndTrack = 2;\n// Medium size dimensions\nconst trackHeightMedium = 20;\nconst trackWidthMedium = 40;\nconst thumbSizeMedium = trackHeightMedium - spaceBetweenThumbAndTrack;\n// Small size dimensions (from design mockup)\nconst trackHeightSmall = 16;\nconst trackWidthSmall = 32;\nconst thumbSizeSmall = trackHeightSmall - spaceBetweenThumbAndTrack;\nconst useRootBaseClassName = makeResetStyles({\n alignItems: 'flex-start',\n boxSizing: 'border-box',\n display: 'inline-flex',\n position: 'relative',\n ...createFocusOutlineStyle({\n style: {},\n selector: 'focus-within'\n })\n});\nconst useRootStyles = makeStyles({\n vertical: {\n flexDirection: 'column'\n }\n});\nconst useIndicatorBaseClassName = makeResetStyles({\n borderRadius: tokens.borderRadiusCircular,\n border: '1px solid',\n lineHeight: 0,\n boxSizing: 'border-box',\n fill: 'currentColor',\n flexShrink: 0,\n fontSize: `${thumbSizeMedium}px`,\n height: `${trackHeightMedium}px`,\n margin: tokens.spacingVerticalS + ' ' + tokens.spacingHorizontalS,\n pointerEvents: 'none',\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'background, border, color',\n width: `${trackWidthMedium}px`,\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms'\n },\n '@media (forced-colors: active)': {\n color: 'CanvasText',\n '> i': {\n forcedColorAdjust: 'none'\n }\n },\n '> *': {\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'transform',\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms'\n }\n }\n});\nconst useIndicatorStyles = makeStyles({\n labelAbove: {\n marginTop: 0\n },\n sizeSmall: {\n fontSize: `${thumbSizeSmall}px`,\n height: `${trackHeightSmall}px`,\n width: `${trackWidthSmall}px`\n }\n});\nconst useInputBaseClassName = makeResetStyles({\n boxSizing: 'border-box',\n cursor: 'pointer',\n height: '100%',\n margin: 0,\n opacity: 0,\n position: 'absolute',\n // Calculate the width of the hidden input by taking into account the size of the indicator + the padding around it.\n // This is done so that clicking on that \"empty space\" still toggles the switch.\n width: `calc(${trackWidthMedium}px + 2 * ${tokens.spacingHorizontalS})`,\n // Checked (both enabled and disabled)\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthMedium - thumbSizeMedium - spaceBetweenThumbAndTrack}px)`\n }\n }\n },\n // Disabled (both checked and unchecked)\n ':disabled, &[aria-disabled=\"true\"]': {\n cursor: 'default',\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralForegroundDisabled\n },\n [`& ~ .${switchClassNames.label}`]: {\n cursor: 'default',\n color: tokens.colorNeutralForegroundDisabled\n }\n },\n // Enabled and unchecked\n ':enabled:not(:checked):not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessible,\n borderColor: tokens.colorNeutralStrokeAccessible\n },\n [`& ~ .${switchClassNames.label}`]: {\n color: tokens.colorNeutralForeground1\n },\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessibleHover,\n borderColor: tokens.colorNeutralStrokeAccessibleHover\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessiblePressed,\n borderColor: tokens.colorNeutralStrokeAccessiblePressed\n }\n }\n },\n // Enabled and checked\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackground,\n color: tokens.colorNeutralForegroundInverted,\n borderColor: tokens.colorTransparentStroke\n },\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundHover,\n borderColor: tokens.colorTransparentStrokeInteractive\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundPressed,\n borderColor: tokens.colorTransparentStrokeInteractive\n }\n }\n },\n // Disabled and unchecked\n ':disabled:not(:checked), &[aria-disabled=\"true\"]:not(:checked)': {\n [`& ~ .${switchClassNames.indicator}`]: {\n borderColor: tokens.colorNeutralStrokeDisabled\n }\n },\n // Disabled and checked\n ':disabled:checked, &[aria-disabled=\"true\"]:checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorNeutralBackgroundDisabled,\n borderColor: tokens.colorTransparentStrokeDisabled\n }\n },\n '@media (forced-colors: active)': {\n ':disabled, &[aria-disabled=\"true\"]': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: 'GrayText',\n borderColor: 'GrayText'\n },\n [`& ~ .${switchClassNames.label}`]: {\n color: 'GrayText'\n }\n },\n ':hover': {\n color: 'CanvasText'\n },\n ':hover:active': {\n color: 'CanvasText'\n },\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n },\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas'\n }\n }\n }\n});\nconst useInputStyles = makeStyles({\n before: {\n right: 0,\n top: 0\n },\n after: {\n left: 0,\n top: 0\n },\n above: {\n bottom: 0,\n height: `calc(${trackHeightMedium}px + ${tokens.spacingVerticalS})`,\n width: '100%'\n },\n sizeSmall: {\n width: `calc(${trackWidthSmall}px + 2 * ${tokens.spacingHorizontalS})`,\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthSmall - thumbSizeSmall - spaceBetweenThumbAndTrack}px)`\n }\n }\n }\n }\n});\n// Can't use makeResetStyles here because Label is a component that may itself use makeResetStyles.\nconst useLabelStyles = makeStyles({\n base: {\n cursor: 'pointer',\n // Use a (negative) margin to account for the difference between the track's height and the label's line height.\n // This prevents the label from expanding the height of the switch, but preserves line height if the label wraps.\n marginBottom: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n marginTop: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalS}`\n },\n sizeSmall: {\n fontSize: tokens.fontSizeBase200,\n lineHeight: tokens.lineHeightBase200,\n marginBottom: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n marginTop: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`\n },\n above: {\n paddingTop: tokens.spacingVerticalXS,\n paddingBottom: tokens.spacingVerticalXS,\n width: '100%'\n },\n after: {\n paddingLeft: tokens.spacingHorizontalXS\n },\n before: {\n paddingRight: tokens.spacingHorizontalXS\n }\n});\n/**\n * Apply styling to the Switch slots based on the state\n */ export const useSwitchStyles_unstable = (state)=>{\n 'use no memo';\n const rootBaseClassName = useRootBaseClassName();\n const rootStyles = useRootStyles();\n const indicatorBaseClassName = useIndicatorBaseClassName();\n const indicatorStyles = useIndicatorStyles();\n const inputBaseClassName = useInputBaseClassName();\n const inputStyles = useInputStyles();\n const labelStyles = useLabelStyles();\n const { label, labelPosition, size } = state;\n // eslint-disable-next-line react-hooks/immutability\n state.root.className = mergeClasses(switchClassNames.root, rootBaseClassName, labelPosition === 'above' && rootStyles.vertical, state.root.className);\n // eslint-disable-next-line react-hooks/immutability\n state.indicator.className = mergeClasses(switchClassNames.indicator, indicatorBaseClassName, label && labelPosition === 'above' && indicatorStyles.labelAbove, size === 'small' && indicatorStyles.sizeSmall, state.indicator.className);\n // eslint-disable-next-line react-hooks/immutability\n state.input.className = mergeClasses(switchClassNames.input, inputBaseClassName, label && inputStyles[labelPosition], size === 'small' && inputStyles.sizeSmall, state.input.className);\n if (state.label) {\n // eslint-disable-next-line react-hooks/immutability\n state.label.className = mergeClasses(switchClassNames.label, labelStyles.base, labelStyles[labelPosition], size === 'small' && labelStyles.sizeSmall, state.label.className);\n }\n return state;\n};\n"],"names":["createFocusOutlineStyle","tokens","__resetStyles","__styles","mergeClasses","switchClassNames","root","indicator","input","label","switchClassName","spaceBetweenThumbAndTrack","trackHeightMedium","trackWidthMedium","thumbSizeMedium","trackHeightSmall","trackWidthSmall","thumbSizeSmall","useRootBaseClassName","r","s","useRootStyles","vertical","Beiy3e4","d","useIndicatorBaseClassName","useIndicatorStyles","labelAbove","B6of3ja","sizeSmall","Be2twd7","Bqenvij","a9b677","useInputBaseClassName","useInputStyles","before","j35jbq","Bhzewxz","after","oyh7mz","above","B5kzvoi","oedwrj","useLabelStyles","base","Bceei9c","jrapky","Byoj8tv","uwmqm3","z189sj","z8tnut","B0ocmuz","Bg96gwp","p","useSwitchStyles_unstable","state","rootBaseClassName","rootStyles","indicatorBaseClassName","indicatorStyles","inputBaseClassName","inputStyles","labelStyles","labelPosition","size","className"],"m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,CAACE,SAAS,EAAEmD,sBAAsB,EAAEjD,KAAK,IAAIsD,aAAa,KAAK,OAAO,IAAIJ,eAAe,CAAChC,UAAU,EAAEqC,IAAI,KAAK,OAAO,IAAIL,eAAe,CAAC9B,SAAS,EAAE0B,KAAK,CAAChD,SAAS,CAAC0D,SAAS,CAAC;IACxO,oDAAA;IACAV,KAAK,CAAC/C,KAAK,CAACyD,SAAS,OAAG7D,mBAAY,EAACC,gBAAgB,CAACG,KAAK,EAAEoD,kBAAkB,EAAEnD,KAAK,IAAIoD,WAAW,CAACE,aAAa,CAAC,EAAEC,IAAI,KAAK,OAAO,IAAIH,WAAW,CAAChC,SAAS,EAAE0B,KAAK,CAAC/C,KAAK,CAACyD,SAAS,CAAC;IACvL,IAAIV,KAAK,CAAC9C,KAAK,EAAE;QACb,oDAAA;QACA8C,KAAK,CAAC9C,KAAK,CAACwD,SAAS,GAAG7D,uBAAY,EAACC,gBAAgB,CAACI,KAAK,EAAEqD,WAAW,CAAClB,IAAI,EAAEkB,WAAW,CAACC,aAAa,CAAC,EAAEC,IAAI,KAAK,OAAO,IAAIF,WAAW,CAACjC,SAAS,EAAE0B,KAAK,CAAC9C,KAAK,CAACwD,SAAS,CAAC;IAChL;IACA,OAAOV,KAAK;AAChB,CAAC"}
|
|
@@ -281,10 +281,14 @@ const useSwitchStyles_unstable = (state)=>{
|
|
|
281
281
|
const inputStyles = useInputStyles();
|
|
282
282
|
const labelStyles = useLabelStyles();
|
|
283
283
|
const { label, labelPosition, size } = state;
|
|
284
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
284
285
|
state.root.className = (0, _react.mergeClasses)(switchClassNames.root, rootBaseClassName, labelPosition === 'above' && rootStyles.vertical, state.root.className);
|
|
286
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
285
287
|
state.indicator.className = (0, _react.mergeClasses)(switchClassNames.indicator, indicatorBaseClassName, label && labelPosition === 'above' && indicatorStyles.labelAbove, size === 'small' && indicatorStyles.sizeSmall, state.indicator.className);
|
|
288
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
286
289
|
state.input.className = (0, _react.mergeClasses)(switchClassNames.input, inputBaseClassName, label && inputStyles[labelPosition], size === 'small' && inputStyles.sizeSmall, state.input.className);
|
|
287
290
|
if (state.label) {
|
|
291
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
288
292
|
state.label.className = (0, _react.mergeClasses)(switchClassNames.label, labelStyles.base, labelStyles[labelPosition], size === 'small' && labelStyles.sizeSmall, state.label.className);
|
|
289
293
|
}
|
|
290
294
|
return state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Switch/useSwitchStyles.styles.ts"],"sourcesContent":["'use client';\n\nimport { createFocusOutlineStyle } from '@fluentui/react-tabster';\nimport { tokens } from '@fluentui/react-theme';\nimport { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport type { SwitchSlots, SwitchState } from './Switch.types';\n\nexport const switchClassNames: SlotClassNames<SwitchSlots> = {\n root: 'fui-Switch',\n indicator: 'fui-Switch__indicator',\n input: 'fui-Switch__input',\n label: 'fui-Switch__label',\n};\n\n/**\n * @deprecated Use `switchClassNames.root` instead.\n */\nexport const switchClassName = switchClassNames.root;\n\n// Thumb and track sizes used by the component.\nconst spaceBetweenThumbAndTrack = 2;\n// Medium size dimensions\nconst trackHeightMedium = 20;\nconst trackWidthMedium = 40;\nconst thumbSizeMedium = trackHeightMedium - spaceBetweenThumbAndTrack;\n// Small size dimensions (from design mockup)\nconst trackHeightSmall = 16;\nconst trackWidthSmall = 32;\nconst thumbSizeSmall = trackHeightSmall - spaceBetweenThumbAndTrack;\n\nconst useRootBaseClassName = makeResetStyles({\n alignItems: 'flex-start',\n boxSizing: 'border-box',\n display: 'inline-flex',\n position: 'relative',\n\n ...createFocusOutlineStyle({ style: {}, selector: 'focus-within' }),\n});\n\nconst useRootStyles = makeStyles({\n vertical: {\n flexDirection: 'column',\n },\n});\n\nconst useIndicatorBaseClassName = makeResetStyles({\n borderRadius: tokens.borderRadiusCircular,\n border: '1px solid',\n lineHeight: 0,\n boxSizing: 'border-box',\n fill: 'currentColor',\n flexShrink: 0,\n fontSize: `${thumbSizeMedium}px`,\n height: `${trackHeightMedium}px`,\n margin: tokens.spacingVerticalS + ' ' + tokens.spacingHorizontalS,\n pointerEvents: 'none',\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'background, border, color',\n width: `${trackWidthMedium}px`,\n\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms',\n },\n\n '@media (forced-colors: active)': {\n color: 'CanvasText',\n '> i': {\n forcedColorAdjust: 'none',\n },\n },\n\n '> *': {\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'transform',\n\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms',\n },\n },\n});\n\nconst useIndicatorStyles = makeStyles({\n labelAbove: {\n marginTop: 0,\n },\n sizeSmall: {\n fontSize: `${thumbSizeSmall}px`,\n height: `${trackHeightSmall}px`,\n width: `${trackWidthSmall}px`,\n },\n});\n\nconst useInputBaseClassName = makeResetStyles({\n boxSizing: 'border-box',\n cursor: 'pointer',\n height: '100%',\n margin: 0,\n opacity: 0,\n position: 'absolute',\n\n // Calculate the width of the hidden input by taking into account the size of the indicator + the padding around it.\n // This is done so that clicking on that \"empty space\" still toggles the switch.\n width: `calc(${trackWidthMedium}px + 2 * ${tokens.spacingHorizontalS})`,\n\n // Checked (both enabled and disabled)\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthMedium - thumbSizeMedium - spaceBetweenThumbAndTrack}px)`,\n },\n },\n },\n\n // Disabled (both checked and unchecked)\n ':disabled, &[aria-disabled=\"true\"]': {\n cursor: 'default',\n\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralForegroundDisabled,\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n cursor: 'default',\n color: tokens.colorNeutralForegroundDisabled,\n },\n },\n\n // Enabled and unchecked\n ':enabled:not(:checked):not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessible,\n borderColor: tokens.colorNeutralStrokeAccessible,\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n color: tokens.colorNeutralForeground1,\n },\n\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessibleHover,\n borderColor: tokens.colorNeutralStrokeAccessibleHover,\n },\n },\n\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessiblePressed,\n borderColor: tokens.colorNeutralStrokeAccessiblePressed,\n },\n },\n },\n\n // Enabled and checked\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackground,\n color: tokens.colorNeutralForegroundInverted,\n borderColor: tokens.colorTransparentStroke,\n },\n\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundHover,\n borderColor: tokens.colorTransparentStrokeInteractive,\n },\n },\n\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundPressed,\n borderColor: tokens.colorTransparentStrokeInteractive,\n },\n },\n },\n\n // Disabled and unchecked\n ':disabled:not(:checked), &[aria-disabled=\"true\"]:not(:checked)': {\n [`& ~ .${switchClassNames.indicator}`]: {\n borderColor: tokens.colorNeutralStrokeDisabled,\n },\n },\n\n // Disabled and checked\n ':disabled:checked, &[aria-disabled=\"true\"]:checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorNeutralBackgroundDisabled,\n borderColor: tokens.colorTransparentStrokeDisabled,\n },\n },\n\n '@media (forced-colors: active)': {\n ':disabled, &[aria-disabled=\"true\"]': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: 'GrayText',\n borderColor: 'GrayText',\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n color: 'GrayText',\n },\n },\n ':hover': {\n color: 'CanvasText',\n },\n ':hover:active': {\n color: 'CanvasText',\n },\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n },\n});\n\nconst useInputStyles = makeStyles({\n before: {\n right: 0,\n top: 0,\n },\n after: {\n left: 0,\n top: 0,\n },\n above: {\n bottom: 0,\n height: `calc(${trackHeightMedium}px + ${tokens.spacingVerticalS})`,\n width: '100%',\n },\n sizeSmall: {\n width: `calc(${trackWidthSmall}px + 2 * ${tokens.spacingHorizontalS})`,\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthSmall - thumbSizeSmall - spaceBetweenThumbAndTrack}px)`,\n },\n },\n },\n },\n});\n\n// Can't use makeResetStyles here because Label is a component that may itself use makeResetStyles.\nconst useLabelStyles = makeStyles({\n base: {\n cursor: 'pointer',\n\n // Use a (negative) margin to account for the difference between the track's height and the label's line height.\n // This prevents the label from expanding the height of the switch, but preserves line height if the label wraps.\n marginBottom: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n marginTop: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalS}`,\n },\n sizeSmall: {\n fontSize: tokens.fontSizeBase200,\n lineHeight: tokens.lineHeightBase200,\n marginBottom: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n marginTop: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n },\n above: {\n paddingTop: tokens.spacingVerticalXS,\n paddingBottom: tokens.spacingVerticalXS,\n width: '100%',\n },\n after: {\n paddingLeft: tokens.spacingHorizontalXS,\n },\n before: {\n paddingRight: tokens.spacingHorizontalXS,\n },\n});\n\n/**\n * Apply styling to the Switch slots based on the state\n */\nexport const useSwitchStyles_unstable = (state: SwitchState): SwitchState => {\n 'use no memo';\n\n const rootBaseClassName = useRootBaseClassName();\n const rootStyles = useRootStyles();\n const indicatorBaseClassName = useIndicatorBaseClassName();\n const indicatorStyles = useIndicatorStyles();\n const inputBaseClassName = useInputBaseClassName();\n const inputStyles = useInputStyles();\n const labelStyles = useLabelStyles();\n\n const { label, labelPosition, size } = state;\n\n state.root.className = mergeClasses(\n switchClassNames.root,\n rootBaseClassName,\n labelPosition === 'above' && rootStyles.vertical,\n state.root.className,\n );\n\n state.indicator.className = mergeClasses(\n switchClassNames.indicator,\n indicatorBaseClassName,\n label && labelPosition === 'above' && indicatorStyles.labelAbove,\n size === 'small' && indicatorStyles.sizeSmall,\n state.indicator.className,\n );\n\n state.input.className = mergeClasses(\n switchClassNames.input,\n inputBaseClassName,\n label && inputStyles[labelPosition],\n size === 'small' && inputStyles.sizeSmall,\n state.input.className,\n );\n\n if (state.label) {\n state.label.className = mergeClasses(\n switchClassNames.label,\n labelStyles.base,\n labelStyles[labelPosition],\n size === 'small' && labelStyles.sizeSmall,\n state.label.className,\n );\n }\n\n return state;\n};\n"],"names":["createFocusOutlineStyle","tokens","makeResetStyles","makeStyles","mergeClasses","switchClassNames","root","indicator","input","label","switchClassName","spaceBetweenThumbAndTrack","trackHeightMedium","trackWidthMedium","thumbSizeMedium","trackHeightSmall","trackWidthSmall","thumbSizeSmall","useRootBaseClassName","alignItems","boxSizing","display","position","style","selector","useRootStyles","vertical","flexDirection","useIndicatorBaseClassName","borderRadius","borderRadiusCircular","border","lineHeight","fill","flexShrink","fontSize","height","margin","spacingVerticalS","spacingHorizontalS","pointerEvents","transitionDuration","durationNormal","transitionTimingFunction","curveEasyEase","transitionProperty","width","color","forcedColorAdjust","useIndicatorStyles","labelAbove","marginTop","sizeSmall","useInputBaseClassName","cursor","opacity","transform","colorNeutralForegroundDisabled","colorNeutralStrokeAccessible","borderColor","colorNeutralForeground1","colorNeutralStrokeAccessibleHover","colorNeutralStrokeAccessiblePressed","backgroundColor","colorCompoundBrandBackground","colorNeutralForegroundInverted","colorTransparentStroke","colorCompoundBrandBackgroundHover","colorTransparentStrokeInteractive","colorCompoundBrandBackgroundPressed","colorNeutralStrokeDisabled","colorNeutralBackgroundDisabled","colorTransparentStrokeDisabled","useInputStyles","before","right","top","after","left","above","bottom","useLabelStyles","base","marginBottom","lineHeightBase300","padding","fontSizeBase200","lineHeightBase200","paddingTop","spacingVerticalXS","paddingBottom","paddingLeft","spacingHorizontalXS","paddingRight","useSwitchStyles_unstable","state","rootBaseClassName","rootStyles","indicatorBaseClassName","indicatorStyles","inputBaseClassName","inputStyles","labelStyles","labelPosition","size","className"],"mappings":"AAAA;;;;;;;;;;;;IAkBaU,eAAAA;;;oBAVAL;;;IA2RAyF,wBAAAA;;;;8BAjS2B,0BAA0B;4BAC3C,wBAAwB;uBACW,iBAAiB;AAIpE,MAAMzF,mBAAgD;IAC3DC,MAAM;IACNC,WAAW;IACXC,OAAO;IACPC,OAAO;AACT,EAAE;AAKK,wBAAwBJ,iBAAiBC,IAAI,CAAC;AAErD,+CAA+C;AAC/C,MAAMK,4BAA4B;AAClC,yBAAyB;AACzB,MAAMC,oBAAoB;AAC1B,MAAMC,mBAAmB;AACzB,MAAMC,kBAAkBF,oBAAoBD;AAC5C,6CAA6C;AAC7C,MAAMI,mBAAmB;AACzB,MAAMC,kBAAkB;AACxB,MAAMC,iBAAiBF,mBAAmBJ;AAE1C,MAAMO,2BAAuBhB,sBAAAA,EAAgB;IAC3CiB,YAAY;IAC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wBACAzF,SAAS8F,kBAAkB,WAAWJ,gBAAgBjD,UAAU,EAChEsD,SAAS,WAAWL,gBAAgB/C,SAAS,EAC7C2C,MAAMxF,SAAS,CAACkG,SAAS;IAG3BV,MAAMvF,KAAK,CAACiG,SAAS,OAAGrG,mBAAAA,EACtBC,iBAAiBG,KAAK,EACtB4F,oBACA3F,SAAS4F,WAAW,CAACE,cAAc,EACnCC,SAAS,WAAWH,YAAYjD,SAAS,EACzC2C,MAAMvF,KAAK,CAACiG,SAAS;IAGvB,IAAIV,MAAMtF,KAAK,EAAE;QACfsF,MAAMtF,KAAK,CAACgG,SAAS,OAAGrG,mBAAAA,EACtBC,iBAAiBI,KAAK,EACtB6F,YAAYpB,IAAI,EAChBoB,WAAW,CAACC,cAAc,EAC1BC,SAAS,WAAWF,YAAYlD,SAAS,EACzC2C,MAAMtF,KAAK,CAACgG,SAAS;IAEzB;IAEA,OAAOV;AACT,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../src/components/Switch/useSwitchStyles.styles.ts"],"sourcesContent":["'use client';\n\nimport { createFocusOutlineStyle } from '@fluentui/react-tabster';\nimport { tokens } from '@fluentui/react-theme';\nimport { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport type { SwitchSlots, SwitchState } from './Switch.types';\n\nexport const switchClassNames: SlotClassNames<SwitchSlots> = {\n root: 'fui-Switch',\n indicator: 'fui-Switch__indicator',\n input: 'fui-Switch__input',\n label: 'fui-Switch__label',\n};\n\n/**\n * @deprecated Use `switchClassNames.root` instead.\n */\nexport const switchClassName = switchClassNames.root;\n\n// Thumb and track sizes used by the component.\nconst spaceBetweenThumbAndTrack = 2;\n// Medium size dimensions\nconst trackHeightMedium = 20;\nconst trackWidthMedium = 40;\nconst thumbSizeMedium = trackHeightMedium - spaceBetweenThumbAndTrack;\n// Small size dimensions (from design mockup)\nconst trackHeightSmall = 16;\nconst trackWidthSmall = 32;\nconst thumbSizeSmall = trackHeightSmall - spaceBetweenThumbAndTrack;\n\nconst useRootBaseClassName = makeResetStyles({\n alignItems: 'flex-start',\n boxSizing: 'border-box',\n display: 'inline-flex',\n position: 'relative',\n\n ...createFocusOutlineStyle({ style: {}, selector: 'focus-within' }),\n});\n\nconst useRootStyles = makeStyles({\n vertical: {\n flexDirection: 'column',\n },\n});\n\nconst useIndicatorBaseClassName = makeResetStyles({\n borderRadius: tokens.borderRadiusCircular,\n border: '1px solid',\n lineHeight: 0,\n boxSizing: 'border-box',\n fill: 'currentColor',\n flexShrink: 0,\n fontSize: `${thumbSizeMedium}px`,\n height: `${trackHeightMedium}px`,\n margin: tokens.spacingVerticalS + ' ' + tokens.spacingHorizontalS,\n pointerEvents: 'none',\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'background, border, color',\n width: `${trackWidthMedium}px`,\n\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms',\n },\n\n '@media (forced-colors: active)': {\n color: 'CanvasText',\n '> i': {\n forcedColorAdjust: 'none',\n },\n },\n\n '> *': {\n transitionDuration: tokens.durationNormal,\n transitionTimingFunction: tokens.curveEasyEase,\n transitionProperty: 'transform',\n\n '@media screen and (prefers-reduced-motion: reduce)': {\n transitionDuration: '0.01ms',\n },\n },\n});\n\nconst useIndicatorStyles = makeStyles({\n labelAbove: {\n marginTop: 0,\n },\n sizeSmall: {\n fontSize: `${thumbSizeSmall}px`,\n height: `${trackHeightSmall}px`,\n width: `${trackWidthSmall}px`,\n },\n});\n\nconst useInputBaseClassName = makeResetStyles({\n boxSizing: 'border-box',\n cursor: 'pointer',\n height: '100%',\n margin: 0,\n opacity: 0,\n position: 'absolute',\n\n // Calculate the width of the hidden input by taking into account the size of the indicator + the padding around it.\n // This is done so that clicking on that \"empty space\" still toggles the switch.\n width: `calc(${trackWidthMedium}px + 2 * ${tokens.spacingHorizontalS})`,\n\n // Checked (both enabled and disabled)\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthMedium - thumbSizeMedium - spaceBetweenThumbAndTrack}px)`,\n },\n },\n },\n\n // Disabled (both checked and unchecked)\n ':disabled, &[aria-disabled=\"true\"]': {\n cursor: 'default',\n\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralForegroundDisabled,\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n cursor: 'default',\n color: tokens.colorNeutralForegroundDisabled,\n },\n },\n\n // Enabled and unchecked\n ':enabled:not(:checked):not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessible,\n borderColor: tokens.colorNeutralStrokeAccessible,\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n color: tokens.colorNeutralForeground1,\n },\n\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessibleHover,\n borderColor: tokens.colorNeutralStrokeAccessibleHover,\n },\n },\n\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: tokens.colorNeutralStrokeAccessiblePressed,\n borderColor: tokens.colorNeutralStrokeAccessiblePressed,\n },\n },\n },\n\n // Enabled and checked\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackground,\n color: tokens.colorNeutralForegroundInverted,\n borderColor: tokens.colorTransparentStroke,\n },\n\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundHover,\n borderColor: tokens.colorTransparentStrokeInteractive,\n },\n },\n\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorCompoundBrandBackgroundPressed,\n borderColor: tokens.colorTransparentStrokeInteractive,\n },\n },\n },\n\n // Disabled and unchecked\n ':disabled:not(:checked), &[aria-disabled=\"true\"]:not(:checked)': {\n [`& ~ .${switchClassNames.indicator}`]: {\n borderColor: tokens.colorNeutralStrokeDisabled,\n },\n },\n\n // Disabled and checked\n ':disabled:checked, &[aria-disabled=\"true\"]:checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: tokens.colorNeutralBackgroundDisabled,\n borderColor: tokens.colorTransparentStrokeDisabled,\n },\n },\n\n '@media (forced-colors: active)': {\n ':disabled, &[aria-disabled=\"true\"]': {\n [`& ~ .${switchClassNames.indicator}`]: {\n color: 'GrayText',\n borderColor: 'GrayText',\n },\n\n [`& ~ .${switchClassNames.label}`]: {\n color: 'GrayText',\n },\n },\n ':hover': {\n color: 'CanvasText',\n },\n ':hover:active': {\n color: 'CanvasText',\n },\n ':enabled:checked:not([aria-disabled=\"true\"])': {\n ':hover': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n ':hover:active': {\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n [`& ~ .${switchClassNames.indicator}`]: {\n backgroundColor: 'Highlight',\n color: 'Canvas',\n },\n },\n },\n});\n\nconst useInputStyles = makeStyles({\n before: {\n right: 0,\n top: 0,\n },\n after: {\n left: 0,\n top: 0,\n },\n above: {\n bottom: 0,\n height: `calc(${trackHeightMedium}px + ${tokens.spacingVerticalS})`,\n width: '100%',\n },\n sizeSmall: {\n width: `calc(${trackWidthSmall}px + 2 * ${tokens.spacingHorizontalS})`,\n ':checked': {\n [`& ~ .${switchClassNames.indicator}`]: {\n '> *': {\n transform: `translateX(${trackWidthSmall - thumbSizeSmall - spaceBetweenThumbAndTrack}px)`,\n },\n },\n },\n },\n});\n\n// Can't use makeResetStyles here because Label is a component that may itself use makeResetStyles.\nconst useLabelStyles = makeStyles({\n base: {\n cursor: 'pointer',\n\n // Use a (negative) margin to account for the difference between the track's height and the label's line height.\n // This prevents the label from expanding the height of the switch, but preserves line height if the label wraps.\n marginBottom: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n marginTop: `calc((${trackHeightMedium}px - ${tokens.lineHeightBase300}) / 2)`,\n padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalS}`,\n },\n sizeSmall: {\n fontSize: tokens.fontSizeBase200,\n lineHeight: tokens.lineHeightBase200,\n marginBottom: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n marginTop: `calc((${trackHeightSmall}px - ${tokens.lineHeightBase200}) / 2)`,\n },\n above: {\n paddingTop: tokens.spacingVerticalXS,\n paddingBottom: tokens.spacingVerticalXS,\n width: '100%',\n },\n after: {\n paddingLeft: tokens.spacingHorizontalXS,\n },\n before: {\n paddingRight: tokens.spacingHorizontalXS,\n },\n});\n\n/**\n * Apply styling to the Switch slots based on the state\n */\nexport const useSwitchStyles_unstable = (state: SwitchState): SwitchState => {\n 'use no memo';\n\n const rootBaseClassName = useRootBaseClassName();\n const rootStyles = useRootStyles();\n const indicatorBaseClassName = useIndicatorBaseClassName();\n const indicatorStyles = useIndicatorStyles();\n const inputBaseClassName = useInputBaseClassName();\n const inputStyles = useInputStyles();\n const labelStyles = useLabelStyles();\n\n const { label, labelPosition, size } = state;\n\n // eslint-disable-next-line react-hooks/immutability\n state.root.className = mergeClasses(\n switchClassNames.root,\n rootBaseClassName,\n labelPosition === 'above' && rootStyles.vertical,\n state.root.className,\n );\n\n // eslint-disable-next-line react-hooks/immutability\n state.indicator.className = mergeClasses(\n switchClassNames.indicator,\n indicatorBaseClassName,\n label && labelPosition === 'above' && indicatorStyles.labelAbove,\n size === 'small' && indicatorStyles.sizeSmall,\n state.indicator.className,\n );\n\n // eslint-disable-next-line react-hooks/immutability\n state.input.className = mergeClasses(\n switchClassNames.input,\n inputBaseClassName,\n label && inputStyles[labelPosition],\n size === 'small' && inputStyles.sizeSmall,\n state.input.className,\n );\n\n if (state.label) {\n // eslint-disable-next-line react-hooks/immutability\n state.label.className = mergeClasses(\n switchClassNames.label,\n labelStyles.base,\n labelStyles[labelPosition],\n size === 'small' && labelStyles.sizeSmall,\n state.label.className,\n );\n }\n\n return state;\n};\n"],"names":["createFocusOutlineStyle","tokens","makeResetStyles","makeStyles","mergeClasses","switchClassNames","root","indicator","input","label","switchClassName","spaceBetweenThumbAndTrack","trackHeightMedium","trackWidthMedium","thumbSizeMedium","trackHeightSmall","trackWidthSmall","thumbSizeSmall","useRootBaseClassName","alignItems","boxSizing","display","position","style","selector","useRootStyles","vertical","flexDirection","useIndicatorBaseClassName","borderRadius","borderRadiusCircular","border","lineHeight","fill","flexShrink","fontSize","height","margin","spacingVerticalS","spacingHorizontalS","pointerEvents","transitionDuration","durationNormal","transitionTimingFunction","curveEasyEase","transitionProperty","width","color","forcedColorAdjust","useIndicatorStyles","labelAbove","marginTop","sizeSmall","useInputBaseClassName","cursor","opacity","transform","colorNeutralForegroundDisabled","colorNeutralStrokeAccessible","borderColor","colorNeutralForeground1","colorNeutralStrokeAccessibleHover","colorNeutralStrokeAccessiblePressed","backgroundColor","colorCompoundBrandBackground","colorNeutralForegroundInverted","colorTransparentStroke","colorCompoundBrandBackgroundHover","colorTransparentStrokeInteractive","colorCompoundBrandBackgroundPressed","colorNeutralStrokeDisabled","colorNeutralBackgroundDisabled","colorTransparentStrokeDisabled","useInputStyles","before","right","top","after","left","above","bottom","useLabelStyles","base","marginBottom","lineHeightBase300","padding","fontSizeBase200","lineHeightBase200","paddingTop","spacingVerticalXS","paddingBottom","paddingLeft","spacingHorizontalXS","paddingRight","useSwitchStyles_unstable","state","rootBaseClassName","rootStyles","indicatorBaseClassName","indicatorStyles","inputBaseClassName","inputStyles","labelStyles","labelPosition","size","className"],"mappings":"AAAA;;;;;;;;;;;;IAkBaU,eAAAA;;;oBAVAL;;;IA2RAyF,wBAAAA;;;;8BAjS2B,0BAA0B;4BAC3C,wBAAwB;uBACW,iBAAiB;AAIpE,MAAMzF,mBAAgD;IAC3DC,MAAM;IACNC,WAAW;IACXC,OAAO;IACPC,OAAO;AACT,EAAE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cAAcrB;IAEpB,MAAM,EAAExE,KAAK,EAAE8F,aAAa,EAAEC,IAAI,EAAE,GAAGT;IAEvC,oDAAoD;IACpDA,MAAMzF,IAAI,CAACmG,SAAS,OAAGrG,mBAAAA,EACrBC,iBAAiBC,IAAI,EACrB0F,mBACAO,kBAAkB,WAAWN,WAAWvE,QAAQ,EAChDqE,MAAMzF,IAAI,CAACmG,SAAS;IAGtB,oDAAoD;IACpDV,MAAMxF,SAAS,CAACkG,SAAS,GAAGrG,uBAAAA,EAC1BC,iBAAiBE,SAAS,EAC1B2F,wBACAzF,SAAS8F,kBAAkB,WAAWJ,gBAAgBjD,UAAU,EAChEsD,SAAS,WAAWL,gBAAgB/C,SAAS,EAC7C2C,MAAMxF,SAAS,CAACkG,SAAS;IAG3B,oDAAoD;IACpDV,MAAMvF,KAAK,CAACiG,SAAS,OAAGrG,mBAAAA,EACtBC,iBAAiBG,KAAK,EACtB4F,oBACA3F,SAAS4F,WAAW,CAACE,cAAc,EACnCC,SAAS,WAAWH,YAAYjD,SAAS,EACzC2C,MAAMvF,KAAK,CAACiG,SAAS;IAGvB,IAAIV,MAAMtF,KAAK,EAAE;QACf,oDAAoD;QACpDsF,MAAMtF,KAAK,CAACgG,SAAS,OAAGrG,mBAAAA,EACtBC,iBAAiBI,KAAK,EACtB6F,YAAYpB,IAAI,EAChBoB,WAAW,CAACC,cAAc,EAC1BC,SAAS,WAAWF,YAAYlD,SAAS,EACzC2C,MAAMtF,KAAK,CAACgG,SAAS;IAEzB;IAEA,OAAOV;AACT,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-switch",
|
|
3
|
-
"version": "9.7.
|
|
3
|
+
"version": "9.7.3",
|
|
4
4
|
"description": "Fluent UI React Switch component.",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@fluentui/react-field": "^9.5.
|
|
15
|
+
"@fluentui/react-field": "^9.5.2",
|
|
16
16
|
"@fluentui/react-icons": "^2.0.245",
|
|
17
|
-
"@fluentui/react-jsx-runtime": "^9.4.
|
|
18
|
-
"@fluentui/react-label": "^9.4.
|
|
17
|
+
"@fluentui/react-jsx-runtime": "^9.4.3",
|
|
18
|
+
"@fluentui/react-label": "^9.4.2",
|
|
19
19
|
"@fluentui/react-shared-contexts": "^9.26.2",
|
|
20
|
-
"@fluentui/react-tabster": "^9.26.
|
|
20
|
+
"@fluentui/react-tabster": "^9.26.15",
|
|
21
21
|
"@fluentui/react-theme": "^9.2.1",
|
|
22
|
-
"@fluentui/react-utilities": "^9.26.
|
|
22
|
+
"@fluentui/react-utilities": "^9.26.4",
|
|
23
23
|
"@griffel/react": "^1.5.32",
|
|
24
24
|
"@swc/helpers": "^0.5.1"
|
|
25
25
|
},
|