@fluentui/react-switch 0.0.0-nightlya0ab3454ed20211208.1 → 0.0.0-nightlya0aef7969220220228.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +171 -21
- package/CHANGELOG.md +47 -12
- package/dist/react-switch.d.ts +59 -47
- package/lib/Switch.js.map +1 -1
- package/lib/components/Switch/Switch.d.ts +1 -1
- package/lib/components/Switch/Switch.js +7 -7
- package/lib/components/Switch/Switch.js.map +1 -1
- package/lib/components/Switch/Switch.types.d.ts +44 -37
- package/lib/components/Switch/Switch.types.js.map +1 -1
- package/lib/components/Switch/index.js.map +1 -1
- package/lib/components/Switch/renderSwitch.d.ts +2 -2
- package/lib/components/Switch/renderSwitch.js +12 -5
- package/lib/components/Switch/renderSwitch.js.map +1 -1
- package/lib/components/Switch/useSwitch.d.ts +9 -7
- package/lib/components/Switch/useSwitch.js +64 -49
- package/lib/components/Switch/useSwitch.js.map +1 -1
- package/lib/components/Switch/useSwitchStyles.d.ts +6 -3
- package/lib/components/Switch/useSwitchStyles.js +150 -282
- package/lib/components/Switch/useSwitchStyles.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/Switch.js.map +1 -1
- package/lib-commonjs/components/Switch/Switch.d.ts +1 -1
- package/lib-commonjs/components/Switch/Switch.js +4 -4
- package/lib-commonjs/components/Switch/Switch.js.map +1 -1
- package/lib-commonjs/components/Switch/Switch.types.d.ts +44 -37
- package/lib-commonjs/components/Switch/Switch.types.js.map +1 -1
- package/lib-commonjs/components/Switch/index.js.map +1 -1
- package/lib-commonjs/components/Switch/renderSwitch.d.ts +2 -2
- package/lib-commonjs/components/Switch/renderSwitch.js +14 -8
- package/lib-commonjs/components/Switch/renderSwitch.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitch.d.ts +9 -7
- package/lib-commonjs/components/Switch/useSwitch.js +67 -50
- package/lib-commonjs/components/Switch/useSwitch.js.map +1 -1
- package/lib-commonjs/components/Switch/useSwitchStyles.d.ts +6 -3
- package/lib-commonjs/components/Switch/useSwitchStyles.js +155 -286
- package/lib-commonjs/components/Switch/useSwitchStyles.js.map +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +9 -9
- package/lib/components/Switch/useSwitchState.d.ts +0 -2
- package/lib/components/Switch/useSwitchState.js +0 -144
- package/lib/components/Switch/useSwitchState.js.map +0 -1
- package/lib-commonjs/components/Switch/useSwitchState.d.ts +0 -2
- package/lib-commonjs/components/Switch/useSwitchState.js +0 -156
- package/lib-commonjs/components/Switch/useSwitchState.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Switch/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC","sourcesContent":["export * from './Switch';\nexport * from './Switch.types';\nexport * from './renderSwitch';\nexport * from './useSwitch';\nexport * from './useSwitchStyles';\n"]}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { SwitchState } from './Switch.types';
|
2
2
|
/**
|
3
|
-
* Render the
|
3
|
+
* Render a Switch component by passing the state defined props to the appropriate slots.
|
4
4
|
*/
|
5
|
-
export declare const
|
5
|
+
export declare const renderSwitch_unstable: (state: SwitchState) => JSX.Element;
|
@@ -1,15 +1,22 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { getSlots } from '@fluentui/react-utilities';
|
3
|
-
import { switchShorthandProps } from './useSwitch';
|
4
3
|
/**
|
5
|
-
* Render the
|
4
|
+
* Render a Switch component by passing the state defined props to the appropriate slots.
|
6
5
|
*/
|
7
6
|
|
8
|
-
export const
|
7
|
+
export const renderSwitch_unstable = state => {
|
9
8
|
const {
|
10
9
|
slots,
|
11
10
|
slotProps
|
12
|
-
} = getSlots(state
|
13
|
-
|
11
|
+
} = getSlots(state);
|
12
|
+
const {
|
13
|
+
labelPosition
|
14
|
+
} = state;
|
15
|
+
return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
16
|
+
}, /*#__PURE__*/React.createElement(slots.input, { ...slotProps.input
|
17
|
+
}), labelPosition !== 'after' && slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
|
18
|
+
}), /*#__PURE__*/React.createElement(slots.indicator, { ...slotProps.indicator
|
19
|
+
}), labelPosition === 'after' && slots.label && /*#__PURE__*/React.createElement(slots.label, { ...slotProps.label
|
20
|
+
}));
|
14
21
|
};
|
15
22
|
//# sourceMappingURL=renderSwitch.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["components/Switch/renderSwitch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,qBAAqB,GAAI,KAAD,IAAuB;AAC1D,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,QAAQ,CAAc,KAAd,CAArC;AACA,QAAM;AAAE,IAAA;AAAF,MAAoB,KAA1B;AAEA,sBACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;AAAf,GAAX,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CADF,EAEG,aAAa,KAAK,OAAlB,IAA6B,KAAK,CAAC,KAAnC,iBAA4C,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CAF/C,eAGE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,SAAP,EAAgB,EAAA,GAAK,SAAS,CAAC;AAAf,GAAhB,CAHF,EAIG,aAAa,KAAK,OAAlB,IAA6B,KAAK,CAAC,KAAnC,iBAA4C,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CAJ/C,CADF;AAQD,CAZM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { SwitchState, SwitchSlots } from './Switch.types';\n\n/**\n * Render a Switch component by passing the state defined props to the appropriate slots.\n */\nexport const renderSwitch_unstable = (state: SwitchState) => {\n const { slots, slotProps } = getSlots<SwitchSlots>(state);\n const { labelPosition } = state;\n\n return (\n <slots.root {...slotProps.root}>\n <slots.input {...slotProps.input} />\n {labelPosition !== 'after' && slots.label && <slots.label {...slotProps.label} />}\n <slots.indicator {...slotProps.indicator} />\n {labelPosition === 'after' && slots.label && <slots.label {...slotProps.label} />}\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -1,10 +1,12 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import type { SwitchProps,
|
2
|
+
import type { SwitchProps, SwitchState } from './Switch.types';
|
3
3
|
/**
|
4
|
-
*
|
4
|
+
* Create the state required to render Switch.
|
5
|
+
*
|
6
|
+
* The returned state can be modified with hooks such as useSwitchStyles_unstable,
|
7
|
+
* before being passed to renderSwitch_unstable.
|
8
|
+
*
|
9
|
+
* @param props - props from this instance of Switch
|
10
|
+
* @param ref - reference to `<input>` element of Switch
|
5
11
|
*/
|
6
|
-
export declare const
|
7
|
-
/**
|
8
|
-
* Given user props, returns state and render function for a Switch.
|
9
|
-
*/
|
10
|
-
export declare const useSwitch: (props: SwitchProps, ref: React.Ref<HTMLElement>) => SwitchState;
|
12
|
+
export declare const useSwitch_unstable: (props: SwitchProps, ref: React.Ref<HTMLInputElement>) => SwitchState;
|
@@ -1,64 +1,79 @@
|
|
1
|
-
import
|
2
|
-
import {
|
1
|
+
import * as React from 'react';
|
2
|
+
import { CircleFilled } from '@fluentui/react-icons';
|
3
|
+
import { Label } from '@fluentui/react-label';
|
4
|
+
import { getPartitionedNativeProps, resolveShorthand, useId, useMergedEventCallbacks } from '@fluentui/react-utilities';
|
3
5
|
/**
|
4
|
-
*
|
6
|
+
* Create the state required to render Switch.
|
7
|
+
*
|
8
|
+
* The returned state can be modified with hooks such as useSwitchStyles_unstable,
|
9
|
+
* before being passed to renderSwitch_unstable.
|
10
|
+
*
|
11
|
+
* @param props - props from this instance of Switch
|
12
|
+
* @param ref - reference to `<input>` element of Switch
|
5
13
|
*/
|
6
14
|
|
7
|
-
export const
|
8
|
-
/**
|
9
|
-
* Given user props, returns state and render function for a Switch.
|
10
|
-
*/
|
11
|
-
|
12
|
-
export const useSwitch = (props, ref) => {
|
15
|
+
export const useSwitch_unstable = (props, ref) => {
|
13
16
|
const {
|
14
|
-
track,
|
15
|
-
thumbWrapper,
|
16
|
-
thumb,
|
17
|
-
activeRail,
|
18
|
-
input,
|
19
|
-
defaultChecked,
|
20
17
|
checked,
|
21
|
-
disabled,
|
22
|
-
onChange
|
23
|
-
} = props;
|
24
|
-
const state = {
|
25
18
|
defaultChecked,
|
26
|
-
checked,
|
27
19
|
disabled,
|
20
|
+
labelPosition = 'after',
|
28
21
|
onChange,
|
29
|
-
|
22
|
+
required
|
23
|
+
} = props;
|
24
|
+
const nativeProps = getPartitionedNativeProps({
|
25
|
+
props,
|
26
|
+
primarySlotTagName: 'input',
|
27
|
+
excludedPropNames: ['checked', 'defaultChecked', 'onChange']
|
28
|
+
});
|
29
|
+
const id = useId('switch-', nativeProps.primary.id);
|
30
|
+
const root = resolveShorthand(props.root, {
|
31
|
+
defaultProps: nativeProps.root,
|
32
|
+
required: true
|
33
|
+
});
|
34
|
+
const indicator = resolveShorthand(props.indicator, {
|
35
|
+
defaultProps: {
|
36
|
+
'aria-hidden': true,
|
37
|
+
children: /*#__PURE__*/React.createElement(CircleFilled, null)
|
38
|
+
},
|
39
|
+
required: true
|
40
|
+
});
|
41
|
+
const input = resolveShorthand(props.input, {
|
42
|
+
defaultProps: {
|
43
|
+
checked,
|
44
|
+
defaultChecked,
|
45
|
+
id,
|
30
46
|
ref,
|
31
|
-
|
32
|
-
|
33
|
-
|
47
|
+
role: 'switch',
|
48
|
+
type: 'checkbox',
|
49
|
+
...nativeProps.primary
|
50
|
+
},
|
51
|
+
required: true
|
52
|
+
});
|
53
|
+
input.onChange = useMergedEventCallbacks(input.onChange, ev => onChange === null || onChange === void 0 ? void 0 : onChange(ev, {
|
54
|
+
checked: ev.currentTarget.checked
|
55
|
+
}));
|
56
|
+
const label = resolveShorthand(props.label, {
|
57
|
+
defaultProps: {
|
58
|
+
disabled,
|
59
|
+
htmlFor: id,
|
60
|
+
required,
|
61
|
+
size: 'medium'
|
62
|
+
}
|
63
|
+
});
|
64
|
+
return {
|
65
|
+
labelPosition,
|
66
|
+
//Slots definition
|
34
67
|
components: {
|
35
68
|
root: 'div',
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
activeRail: 'div',
|
40
|
-
input: 'input'
|
69
|
+
indicator: 'div',
|
70
|
+
input: 'input',
|
71
|
+
label: Label
|
41
72
|
},
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
required: true
|
47
|
-
}),
|
48
|
-
thumb: resolveShorthand(thumb, {
|
49
|
-
required: true
|
50
|
-
}),
|
51
|
-
activeRail: resolveShorthand(activeRail, {
|
52
|
-
required: true
|
53
|
-
}),
|
54
|
-
input: resolveShorthand(input, {
|
55
|
-
required: true,
|
56
|
-
defaultProps: {
|
57
|
-
type: 'checkbox'
|
58
|
-
}
|
59
|
-
})
|
73
|
+
root,
|
74
|
+
indicator,
|
75
|
+
input,
|
76
|
+
label
|
60
77
|
};
|
61
|
-
useSwitchState(state);
|
62
|
-
return state;
|
63
78
|
};
|
64
79
|
//# sourceMappingURL=useSwitch.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["components/Switch/useS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,MAAA,EAHY;AAIZ,MAAA,GAJY;AAKZ,MAAA,IAAI,EAAE,QALM;AAMZ,MAAA,IAAI,EAAE,UANM;AAOZ,SAAG,WAAW,CAAC;AAPH,KAD4B;AAU1C,IAAA,QAAQ,EAAE;AAVgC,GAAd,CAA9B;AAYA,EAAA,KAAK,CAAC,QAAN,GAAiB,uBAAuB,CAAC,KAAK,CAAC,QAAP,EAAiB,EAAE,IAAI,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAQ,KAAA,CAAR,GAAA,QAAQ,CAAG,EAAH,EAAO;AAAE,IAAA,OAAO,EAAE,EAAE,CAAC,aAAH,CAAiB;AAA5B,GAAP,CAA/B,CAAxC;AAEA,QAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAP,EAAc;AAC1C,IAAA,YAAY,EAAE;AACZ,MAAA,QADY;AAEZ,MAAA,OAAO,EAAE,EAFG;AAGZ,MAAA,QAHY;AAIZ,MAAA,IAAI,EAAE;AAJM;AAD4B,GAAd,CAA9B;AASA,SAAO;AACL,IAAA,aADK;AAGL;AACA,IAAA,UAAU,EAAE;AACV,MAAA,IAAI,EAAE,KADI;AAEV,MAAA,SAAS,EAAE,KAFD;AAGV,MAAA,KAAK,EAAE,OAHG;AAIV,MAAA,KAAK,EAAE;AAJG,KAJP;AAWL,IAAA,IAXK;AAYL,IAAA,SAZK;AAaL,IAAA,KAbK;AAcL,IAAA;AAdK,GAAP;AAgBD,CA/DM","sourcesContent":["import * as React from 'react';\nimport { CircleFilled } from '@fluentui/react-icons';\nimport { Label } from '@fluentui/react-label';\nimport { getPartitionedNativeProps, resolveShorthand, useId, useMergedEventCallbacks } from '@fluentui/react-utilities';\nimport type { SwitchProps, SwitchState } from './Switch.types';\n\n/**\n * Create the state required to render Switch.\n *\n * The returned state can be modified with hooks such as useSwitchStyles_unstable,\n * before being passed to renderSwitch_unstable.\n *\n * @param props - props from this instance of Switch\n * @param ref - reference to `<input>` element of Switch\n */\nexport const useSwitch_unstable = (props: SwitchProps, ref: React.Ref<HTMLInputElement>): SwitchState => {\n const { checked, defaultChecked, disabled, labelPosition = 'after', onChange, required } = props;\n\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['checked', 'defaultChecked', 'onChange'],\n });\n\n const id = useId('switch-', nativeProps.primary.id);\n\n const root = resolveShorthand(props.root, {\n defaultProps: nativeProps.root,\n required: true,\n });\n\n const indicator = resolveShorthand(props.indicator, {\n defaultProps: {\n 'aria-hidden': true,\n children: <CircleFilled />,\n },\n required: true,\n });\n\n const input = resolveShorthand(props.input, {\n defaultProps: {\n checked,\n defaultChecked,\n id,\n ref,\n role: 'switch',\n type: 'checkbox',\n ...nativeProps.primary,\n },\n required: true,\n });\n input.onChange = useMergedEventCallbacks(input.onChange, ev => onChange?.(ev, { checked: ev.currentTarget.checked }));\n\n const label = resolveShorthand(props.label, {\n defaultProps: {\n disabled,\n htmlFor: id,\n required,\n size: 'medium',\n },\n });\n\n return {\n labelPosition,\n\n //Slots definition\n components: {\n root: 'div',\n indicator: 'div',\n input: 'input',\n label: Label,\n },\n\n root,\n indicator,\n input,\n label,\n };\n};\n"],"sourceRoot":"../src/"}
|
@@ -1,6 +1,9 @@
|
|
1
|
-
import type { SwitchState } from './Switch.types';
|
2
|
-
export declare const
|
1
|
+
import type { SwitchSlots, SwitchState } from './Switch.types';
|
2
|
+
export declare const switchClassNames: {
|
3
|
+
[SlotName in keyof SwitchSlots]-?: string;
|
4
|
+
};
|
5
|
+
export declare const switchClassName: string;
|
3
6
|
/**
|
4
7
|
* Apply styling to the Switch slots based on the state
|
5
8
|
*/
|
6
|
-
export declare const
|
9
|
+
export declare const useSwitchStyles_unstable: (state: SwitchState) => SwitchState;
|