@zohodesk/components 1.3.4 → 1.4.0
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 +9 -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/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 +120 -78
- package/es/v1/Switch/__tests__/Switch.spec.js +30 -0
- package/es/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +137 -0
- package/es/v1/Switch/contants/index.js +18 -0
- package/es/v1/Switch/css/Switch_v1.module.css +133 -0
- package/es/v1/Switch/css/cssJSLogic.js +48 -0
- package/es/v1/Switch/props/defaultProps.js +10 -7
- 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/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 +128 -79
- package/lib/v1/Switch/__tests__/Switch.spec.js +37 -0
- package/lib/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +137 -0
- package/lib/v1/Switch/contants/index.js +27 -0
- package/lib/v1/Switch/css/Switch_v1.module.css +133 -0
- package/lib/v1/Switch/css/cssJSLogic.js +37 -0
- package/lib/v1/Switch/props/defaultProps.js +12 -9
- package/lib/v1/Switch/props/propTypes.js +32 -24
- package/lib/v1/Switch/useSwitch.js +56 -0
- package/package.json +6 -2
- package/result.json +1 -1
|
@@ -0,0 +1,133 @@
|
|
|
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:hover {
|
|
54
|
+
--local-switch-track-background-color: var(--zdt_v1_switch_track_on_hover_bg);
|
|
55
|
+
}
|
|
56
|
+
.unChecked.enabled:hover {
|
|
57
|
+
--local-switch-track-background-color: var(--zdt_v1_switch_track_off_hover_bg);
|
|
58
|
+
}
|
|
59
|
+
.enabled: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
|
+
cursor: var(--local-switch-cursor);
|
|
100
|
+
}
|
|
101
|
+
.onLabel {
|
|
102
|
+
height: var(--local-switch-onLabel-height);
|
|
103
|
+
fill: var(--zdt_v1_switch_onLabel);
|
|
104
|
+
width: var(--zd_size1) ;
|
|
105
|
+
transform: translateY(-50%) scaleX(var(--local-switch-onLabel-scaleX));
|
|
106
|
+
}
|
|
107
|
+
[dir=ltr] .onLabel {
|
|
108
|
+
left: var(--local-switch-onLabel-left);
|
|
109
|
+
}
|
|
110
|
+
[dir=rtl] .onLabel {
|
|
111
|
+
right: var(--local-switch-onLabel-left);
|
|
112
|
+
}
|
|
113
|
+
.offLabel {
|
|
114
|
+
height: var(--local-switch-offLabel-size);
|
|
115
|
+
width: var(--local-switch-offLabel-size);
|
|
116
|
+
fill: transparent;
|
|
117
|
+
stroke: var(--local-switch-offLabel-stroke);
|
|
118
|
+
transform: translateY(-50%);
|
|
119
|
+
}
|
|
120
|
+
[dir=ltr] .offLabel {
|
|
121
|
+
right: var(--local-switch-offLabel-right);
|
|
122
|
+
}
|
|
123
|
+
[dir=rtl] .offLabel {
|
|
124
|
+
left: var(--local-switch-offLabel-right);
|
|
125
|
+
}
|
|
126
|
+
.checked {
|
|
127
|
+
--local-switch-track-background-color: var(--zdt_v1_switch_track_on_bg);
|
|
128
|
+
--local-switch-thumb-translateX: calc(var(--local-switch-track-width) - var(--local-switch-thumb-size) - 2px)
|
|
129
|
+
}
|
|
130
|
+
.unChecked {
|
|
131
|
+
--local-switch-track-background-color: var(--zdt_v1_switch_track_off_bg);
|
|
132
|
+
--local-switch-thumb-translateX: 0;
|
|
133
|
+
}
|
|
@@ -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,14 @@
|
|
|
1
|
-
export
|
|
2
|
-
checked: false,
|
|
3
|
-
disabled: false,
|
|
4
|
-
labelPalette: 'primary',
|
|
5
|
-
labelSize: 'medium',
|
|
1
|
+
export default {
|
|
6
2
|
size: 'medium',
|
|
3
|
+
isDefaultChecked: false,
|
|
4
|
+
isDisabled: false,
|
|
7
5
|
isReadOnly: false,
|
|
8
|
-
|
|
6
|
+
hasStateIndication: true,
|
|
7
|
+
labelPlacement: 'start',
|
|
8
|
+
labelSize: 'medium',
|
|
9
9
|
customProps: {},
|
|
10
|
-
|
|
10
|
+
tagAttributes: {},
|
|
11
|
+
a11yAttributes: {},
|
|
12
|
+
i18nKeys: {},
|
|
13
|
+
customStyle: {}
|
|
11
14
|
};
|
|
@@ -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
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
|
|
3
|
+
const useSwitch = props => {
|
|
4
|
+
const {
|
|
5
|
+
isChecked: isCheckedProp,
|
|
6
|
+
isDefaultChecked,
|
|
7
|
+
onChange,
|
|
8
|
+
isReadOnly,
|
|
9
|
+
isDisabled
|
|
10
|
+
} = props;
|
|
11
|
+
const isControlled = isCheckedProp !== undefined;
|
|
12
|
+
const [internalChecked, setInternalChecked] = useState(isDefaultChecked);
|
|
13
|
+
const isChecked = isControlled ? isCheckedProp : internalChecked;
|
|
14
|
+
|
|
15
|
+
const handleChange = e => {
|
|
16
|
+
if (isReadOnly || isDisabled) return;
|
|
17
|
+
|
|
18
|
+
if (!isControlled) {
|
|
19
|
+
setInternalChecked(!isChecked);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
onChange?.({
|
|
23
|
+
isChecked: !isChecked
|
|
24
|
+
}, e);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
isChecked,
|
|
29
|
+
handleChange
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default useSwitch;
|
|
@@ -148,14 +148,15 @@ var AppContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
148
148
|
|
|
149
149
|
if (this.containerElement && needTooltip) {
|
|
150
150
|
this.containerElement.removeEventListener('mouseover', this.handleOver, false);
|
|
151
|
-
this.containerElement.
|
|
151
|
+
this.containerElement.removeEventListener('mouseout', this.removeTimeout, false);
|
|
152
152
|
this.tooltipRef.unObserveElement();
|
|
153
|
-
(0, _Config.setLibraryConfig)({
|
|
154
|
-
getTooltipContainer: function getTooltipContainer() {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
153
|
}
|
|
154
|
+
|
|
155
|
+
(0, _Config.setLibraryConfig)({
|
|
156
|
+
getTooltipContainer: function getTooltipContainer() {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
159
160
|
}
|
|
160
161
|
}, {
|
|
161
162
|
key: "render",
|
|
@@ -44,13 +44,15 @@ var LibraryContextProvider = function LibraryContextProvider(_ref) {
|
|
|
44
44
|
direction = _ref.direction,
|
|
45
45
|
coloredTagVariant = _ref.coloredTagVariant,
|
|
46
46
|
hasTagColorInheritedToText = _ref.hasTagColorInheritedToText,
|
|
47
|
+
shouldIndicateSwitchState = _ref.shouldIndicateSwitchState,
|
|
47
48
|
children = _ref.children;
|
|
48
49
|
|
|
49
50
|
var _useState = (0, _react.useState)({
|
|
50
51
|
isReducedMotion: isReducedMotion,
|
|
51
52
|
direction: direction,
|
|
52
53
|
coloredTagVariant: coloredTagVariant,
|
|
53
|
-
hasTagColorInheritedToText: hasTagColorInheritedToText
|
|
54
|
+
hasTagColorInheritedToText: hasTagColorInheritedToText,
|
|
55
|
+
shouldIndicateSwitchState: shouldIndicateSwitchState
|
|
54
56
|
}),
|
|
55
57
|
_useState2 = _slicedToArray(_useState, 2),
|
|
56
58
|
value = _useState2[0],
|
|
@@ -74,13 +76,15 @@ LibraryContextProvider.propTypes = {
|
|
|
74
76
|
isReducedMotion: _propTypes["default"].bool,
|
|
75
77
|
coloredTagVariant: _propTypes["default"].oneOf(['bold', 'subtle', 'minimal']),
|
|
76
78
|
hasTagColorInheritedToText: _propTypes["default"].bool,
|
|
77
|
-
direction: _propTypes["default"].string
|
|
79
|
+
direction: _propTypes["default"].string,
|
|
80
|
+
shouldIndicateSwitchState: _propTypes["default"].bool
|
|
78
81
|
};
|
|
79
82
|
LibraryContextProvider.defaultProps = {
|
|
80
83
|
isReducedMotion: (0, _Config.getLibraryConfig)('isReducedMotion'),
|
|
81
84
|
direction: (0, _Config.getLibraryConfig)('direction'),
|
|
82
85
|
coloredTagVariant: 'bold',
|
|
83
|
-
hasTagColorInheritedToText: true
|
|
86
|
+
hasTagColorInheritedToText: true,
|
|
87
|
+
shouldIndicateSwitchState: false
|
|
84
88
|
};
|
|
85
89
|
var _default = LibraryContextProvider;
|
|
86
90
|
exports["default"] = _default;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _defaultProps = require("./props/defaultProps");
|
|
11
|
+
|
|
12
|
+
var _propTypes = require("./props/propTypes");
|
|
13
|
+
|
|
14
|
+
var _Layout = require("../../v1/Layout");
|
|
15
|
+
|
|
16
|
+
var _Label = _interopRequireDefault(require("../../v1/Label/Label"));
|
|
17
|
+
|
|
18
|
+
var _SwitchModule = _interopRequireDefault(require("../../Switch/Switch.module.css"));
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
21
|
+
|
|
22
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
23
|
+
|
|
24
|
+
var Switch = function Switch(props) {
|
|
25
|
+
var id = props.id,
|
|
26
|
+
name = props.name,
|
|
27
|
+
value = props.value,
|
|
28
|
+
checked = props.checked,
|
|
29
|
+
disabled = props.disabled,
|
|
30
|
+
isReadOnly = props.isReadOnly,
|
|
31
|
+
size = props.size,
|
|
32
|
+
text = props.text,
|
|
33
|
+
labelSize = props.labelSize,
|
|
34
|
+
labelPalette = props.labelPalette,
|
|
35
|
+
title = props.title,
|
|
36
|
+
disableTitle = props.disableTitle,
|
|
37
|
+
dataId = props.dataId,
|
|
38
|
+
dataSelectorId = props.dataSelectorId,
|
|
39
|
+
customClass = props.customClass,
|
|
40
|
+
customProps = props.customProps;
|
|
41
|
+
|
|
42
|
+
function onChange(e) {
|
|
43
|
+
var onChange = props.onChange;
|
|
44
|
+
onChange && onChange(!checked, e);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var _customProps$SwitchPr = customProps.SwitchProps,
|
|
48
|
+
SwitchProps = _customProps$SwitchPr === void 0 ? {} : _customProps$SwitchPr,
|
|
49
|
+
_customProps$LabelPro = customProps.LabelProps,
|
|
50
|
+
LabelProps = _customProps$LabelPro === void 0 ? {} : _customProps$LabelPro;
|
|
51
|
+
var _customClass$customSw = customClass.customSwitchWrap,
|
|
52
|
+
customSwitchWrap = _customClass$customSw === void 0 ? '' : _customClass$customSw,
|
|
53
|
+
_customClass$customSw2 = customClass.customSwitch,
|
|
54
|
+
customSwitch = _customClass$customSw2 === void 0 ? '' : _customClass$customSw2,
|
|
55
|
+
_customClass$customSw3 = customClass.customSwitchSize,
|
|
56
|
+
customSwitchSize = _customClass$customSw3 === void 0 ? '' : _customClass$customSw3,
|
|
57
|
+
_customClass$customLa = customClass.customLabel,
|
|
58
|
+
customLabel = _customClass$customLa === void 0 ? '' : _customClass$customLa;
|
|
59
|
+
size !== 'small' ? size = 'switch_medium' : size = 'switch_small';
|
|
60
|
+
return /*#__PURE__*/_react["default"].createElement(_Layout.Container, _extends({
|
|
61
|
+
align: "vertical",
|
|
62
|
+
isCover: false,
|
|
63
|
+
alignBox: "row",
|
|
64
|
+
isInline: true,
|
|
65
|
+
className: "".concat(_SwitchModule["default"].container, " ").concat(customSwitchWrap, " ").concat(disabled ? _SwitchModule["default"].disabled : isReadOnly ? _SwitchModule["default"].readonly : _SwitchModule["default"].effect),
|
|
66
|
+
"data-title": disabled ? disableTitle : title,
|
|
67
|
+
"aria-checked": checked,
|
|
68
|
+
role: "switch",
|
|
69
|
+
dataSelectorId: dataSelectorId
|
|
70
|
+
}, SwitchProps), /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
|
|
71
|
+
className: "".concat(_SwitchModule["default"][size], " ").concat(customSwitchSize)
|
|
72
|
+
}, /*#__PURE__*/_react["default"].createElement("input", {
|
|
73
|
+
type: "checkbox",
|
|
74
|
+
id: id,
|
|
75
|
+
className: "".concat(_SwitchModule["default"].input, " ").concat(checked ? _SwitchModule["default"].checked : ''),
|
|
76
|
+
name: name,
|
|
77
|
+
value: value,
|
|
78
|
+
checked: checked,
|
|
79
|
+
disabled: disabled,
|
|
80
|
+
readOnly: isReadOnly,
|
|
81
|
+
onClick: !disabled || !isReadOnly ? onChange : null
|
|
82
|
+
}), /*#__PURE__*/_react["default"].createElement("label", {
|
|
83
|
+
htmlFor: id,
|
|
84
|
+
"data-id": dataId,
|
|
85
|
+
"data-test-id": dataId,
|
|
86
|
+
className: "".concat(_SwitchModule["default"].label, " ").concat(_SwitchModule["default"]["".concat(size, "Label")], " ").concat(customSwitch),
|
|
87
|
+
tabIndex: isReadOnly || disabled ? '-1' : '0'
|
|
88
|
+
})), text && /*#__PURE__*/_react["default"].createElement(_Label["default"], _extends({
|
|
89
|
+
text: text,
|
|
90
|
+
palette: labelPalette,
|
|
91
|
+
id: id,
|
|
92
|
+
size: labelSize,
|
|
93
|
+
type: "subtitle",
|
|
94
|
+
onClick: !disabled || !isReadOnly ? onChange : null,
|
|
95
|
+
customClass: customLabel
|
|
96
|
+
}, LabelProps)));
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
Switch.defaultProps = _defaultProps.defaultProps;
|
|
100
|
+
Switch.propTypes = _propTypes.propTypes;
|
|
101
|
+
var _default = Switch; // if (__DOCS__) {
|
|
102
|
+
// Switch.docs = {
|
|
103
|
+
// componentGroup: 'Form Elements',
|
|
104
|
+
// folderName: 'Style Guide'
|
|
105
|
+
// };
|
|
106
|
+
// }
|
|
107
|
+
|
|
108
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.defaultProps = void 0;
|
|
7
|
+
var defaultProps = {
|
|
8
|
+
checked: false,
|
|
9
|
+
disabled: false,
|
|
10
|
+
labelPalette: 'primary',
|
|
11
|
+
labelSize: 'medium',
|
|
12
|
+
size: 'medium',
|
|
13
|
+
isReadOnly: false,
|
|
14
|
+
customClass: {},
|
|
15
|
+
customProps: {},
|
|
16
|
+
dataSelectorId: 'switch'
|
|
17
|
+
};
|
|
18
|
+
exports.defaultProps = defaultProps;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.propTypes = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
12
|
+
var propTypes = {
|
|
13
|
+
checked: _propTypes["default"].bool,
|
|
14
|
+
dataId: _propTypes["default"].string,
|
|
15
|
+
dataSelectorId: _propTypes["default"].string,
|
|
16
|
+
disableTitle: _propTypes["default"].string,
|
|
17
|
+
disabled: _propTypes["default"].bool,
|
|
18
|
+
id: _propTypes["default"].string.isRequired,
|
|
19
|
+
isReadOnly: _propTypes["default"].bool,
|
|
20
|
+
labelPalette: _propTypes["default"].oneOf(['default', 'primary', 'secondary', 'danger', 'mandatory']),
|
|
21
|
+
labelSize: _propTypes["default"].oneOf(['small', 'medium', 'large']),
|
|
22
|
+
name: _propTypes["default"].string,
|
|
23
|
+
onChange: _propTypes["default"].func,
|
|
24
|
+
size: _propTypes["default"].oneOf(['small', 'medium']),
|
|
25
|
+
text: _propTypes["default"].string,
|
|
26
|
+
title: _propTypes["default"].string,
|
|
27
|
+
value: _propTypes["default"].bool,
|
|
28
|
+
customClass: _propTypes["default"].shape({
|
|
29
|
+
customSwitchWrap: _propTypes["default"].string,
|
|
30
|
+
customSwitch: _propTypes["default"].string,
|
|
31
|
+
customSwitchSize: _propTypes["default"].string,
|
|
32
|
+
customLabel: _propTypes["default"].string
|
|
33
|
+
}),
|
|
34
|
+
customProps: _propTypes["default"].shape({
|
|
35
|
+
SwitchProps: _propTypes["default"].object,
|
|
36
|
+
LabelProps: _propTypes["default"].object
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
exports.propTypes = propTypes;
|