@zohodesk/components 1.0.0-temp-220.10 → 1.0.0-temp-229
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/.cli/config/variables/variableMapping.json +8 -1
- package/.cli/propValidation_report.html +1 -1
- package/README.md +13 -0
- package/assets/Appearance/dark/mode/Component_v1_DarkMode.module.css +11 -0
- package/assets/Appearance/light/mode/Component_v1_LightMode.module.css +11 -0
- package/assets/Appearance/pureDark/mode/Component_v1_PureDarkMode.module.css +11 -0
- package/es/AppContainer/AppContainer.js +5 -4
- package/es/Card/Card.js +35 -8
- package/es/Card/props/defaultProps.js +2 -1
- package/es/Card/props/propTypes.js +2 -1
- package/es/Popup/Popup.js +92 -200
- package/es/Provider/Config.js +1 -2
- package/es/Provider/LibraryContext.js +7 -3
- package/es/deprecated/Switch/Switch.js +94 -0
- package/es/deprecated/Switch/props/defaultProps.js +11 -0
- package/es/deprecated/Switch/props/propTypes.js +28 -0
- package/es/v1/Switch/Switch.js +122 -78
- package/es/v1/Switch/__tests__/Switch.spec.js +30 -0
- package/es/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +135 -0
- package/es/v1/Switch/contants/index.js +24 -0
- package/es/v1/Switch/css/Switch_v1.module.css +134 -0
- package/es/v1/Switch/css/cssJSLogic.js +48 -0
- package/es/v1/Switch/props/defaultProps.js +8 -8
- package/es/v1/Switch/props/propTypes.js +30 -22
- package/es/v1/Switch/useSwitch.js +33 -0
- package/lib/AppContainer/AppContainer.js +7 -6
- package/lib/Card/Card.js +50 -23
- package/lib/Card/props/defaultProps.js +2 -1
- package/lib/Card/props/propTypes.js +2 -1
- package/lib/Popup/Popup.js +147 -272
- package/lib/Provider/Config.js +1 -2
- package/lib/Provider/LibraryContext.js +7 -3
- package/lib/deprecated/Switch/Switch.js +108 -0
- package/lib/deprecated/Switch/props/defaultProps.js +18 -0
- package/lib/deprecated/Switch/props/propTypes.js +39 -0
- package/lib/v1/Switch/Switch.js +130 -79
- package/lib/v1/Switch/__tests__/Switch.spec.js +37 -0
- package/lib/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +135 -0
- package/lib/v1/Switch/contants/index.js +34 -0
- package/lib/v1/Switch/css/Switch_v1.module.css +134 -0
- package/lib/v1/Switch/css/cssJSLogic.js +37 -0
- package/lib/v1/Switch/props/defaultProps.js +10 -10
- package/lib/v1/Switch/props/propTypes.js +32 -24
- package/lib/v1/Switch/useSwitch.js +56 -0
- package/package.json +10 -6
- package/es/Popup/Registry.js +0 -37
- package/lib/Popup/Registry.js +0 -47
- package/result.json +0 -1
package/es/v1/Switch/Switch.js
CHANGED
|
@@ -1,94 +1,138 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import
|
|
1
|
+
import React from 'react'; // props
|
|
2
|
+
|
|
3
|
+
import defaultProps from "./props/defaultProps";
|
|
4
|
+
import propTypes from "./props/propTypes"; // methods
|
|
5
|
+
|
|
6
|
+
import cssJSLogic from "./css/cssJSLogic";
|
|
7
|
+
import { mergeStyle } from '@zohodesk/utils'; // hooks
|
|
8
|
+
|
|
9
|
+
import useSwitch from "./useSwitch"; // constants
|
|
10
|
+
|
|
11
|
+
import { ALIGN_ITEMS, ITEMS_DIRECTION, OFF_LABEL_RADIUS, THUMB_RADIUS } from "./contants"; // components
|
|
12
|
+
|
|
13
|
+
import Flex from '@zohodesk/layout/es/Flex/Flex';
|
|
14
|
+
import Label from "../../Label/Label"; // css
|
|
15
|
+
|
|
16
|
+
import defaultStyle from "./css/Switch_v1.module.css";
|
|
7
17
|
|
|
8
18
|
const Switch = props => {
|
|
9
|
-
|
|
10
|
-
id,
|
|
19
|
+
const {
|
|
11
20
|
name,
|
|
12
21
|
value,
|
|
13
|
-
|
|
14
|
-
disabled,
|
|
15
|
-
isReadOnly,
|
|
22
|
+
id,
|
|
16
23
|
size,
|
|
17
|
-
|
|
24
|
+
isDisabled,
|
|
25
|
+
isReadOnly,
|
|
26
|
+
hasStateIndication,
|
|
27
|
+
label,
|
|
28
|
+
labelPlacement,
|
|
18
29
|
labelSize,
|
|
19
|
-
labelPalette,
|
|
20
30
|
title,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
customProps,
|
|
32
|
+
tagAttributes,
|
|
33
|
+
a11yAttributes,
|
|
34
|
+
i18nKeys,
|
|
35
|
+
customId,
|
|
36
|
+
testId,
|
|
37
|
+
customStyle
|
|
26
38
|
} = props;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
onChange
|
|
31
|
-
} = props;
|
|
32
|
-
onChange && onChange(!checked, e);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let {
|
|
36
|
-
SwitchProps = {},
|
|
37
|
-
LabelProps = {}
|
|
39
|
+
const {
|
|
40
|
+
container: customProps_container,
|
|
41
|
+
label: customProps_label
|
|
38
42
|
} = customProps;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
43
|
+
const {
|
|
44
|
+
container: tagAttributes_container,
|
|
45
|
+
switch: tagAttributes_switch
|
|
46
|
+
} = tagAttributes;
|
|
47
|
+
const {
|
|
48
|
+
container: a11yAttributes_container,
|
|
49
|
+
switch: a11yAttributes_switch = {},
|
|
50
|
+
label: a11yAttributes_label
|
|
51
|
+
} = a11yAttributes;
|
|
52
|
+
const {
|
|
53
|
+
ariaDisabled = isDisabled,
|
|
54
|
+
ariaLabel,
|
|
55
|
+
...restA11yAttributes_switch
|
|
56
|
+
} = a11yAttributes_switch;
|
|
57
|
+
const {
|
|
58
|
+
readOnlyAriaLabel: i18n_readOnlyAriaLabel = 'Read Only'
|
|
59
|
+
} = i18nKeys;
|
|
60
|
+
const readOnlyAriaLabel = label ? `${label}, ${i18n_readOnlyAriaLabel}` : i18n_readOnlyAriaLabel;
|
|
61
|
+
const {
|
|
62
|
+
isChecked,
|
|
63
|
+
handleChange
|
|
64
|
+
} = useSwitch(props);
|
|
65
|
+
const style = mergeStyle(defaultStyle, customStyle);
|
|
66
|
+
const {
|
|
67
|
+
containerClass,
|
|
68
|
+
labelClass,
|
|
69
|
+
trackClass,
|
|
70
|
+
trackWrapperClass,
|
|
71
|
+
thumbClass,
|
|
72
|
+
labelIndicationClass
|
|
73
|
+
} = cssJSLogic({
|
|
74
|
+
props: { ...props,
|
|
75
|
+
isChecked
|
|
76
|
+
},
|
|
77
|
+
style
|
|
78
|
+
});
|
|
79
|
+
return /*#__PURE__*/React.createElement(Flex, { ...customProps_container,
|
|
80
|
+
$ui_displayMode: "inline",
|
|
81
|
+
$ui_direction: ITEMS_DIRECTION[labelPlacement],
|
|
82
|
+
$ui_alignItems: ALIGN_ITEMS[labelPlacement],
|
|
83
|
+
$tagAttributes_container: { ...tagAttributes_container,
|
|
84
|
+
'data-selector-id': customId
|
|
85
|
+
},
|
|
86
|
+
testId: testId,
|
|
87
|
+
customId: customId,
|
|
88
|
+
$ui_className: containerClass,
|
|
89
|
+
$a11yAttributes_container: a11yAttributes_container
|
|
90
|
+
}, label && /*#__PURE__*/React.createElement(Label, { ...customProps_label,
|
|
91
|
+
text: label,
|
|
92
|
+
palette: isDisabled ? 'primary' : 'default',
|
|
93
|
+
size: labelSize,
|
|
94
|
+
htmlFor: id,
|
|
95
|
+
customClass: labelClass,
|
|
96
|
+
a11y: a11yAttributes_label,
|
|
97
|
+
clipped: true,
|
|
98
|
+
title: label
|
|
99
|
+
}), /*#__PURE__*/React.createElement(Flex, {
|
|
100
|
+
$flag_shrink: false,
|
|
101
|
+
$ui_className: trackWrapperClass
|
|
102
|
+
}, /*#__PURE__*/React.createElement("input", { ...tagAttributes_switch,
|
|
103
|
+
...restA11yAttributes_switch,
|
|
60
104
|
type: "checkbox",
|
|
61
105
|
id: id,
|
|
62
|
-
className: `${style.input} ${checked ? style.checked : ''}`,
|
|
63
106
|
name: name,
|
|
64
107
|
value: value,
|
|
65
|
-
checked:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
className:
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
108
|
+
checked: isChecked,
|
|
109
|
+
onChange: handleChange,
|
|
110
|
+
className: trackClass,
|
|
111
|
+
"data-title": title,
|
|
112
|
+
role: "switch",
|
|
113
|
+
"aria-disabled": ariaDisabled,
|
|
114
|
+
"aria-label": isReadOnly ? readOnlyAriaLabel : ariaLabel
|
|
115
|
+
}), /*#__PURE__*/React.createElement("svg", {
|
|
116
|
+
className: thumbClass,
|
|
117
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
118
|
+
}, /*#__PURE__*/React.createElement("circle", {
|
|
119
|
+
cx: "50%",
|
|
120
|
+
cy: "50%",
|
|
121
|
+
r: THUMB_RADIUS[size]
|
|
122
|
+
})), hasStateIndication ? /*#__PURE__*/React.createElement("svg", {
|
|
123
|
+
className: labelIndicationClass,
|
|
124
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
125
|
+
}, isChecked ? /*#__PURE__*/React.createElement("rect", {
|
|
126
|
+
width: "100%",
|
|
127
|
+
height: "100%",
|
|
128
|
+
rx: "50%"
|
|
129
|
+
}) : /*#__PURE__*/React.createElement("circle", {
|
|
130
|
+
cx: "50%",
|
|
131
|
+
cy: "50%",
|
|
132
|
+
r: OFF_LABEL_RADIUS[size]
|
|
133
|
+
})) : null));
|
|
85
134
|
};
|
|
86
135
|
|
|
136
|
+
export default Switch;
|
|
87
137
|
Switch.defaultProps = defaultProps;
|
|
88
|
-
Switch.propTypes = propTypes;
|
|
89
|
-
export default Switch; // if (__DOCS__) {
|
|
90
|
-
// Switch.docs = {
|
|
91
|
-
// componentGroup: 'Form Elements',
|
|
92
|
-
// folderName: 'Style Guide'
|
|
93
|
-
// };
|
|
94
|
-
// }
|
|
138
|
+
Switch.propTypes = propTypes;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import Switch from "../Switch";
|
|
4
|
+
describe('Switch', () => {
|
|
5
|
+
test('rendering the defult props', () => {
|
|
6
|
+
const {
|
|
7
|
+
asFragment
|
|
8
|
+
} = render( /*#__PURE__*/React.createElement(Switch, null));
|
|
9
|
+
expect(asFragment()).toMatchSnapshot();
|
|
10
|
+
});
|
|
11
|
+
test('rendering the Switch with Checked', () => {
|
|
12
|
+
const {
|
|
13
|
+
asFragment
|
|
14
|
+
} = render( /*#__PURE__*/React.createElement(Switch, {
|
|
15
|
+
id: "switch",
|
|
16
|
+
isChecked: true
|
|
17
|
+
}));
|
|
18
|
+
expect(asFragment()).toMatchSnapshot();
|
|
19
|
+
});
|
|
20
|
+
test('rendering the Switch with Disabled', () => {
|
|
21
|
+
const {
|
|
22
|
+
asFragment
|
|
23
|
+
} = render( /*#__PURE__*/React.createElement(Switch, {
|
|
24
|
+
id: "switch",
|
|
25
|
+
isChecked: true,
|
|
26
|
+
isDisabled: true
|
|
27
|
+
}));
|
|
28
|
+
expect(asFragment()).toMatchSnapshot();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Switch rendering the Switch with Checked 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class="inlineFlex row alignItems_center container medium checked enabled"
|
|
7
|
+
data-id="flex"
|
|
8
|
+
data-test-id="flex"
|
|
9
|
+
>
|
|
10
|
+
<div
|
|
11
|
+
class="noShrink trackWrapper"
|
|
12
|
+
data-id="flex"
|
|
13
|
+
data-test-id="flex"
|
|
14
|
+
>
|
|
15
|
+
<input
|
|
16
|
+
checked=""
|
|
17
|
+
class="track"
|
|
18
|
+
id="switch"
|
|
19
|
+
role="switch"
|
|
20
|
+
type="checkbox"
|
|
21
|
+
value=""
|
|
22
|
+
/>
|
|
23
|
+
<svg
|
|
24
|
+
class="thumb commonSvg"
|
|
25
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
26
|
+
>
|
|
27
|
+
<circle
|
|
28
|
+
cx="50%"
|
|
29
|
+
cy="50%"
|
|
30
|
+
r="42.85%"
|
|
31
|
+
/>
|
|
32
|
+
</svg>
|
|
33
|
+
<svg
|
|
34
|
+
class="onLabel commonSvg"
|
|
35
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
36
|
+
>
|
|
37
|
+
<rect
|
|
38
|
+
height="100%"
|
|
39
|
+
rx="50%"
|
|
40
|
+
width="100%"
|
|
41
|
+
/>
|
|
42
|
+
</svg>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</DocumentFragment>
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
exports[`Switch rendering the Switch with Disabled 1`] = `
|
|
49
|
+
<DocumentFragment>
|
|
50
|
+
<div
|
|
51
|
+
class="inlineFlex row alignItems_center container medium checked disabled"
|
|
52
|
+
data-id="flex"
|
|
53
|
+
data-test-id="flex"
|
|
54
|
+
>
|
|
55
|
+
<div
|
|
56
|
+
class="noShrink trackWrapper"
|
|
57
|
+
data-id="flex"
|
|
58
|
+
data-test-id="flex"
|
|
59
|
+
>
|
|
60
|
+
<input
|
|
61
|
+
aria-disabled="true"
|
|
62
|
+
checked=""
|
|
63
|
+
class="track"
|
|
64
|
+
id="switch"
|
|
65
|
+
role="switch"
|
|
66
|
+
type="checkbox"
|
|
67
|
+
value=""
|
|
68
|
+
/>
|
|
69
|
+
<svg
|
|
70
|
+
class="thumb commonSvg"
|
|
71
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
72
|
+
>
|
|
73
|
+
<circle
|
|
74
|
+
cx="50%"
|
|
75
|
+
cy="50%"
|
|
76
|
+
r="42.85%"
|
|
77
|
+
/>
|
|
78
|
+
</svg>
|
|
79
|
+
<svg
|
|
80
|
+
class="onLabel commonSvg"
|
|
81
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
82
|
+
>
|
|
83
|
+
<rect
|
|
84
|
+
height="100%"
|
|
85
|
+
rx="50%"
|
|
86
|
+
width="100%"
|
|
87
|
+
/>
|
|
88
|
+
</svg>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
</DocumentFragment>
|
|
92
|
+
`;
|
|
93
|
+
|
|
94
|
+
exports[`Switch rendering the defult props 1`] = `
|
|
95
|
+
<DocumentFragment>
|
|
96
|
+
<div
|
|
97
|
+
class="inlineFlex row alignItems_center container medium unChecked enabled"
|
|
98
|
+
data-id="flex"
|
|
99
|
+
data-test-id="flex"
|
|
100
|
+
>
|
|
101
|
+
<div
|
|
102
|
+
class="noShrink trackWrapper"
|
|
103
|
+
data-id="flex"
|
|
104
|
+
data-test-id="flex"
|
|
105
|
+
>
|
|
106
|
+
<input
|
|
107
|
+
class="track"
|
|
108
|
+
role="switch"
|
|
109
|
+
type="checkbox"
|
|
110
|
+
value=""
|
|
111
|
+
/>
|
|
112
|
+
<svg
|
|
113
|
+
class="thumb commonSvg"
|
|
114
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
115
|
+
>
|
|
116
|
+
<circle
|
|
117
|
+
cx="50%"
|
|
118
|
+
cy="50%"
|
|
119
|
+
r="42.85%"
|
|
120
|
+
/>
|
|
121
|
+
</svg>
|
|
122
|
+
<svg
|
|
123
|
+
class="offLabel commonSvg"
|
|
124
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
125
|
+
>
|
|
126
|
+
<circle
|
|
127
|
+
cx="50%"
|
|
128
|
+
cy="50%"
|
|
129
|
+
r="37.5%"
|
|
130
|
+
/>
|
|
131
|
+
</svg>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
</DocumentFragment>
|
|
135
|
+
`;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const OFF_LABEL_RADIUS = {
|
|
2
|
+
small: '35.7%',
|
|
3
|
+
medium: '37.5%',
|
|
4
|
+
large: '38.9%',
|
|
5
|
+
xlarge: '40%'
|
|
6
|
+
};
|
|
7
|
+
export const THUMB_RADIUS = {
|
|
8
|
+
small: '40%',
|
|
9
|
+
medium: '42.85%',
|
|
10
|
+
large: '44.45%',
|
|
11
|
+
xlarge: '45.45%'
|
|
12
|
+
};
|
|
13
|
+
export const ITEMS_DIRECTION = {
|
|
14
|
+
start: 'row',
|
|
15
|
+
end: 'rowReverse',
|
|
16
|
+
top: 'column',
|
|
17
|
+
bottom: 'columnReverse'
|
|
18
|
+
};
|
|
19
|
+
export const ALIGN_ITEMS = {
|
|
20
|
+
start: 'center',
|
|
21
|
+
end: 'center',
|
|
22
|
+
top: 'start',
|
|
23
|
+
bottom: 'start'
|
|
24
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
.container {
|
|
2
|
+
--local-switch-cursor: pointer;
|
|
3
|
+
--local-switch-offLabel-stroke: var(--zdt_v1_switch_offLabel);
|
|
4
|
+
gap: var(--zd_size6) ;
|
|
5
|
+
}
|
|
6
|
+
.small {
|
|
7
|
+
--local-switch-track-width: var(--zd_size22);
|
|
8
|
+
--local-switch-track-height: var(--zd_size12);
|
|
9
|
+
--local-switch-track-border-radius: 8px;
|
|
10
|
+
--local-switch-thumb-size: var(--zd_size10);
|
|
11
|
+
--local-switch-onLabel-height: var(--zd_size6);
|
|
12
|
+
--local-switch-onLabel-left: var(--zd_size5);
|
|
13
|
+
--local-switch-offLabel-size: var(--zd_size7);
|
|
14
|
+
--local-switch-offLabel-right: var(--zd_size2);
|
|
15
|
+
--local-switch-onLabel-scaleX: 1.2;
|
|
16
|
+
}
|
|
17
|
+
.medium {
|
|
18
|
+
--local-switch-track-width: var(--zd_size28);
|
|
19
|
+
--local-switch-track-height: var(--zd_size16);
|
|
20
|
+
--local-switch-track-border-radius: 16px;
|
|
21
|
+
--local-switch-thumb-size: var(--zd_size14);
|
|
22
|
+
--local-switch-onLabel-height: var(--zd_size8);
|
|
23
|
+
--local-switch-onLabel-left: var(--zd_size6);
|
|
24
|
+
--local-switch-offLabel-size: var(--zd_size8);
|
|
25
|
+
--local-switch-offLabel-right: var(--zd_size3);
|
|
26
|
+
--local-switch-onLabel-scaleX: 1.4;
|
|
27
|
+
}
|
|
28
|
+
.large {
|
|
29
|
+
--local-switch-track-width: var(--zd_size34);
|
|
30
|
+
--local-switch-track-height: var(--zd_size20);
|
|
31
|
+
--local-switch-track-border-radius: 10px;
|
|
32
|
+
--local-switch-thumb-size: var(--zd_size18);
|
|
33
|
+
--local-switch-onLabel-height: var(--zd_size10);
|
|
34
|
+
--local-switch-onLabel-left: var(--zd_size7);
|
|
35
|
+
--local-switch-offLabel-size: var(--zd_size9);
|
|
36
|
+
--local-switch-offLabel-right: var(--zd_size4);
|
|
37
|
+
--local-switch-onLabel-scaleX: 1.6;
|
|
38
|
+
}
|
|
39
|
+
.xlarge {
|
|
40
|
+
--local-switch-track-width: var(--zd_size40);
|
|
41
|
+
--local-switch-track-height: var(--zd_size24);
|
|
42
|
+
--local-switch-track-border-radius: 12px;
|
|
43
|
+
--local-switch-thumb-size: var(--zd_size22);
|
|
44
|
+
--local-switch-onLabel-height: var(--zd_size12);
|
|
45
|
+
--local-switch-onLabel-left: var(--zd_size8);
|
|
46
|
+
--local-switch-offLabel-size: var(--zd_size10);
|
|
47
|
+
--local-switch-offLabel-right: var(--zd_size5);
|
|
48
|
+
--local-switch-onLabel-scaleX: 1.8;
|
|
49
|
+
}
|
|
50
|
+
.disabled, .readonly {
|
|
51
|
+
--local-switch-cursor: not-allowed;
|
|
52
|
+
}
|
|
53
|
+
.checked.enabled > .trackWrapper:hover {
|
|
54
|
+
--local-switch-track-background-color: var(--zdt_v1_switch_track_on_hover_bg);
|
|
55
|
+
}
|
|
56
|
+
.unChecked.enabled > .trackWrapper:hover {
|
|
57
|
+
--local-switch-track-background-color: var(--zdt_v1_switch_track_off_hover_bg);
|
|
58
|
+
}
|
|
59
|
+
.enabled > .trackWrapper:hover {
|
|
60
|
+
--local-switch-offLabel-stroke: var(--zdt_v1_switch_offLabel_hover);
|
|
61
|
+
}
|
|
62
|
+
.trackWrapper {
|
|
63
|
+
position: relative;
|
|
64
|
+
}
|
|
65
|
+
.disabled > .trackWrapper {
|
|
66
|
+
opacity: 0.4;
|
|
67
|
+
}
|
|
68
|
+
.track {
|
|
69
|
+
appearance: none;
|
|
70
|
+
display: block;
|
|
71
|
+
position: relative;
|
|
72
|
+
height: var(--local-switch-track-height);
|
|
73
|
+
width: var(--local-switch-track-width);
|
|
74
|
+
margin: 0 ;
|
|
75
|
+
border-radius: var(--local-switch-track-border-radius);
|
|
76
|
+
background-color: var(--local-switch-track-background-color);
|
|
77
|
+
cursor: var(--local-switch-cursor);
|
|
78
|
+
}
|
|
79
|
+
.commonSvg {
|
|
80
|
+
display: block;
|
|
81
|
+
position: absolute;
|
|
82
|
+
pointer-events: none;
|
|
83
|
+
top: 50% ;
|
|
84
|
+
}
|
|
85
|
+
.thumb {
|
|
86
|
+
transition: transform var(--zd_transition2) cubic-bezier(0.4, 0, 0.2, 1);
|
|
87
|
+
fill: var(--zdt_v1_switch_thumb_bg);
|
|
88
|
+
height: var(--local-switch-thumb-size);
|
|
89
|
+
width: var(--local-switch-thumb-size);
|
|
90
|
+
transform: translateX(var(--local-switch-thumb-translateX)) translateY(-50%);
|
|
91
|
+
}
|
|
92
|
+
[dir=ltr] .thumb {
|
|
93
|
+
left: var(--zd_size1) ;
|
|
94
|
+
}
|
|
95
|
+
[dir=rtl] .thumb {
|
|
96
|
+
right: var(--zd_size1) ;
|
|
97
|
+
}
|
|
98
|
+
.label {
|
|
99
|
+
max-width: 100% ;
|
|
100
|
+
cursor: var(--local-switch-cursor);
|
|
101
|
+
}
|
|
102
|
+
.onLabel {
|
|
103
|
+
height: var(--local-switch-onLabel-height);
|
|
104
|
+
fill: var(--zdt_v1_switch_onLabel);
|
|
105
|
+
width: var(--zd_size1) ;
|
|
106
|
+
transform: translateY(-50%) scaleX(var(--local-switch-onLabel-scaleX));
|
|
107
|
+
}
|
|
108
|
+
[dir=ltr] .onLabel {
|
|
109
|
+
left: var(--local-switch-onLabel-left);
|
|
110
|
+
}
|
|
111
|
+
[dir=rtl] .onLabel {
|
|
112
|
+
right: var(--local-switch-onLabel-left);
|
|
113
|
+
}
|
|
114
|
+
.offLabel {
|
|
115
|
+
height: var(--local-switch-offLabel-size);
|
|
116
|
+
width: var(--local-switch-offLabel-size);
|
|
117
|
+
fill: transparent;
|
|
118
|
+
stroke: var(--local-switch-offLabel-stroke);
|
|
119
|
+
transform: translateY(-50%);
|
|
120
|
+
}
|
|
121
|
+
[dir=ltr] .offLabel {
|
|
122
|
+
right: var(--local-switch-offLabel-right);
|
|
123
|
+
}
|
|
124
|
+
[dir=rtl] .offLabel {
|
|
125
|
+
left: var(--local-switch-offLabel-right);
|
|
126
|
+
}
|
|
127
|
+
.checked {
|
|
128
|
+
--local-switch-track-background-color: var(--zdt_v1_switch_track_on_bg);
|
|
129
|
+
--local-switch-thumb-translateX: calc(var(--local-switch-track-width) - var(--local-switch-thumb-size) - 2px)
|
|
130
|
+
}
|
|
131
|
+
.unChecked {
|
|
132
|
+
--local-switch-track-background-color: var(--zdt_v1_switch_track_off_bg);
|
|
133
|
+
--local-switch-thumb-translateX: 0;
|
|
134
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import compileClassNames from '@zohodesk/utils/es/compileClassNames';
|
|
2
|
+
export default function cssJSLogic(_ref) {
|
|
3
|
+
let {
|
|
4
|
+
props,
|
|
5
|
+
style
|
|
6
|
+
} = _ref;
|
|
7
|
+
const {
|
|
8
|
+
size,
|
|
9
|
+
isChecked,
|
|
10
|
+
isDisabled,
|
|
11
|
+
isReadOnly
|
|
12
|
+
} = props;
|
|
13
|
+
let containerClass = compileClassNames({
|
|
14
|
+
[style.container]: true,
|
|
15
|
+
[style[size]]: !!style[size],
|
|
16
|
+
[style.checked]: isChecked,
|
|
17
|
+
[style.unChecked]: !isChecked,
|
|
18
|
+
[style.disabled]: isDisabled,
|
|
19
|
+
[style.enabled]: !isDisabled,
|
|
20
|
+
[style.readonly]: isReadOnly
|
|
21
|
+
});
|
|
22
|
+
let trackClass = compileClassNames({
|
|
23
|
+
[style.track]: true
|
|
24
|
+
});
|
|
25
|
+
let labelClass = compileClassNames({
|
|
26
|
+
[style.label]: true
|
|
27
|
+
});
|
|
28
|
+
let trackWrapperClass = compileClassNames({
|
|
29
|
+
[style.trackWrapper]: true
|
|
30
|
+
});
|
|
31
|
+
let thumbClass = compileClassNames({
|
|
32
|
+
[style.thumb]: true,
|
|
33
|
+
[style.commonSvg]: true
|
|
34
|
+
});
|
|
35
|
+
let labelIndicationClass = compileClassNames({
|
|
36
|
+
[style.onLabel]: isChecked,
|
|
37
|
+
[style.offLabel]: !isChecked,
|
|
38
|
+
[style.commonSvg]: true
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
containerClass,
|
|
42
|
+
trackClass,
|
|
43
|
+
labelClass,
|
|
44
|
+
trackWrapperClass,
|
|
45
|
+
thumbClass,
|
|
46
|
+
labelIndicationClass
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
checked: false,
|
|
3
|
-
disabled: false,
|
|
4
|
-
labelPalette: 'primary',
|
|
5
|
-
labelSize: 'medium',
|
|
1
|
+
export default {
|
|
6
2
|
size: 'medium',
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
hasStateIndication: true,
|
|
4
|
+
labelPlacement: 'start',
|
|
5
|
+
labelSize: 'medium',
|
|
9
6
|
customProps: {},
|
|
10
|
-
|
|
7
|
+
tagAttributes: {},
|
|
8
|
+
a11yAttributes: {},
|
|
9
|
+
i18nKeys: {},
|
|
10
|
+
customStyle: {}
|
|
11
11
|
};
|
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
|
-
export
|
|
3
|
-
checked: PropTypes.bool,
|
|
4
|
-
dataId: PropTypes.string,
|
|
5
|
-
dataSelectorId: PropTypes.string,
|
|
6
|
-
disableTitle: PropTypes.string,
|
|
7
|
-
disabled: PropTypes.bool,
|
|
8
|
-
id: PropTypes.string.isRequired,
|
|
9
|
-
isReadOnly: PropTypes.bool,
|
|
10
|
-
labelPalette: PropTypes.oneOf(['default', 'primary', 'secondary', 'danger', 'mandatory']),
|
|
11
|
-
labelSize: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
2
|
+
export default {
|
|
12
3
|
name: PropTypes.string,
|
|
4
|
+
value: PropTypes.string,
|
|
5
|
+
id: PropTypes.string,
|
|
6
|
+
size: PropTypes.oneOf(['small', 'medium', 'large', 'xlarge']),
|
|
7
|
+
isChecked: PropTypes.bool,
|
|
8
|
+
isDefaultChecked: PropTypes.bool,
|
|
9
|
+
isDisabled: PropTypes.bool,
|
|
10
|
+
isReadOnly: PropTypes.bool,
|
|
13
11
|
onChange: PropTypes.func,
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
hasStateIndication: PropTypes.bool,
|
|
13
|
+
label: PropTypes.string,
|
|
14
|
+
labelPlacement: PropTypes.oneOf(['start', 'end', 'top', 'bottom']),
|
|
15
|
+
labelSize: PropTypes.oneOf(['xsmall', 'small', 'medium', 'large']),
|
|
16
16
|
title: PropTypes.string,
|
|
17
|
-
value: PropTypes.bool,
|
|
18
|
-
customClass: PropTypes.shape({
|
|
19
|
-
customSwitchWrap: PropTypes.string,
|
|
20
|
-
customSwitch: PropTypes.string,
|
|
21
|
-
customSwitchSize: PropTypes.string,
|
|
22
|
-
customLabel: PropTypes.string
|
|
23
|
-
}),
|
|
24
17
|
customProps: PropTypes.shape({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
18
|
+
container: PropTypes.object,
|
|
19
|
+
label: PropTypes.object
|
|
20
|
+
}),
|
|
21
|
+
tagAttributes: PropTypes.shape({
|
|
22
|
+
container: PropTypes.object,
|
|
23
|
+
switch: PropTypes.object
|
|
24
|
+
}),
|
|
25
|
+
a11yAttributes: PropTypes.shape({
|
|
26
|
+
container: PropTypes.object,
|
|
27
|
+
switch: PropTypes.object,
|
|
28
|
+
label: PropTypes.object
|
|
29
|
+
}),
|
|
30
|
+
i18nKeys: PropTypes.shape({
|
|
31
|
+
readOnlyAriaLabel: PropTypes.string
|
|
32
|
+
}),
|
|
33
|
+
customId: PropTypes.string,
|
|
34
|
+
testId: PropTypes.string,
|
|
35
|
+
customStyle: PropTypes.object
|
|
28
36
|
};
|