@zohodesk/components 1.0.0-temp-219.3 → 1.0.0-temp-229.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/.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 +39 -10
- package/es/Card/props/defaultProps.js +2 -1
- package/es/Card/props/propTypes.js +2 -1
- package/es/CheckBox/CheckBox.js +2 -9
- package/es/Label/Label.js +2 -9
- 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 +54 -25
- package/lib/Card/props/defaultProps.js +2 -1
- package/lib/Card/props/propTypes.js +2 -1
- package/lib/CheckBox/CheckBox.js +2 -9
- package/lib/Label/Label.js +2 -9
- 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 -8
- package/result.json +1 -1
package/lib/CheckBox/CheckBox.js
CHANGED
|
@@ -13,8 +13,6 @@ var _propTypes = require("./props/propTypes");
|
|
|
13
13
|
|
|
14
14
|
var _defaultProps = require("./props/defaultProps");
|
|
15
15
|
|
|
16
|
-
var _ComponentRegistry = require("@zohodesk/dotkit/es/react/ComponentRegistry");
|
|
17
|
-
|
|
18
16
|
var _Label = _interopRequireDefault(require("../Label/Label"));
|
|
19
17
|
|
|
20
18
|
var _Layout = require("../Layout");
|
|
@@ -215,16 +213,11 @@ var CheckBox = /*#__PURE__*/function (_React$Component) {
|
|
|
215
213
|
return CheckBox;
|
|
216
214
|
}(_react["default"].Component);
|
|
217
215
|
|
|
216
|
+
exports["default"] = CheckBox;
|
|
218
217
|
CheckBox.defaultProps = _defaultProps.defaultProps;
|
|
219
218
|
CheckBox.propTypes = _propTypes.propTypes; // if (__DOCS__) {
|
|
220
219
|
// CheckBox.docs = {
|
|
221
220
|
// componentGroup: 'Form Elements',
|
|
222
221
|
// folderName: 'Style Guide'
|
|
223
222
|
// };
|
|
224
|
-
// }
|
|
225
|
-
|
|
226
|
-
var _default = (0, _ComponentRegistry.withComponentRegistrar)(CheckBox, {
|
|
227
|
-
name: 'ZDC_CheckBox'
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
exports["default"] = _default;
|
|
223
|
+
// }
|
package/lib/Label/Label.js
CHANGED
|
@@ -13,8 +13,6 @@ var _defaultProps = require("./props/defaultProps");
|
|
|
13
13
|
|
|
14
14
|
var _propTypes = require("./props/propTypes");
|
|
15
15
|
|
|
16
|
-
var _ComponentRegistry = require("@zohodesk/dotkit/es/react/ComponentRegistry");
|
|
17
|
-
|
|
18
16
|
var _LabelModule = _interopRequireDefault(require("./Label.module.css"));
|
|
19
17
|
|
|
20
18
|
var _LabelColorsModule = _interopRequireDefault(require("./LabelColors.module.css"));
|
|
@@ -89,16 +87,11 @@ var Label = /*#__PURE__*/function (_React$Component) {
|
|
|
89
87
|
return Label;
|
|
90
88
|
}(_react["default"].Component);
|
|
91
89
|
|
|
90
|
+
exports["default"] = Label;
|
|
92
91
|
Label.defaultProps = _defaultProps.defaultProps;
|
|
93
92
|
Label.propTypes = _propTypes.propTypes; // if (__DOCS__) {
|
|
94
93
|
// Label.docs = {
|
|
95
94
|
// componentGroup: 'Form Elements',
|
|
96
95
|
// folderName: 'Style Guide'
|
|
97
96
|
// };
|
|
98
|
-
// }
|
|
99
|
-
|
|
100
|
-
var _default = (0, _ComponentRegistry.withComponentRegistrar)(Label, {
|
|
101
|
-
name: 'ZDC_Label'
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
exports["default"] = _default;
|
|
97
|
+
// }
|
|
@@ -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;
|
package/lib/v1/Switch/Switch.js
CHANGED
|
@@ -7,102 +7,153 @@ exports["default"] = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
10
|
-
var _defaultProps = require("./props/defaultProps");
|
|
10
|
+
var _defaultProps = _interopRequireDefault(require("./props/defaultProps"));
|
|
11
11
|
|
|
12
|
-
var _propTypes = require("./props/propTypes");
|
|
12
|
+
var _propTypes = _interopRequireDefault(require("./props/propTypes"));
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _cssJSLogic2 = _interopRequireDefault(require("./css/cssJSLogic"));
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _utils = require("@zohodesk/utils");
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _useSwitch2 = _interopRequireDefault(require("./useSwitch"));
|
|
19
|
+
|
|
20
|
+
var _contants = require("./contants");
|
|
21
|
+
|
|
22
|
+
var _Flex = _interopRequireDefault(require("@zohodesk/layout/es/Flex/Flex"));
|
|
23
|
+
|
|
24
|
+
var _Label = _interopRequireDefault(require("../../Label/Label"));
|
|
25
|
+
|
|
26
|
+
var _Switch_v1Module = _interopRequireDefault(require("./css/Switch_v1.module.css"));
|
|
27
|
+
|
|
28
|
+
var _excluded = ["ariaDisabled", "ariaLabel"];
|
|
19
29
|
|
|
20
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
21
31
|
|
|
22
32
|
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
33
|
|
|
34
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
35
|
+
|
|
36
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
37
|
+
|
|
38
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
39
|
+
|
|
40
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
41
|
+
|
|
42
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
43
|
+
|
|
24
44
|
var Switch = function Switch(props) {
|
|
25
|
-
var
|
|
26
|
-
name = props.name,
|
|
45
|
+
var name = props.name,
|
|
27
46
|
value = props.value,
|
|
28
|
-
|
|
29
|
-
disabled = props.disabled,
|
|
30
|
-
isReadOnly = props.isReadOnly,
|
|
47
|
+
id = props.id,
|
|
31
48
|
size = props.size,
|
|
32
|
-
|
|
49
|
+
isDisabled = props.isDisabled,
|
|
50
|
+
isReadOnly = props.isReadOnly,
|
|
51
|
+
hasStateIndication = props.hasStateIndication,
|
|
52
|
+
label = props.label,
|
|
53
|
+
labelPlacement = props.labelPlacement,
|
|
33
54
|
labelSize = props.labelSize,
|
|
34
|
-
labelPalette = props.labelPalette,
|
|
35
55
|
title = props.title,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
},
|
|
56
|
+
customProps = props.customProps,
|
|
57
|
+
tagAttributes = props.tagAttributes,
|
|
58
|
+
a11yAttributes = props.a11yAttributes,
|
|
59
|
+
i18nKeys = props.i18nKeys,
|
|
60
|
+
customId = props.customId,
|
|
61
|
+
testId = props.testId,
|
|
62
|
+
customStyle = props.customStyle;
|
|
63
|
+
var customProps_container = customProps.container,
|
|
64
|
+
customProps_label = customProps.label;
|
|
65
|
+
var tagAttributes_container = tagAttributes.container,
|
|
66
|
+
tagAttributes_switch = tagAttributes["switch"];
|
|
67
|
+
var a11yAttributes_container = a11yAttributes.container,
|
|
68
|
+
_a11yAttributes$switc = a11yAttributes["switch"],
|
|
69
|
+
a11yAttributes_switch = _a11yAttributes$switc === void 0 ? {} : _a11yAttributes$switc,
|
|
70
|
+
a11yAttributes_label = a11yAttributes.label;
|
|
71
|
+
|
|
72
|
+
var _a11yAttributes_switc = a11yAttributes_switch.ariaDisabled,
|
|
73
|
+
ariaDisabled = _a11yAttributes_switc === void 0 ? isDisabled : _a11yAttributes_switc,
|
|
74
|
+
ariaLabel = a11yAttributes_switch.ariaLabel,
|
|
75
|
+
restA11yAttributes_switch = _objectWithoutProperties(a11yAttributes_switch, _excluded);
|
|
76
|
+
|
|
77
|
+
var _i18nKeys$readOnlyAri = i18nKeys.readOnlyAriaLabel,
|
|
78
|
+
i18n_readOnlyAriaLabel = _i18nKeys$readOnlyAri === void 0 ? 'Read Only' : _i18nKeys$readOnlyAri;
|
|
79
|
+
var readOnlyAriaLabel = label ? "".concat(label, ", ").concat(i18n_readOnlyAriaLabel) : i18n_readOnlyAriaLabel;
|
|
80
|
+
|
|
81
|
+
var _useSwitch = (0, _useSwitch2["default"])(props),
|
|
82
|
+
isChecked = _useSwitch.isChecked,
|
|
83
|
+
handleChange = _useSwitch.handleChange;
|
|
84
|
+
|
|
85
|
+
var style = (0, _utils.mergeStyle)(_Switch_v1Module["default"], customStyle);
|
|
86
|
+
|
|
87
|
+
var _cssJSLogic = (0, _cssJSLogic2["default"])({
|
|
88
|
+
props: _objectSpread(_objectSpread({}, props), {}, {
|
|
89
|
+
isChecked: isChecked
|
|
90
|
+
}),
|
|
91
|
+
style: style
|
|
92
|
+
}),
|
|
93
|
+
containerClass = _cssJSLogic.containerClass,
|
|
94
|
+
labelClass = _cssJSLogic.labelClass,
|
|
95
|
+
trackClass = _cssJSLogic.trackClass,
|
|
96
|
+
trackWrapperClass = _cssJSLogic.trackWrapperClass,
|
|
97
|
+
thumbClass = _cssJSLogic.thumbClass,
|
|
98
|
+
labelIndicationClass = _cssJSLogic.labelIndicationClass;
|
|
99
|
+
|
|
100
|
+
return /*#__PURE__*/_react["default"].createElement(_Flex["default"], _extends({}, customProps_container, {
|
|
101
|
+
$ui_displayMode: "inline",
|
|
102
|
+
$ui_direction: _contants.ITEMS_DIRECTION[labelPlacement],
|
|
103
|
+
$ui_alignItems: _contants.ALIGN_ITEMS[labelPlacement],
|
|
104
|
+
$tagAttributes_container: _objectSpread(_objectSpread({}, tagAttributes_container), {}, {
|
|
105
|
+
'data-selector-id': customId
|
|
106
|
+
}),
|
|
107
|
+
testId: testId,
|
|
108
|
+
customId: customId,
|
|
109
|
+
$ui_className: containerClass,
|
|
110
|
+
$a11yAttributes_container: a11yAttributes_container
|
|
111
|
+
}), label && /*#__PURE__*/_react["default"].createElement(_Label["default"], _extends({}, customProps_label, {
|
|
112
|
+
text: label,
|
|
113
|
+
palette: isDisabled ? 'primary' : 'default',
|
|
114
|
+
size: labelSize,
|
|
115
|
+
htmlFor: id,
|
|
116
|
+
customClass: labelClass,
|
|
117
|
+
a11y: a11yAttributes_label,
|
|
118
|
+
clipped: true,
|
|
119
|
+
title: label
|
|
120
|
+
})), /*#__PURE__*/_react["default"].createElement(_Flex["default"], {
|
|
121
|
+
$flag_shrink: false,
|
|
122
|
+
$ui_className: trackWrapperClass
|
|
123
|
+
}, /*#__PURE__*/_react["default"].createElement("input", _extends({}, tagAttributes_switch, restA11yAttributes_switch, {
|
|
73
124
|
type: "checkbox",
|
|
74
125
|
id: id,
|
|
75
|
-
className: "".concat(_SwitchModule["default"].input, " ").concat(checked ? _SwitchModule["default"].checked : ''),
|
|
76
126
|
name: name,
|
|
77
127
|
value: value,
|
|
78
|
-
checked:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"
|
|
85
|
-
|
|
86
|
-
className:
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
128
|
+
checked: isChecked,
|
|
129
|
+
onChange: handleChange,
|
|
130
|
+
className: trackClass,
|
|
131
|
+
"data-title": title,
|
|
132
|
+
role: "switch",
|
|
133
|
+
"aria-disabled": ariaDisabled,
|
|
134
|
+
"aria-label": isReadOnly ? readOnlyAriaLabel : ariaLabel
|
|
135
|
+
})), /*#__PURE__*/_react["default"].createElement("svg", {
|
|
136
|
+
className: thumbClass,
|
|
137
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
138
|
+
}, /*#__PURE__*/_react["default"].createElement("circle", {
|
|
139
|
+
cx: "50%",
|
|
140
|
+
cy: "50%",
|
|
141
|
+
r: _contants.THUMB_RADIUS[size]
|
|
142
|
+
})), hasStateIndication ? /*#__PURE__*/_react["default"].createElement("svg", {
|
|
143
|
+
className: labelIndicationClass,
|
|
144
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
145
|
+
}, isChecked ? /*#__PURE__*/_react["default"].createElement("rect", {
|
|
146
|
+
width: "100%",
|
|
147
|
+
height: "100%",
|
|
148
|
+
rx: "50%"
|
|
149
|
+
}) : /*#__PURE__*/_react["default"].createElement("circle", {
|
|
150
|
+
cx: "50%",
|
|
151
|
+
cy: "50%",
|
|
152
|
+
r: _contants.OFF_LABEL_RADIUS[size]
|
|
153
|
+
})) : null));
|
|
97
154
|
};
|
|
98
155
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// componentGroup: 'Form Elements',
|
|
104
|
-
// folderName: 'Style Guide'
|
|
105
|
-
// };
|
|
106
|
-
// }
|
|
107
|
-
|
|
108
|
-
exports["default"] = _default;
|
|
156
|
+
var _default = Switch;
|
|
157
|
+
exports["default"] = _default;
|
|
158
|
+
Switch.defaultProps = _defaultProps["default"];
|
|
159
|
+
Switch.propTypes = _propTypes["default"];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = _interopRequireDefault(require("react"));
|
|
4
|
+
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
|
|
7
|
+
var _Switch = _interopRequireDefault(require("../Switch"));
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
|
|
11
|
+
describe('Switch', function () {
|
|
12
|
+
test('rendering the defult props', function () {
|
|
13
|
+
var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], null)),
|
|
14
|
+
asFragment = _render.asFragment;
|
|
15
|
+
|
|
16
|
+
expect(asFragment()).toMatchSnapshot();
|
|
17
|
+
});
|
|
18
|
+
test('rendering the Switch with Checked', function () {
|
|
19
|
+
var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
20
|
+
id: "switch",
|
|
21
|
+
isChecked: true
|
|
22
|
+
})),
|
|
23
|
+
asFragment = _render2.asFragment;
|
|
24
|
+
|
|
25
|
+
expect(asFragment()).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
test('rendering the Switch with Disabled', function () {
|
|
28
|
+
var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
29
|
+
id: "switch",
|
|
30
|
+
isChecked: true,
|
|
31
|
+
isDisabled: true
|
|
32
|
+
})),
|
|
33
|
+
asFragment = _render3.asFragment;
|
|
34
|
+
|
|
35
|
+
expect(asFragment()).toMatchSnapshot();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -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
|
+
`;
|