@dxc-technology/halstack-react 6.0.0 → 6.2.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/accordion/Accordion.js +122 -103
- package/accordion/Accordion.stories.tsx +1 -2
- package/accordion/Accordion.test.js +9 -10
- package/accordion/types.d.ts +4 -4
- package/accordion-group/AccordionGroup.js +1 -21
- package/accordion-group/AccordionGroup.stories.tsx +27 -1
- package/accordion-group/AccordionGroup.test.js +20 -45
- package/accordion-group/types.d.ts +9 -3
- package/alert/Alert.js +1 -1
- package/box/Box.js +1 -1
- package/bulleted-list/types.d.ts +1 -1
- package/button/Button.js +43 -61
- package/button/Button.stories.tsx +9 -0
- package/button/types.d.ts +7 -7
- package/checkbox/Checkbox.js +88 -95
- package/checkbox/Checkbox.test.js +93 -16
- package/checkbox/types.d.ts +2 -2
- package/chip/types.d.ts +1 -1
- package/common/variables.js +23 -10
- package/date-input/DateInput.js +3 -3
- package/dialog/Dialog.js +52 -28
- package/dialog/Dialog.stories.tsx +1 -2
- package/dialog/Dialog.test.js +34 -4
- package/dialog/types.d.ts +2 -2
- package/dropdown/Dropdown.d.ts +1 -1
- package/dropdown/Dropdown.js +243 -247
- package/dropdown/Dropdown.stories.tsx +126 -63
- package/dropdown/Dropdown.test.js +510 -108
- package/dropdown/DropdownMenu.d.ts +4 -0
- package/dropdown/DropdownMenu.js +80 -0
- package/dropdown/DropdownMenuItem.d.ts +4 -0
- package/dropdown/DropdownMenuItem.js +92 -0
- package/dropdown/types.d.ts +25 -5
- package/flex/Flex.js +1 -1
- package/flex/types.d.ts +1 -1
- package/footer/Footer.stories.tsx +8 -1
- package/footer/types.d.ts +1 -1
- package/header/Header.js +74 -72
- package/header/Header.stories.tsx +4 -4
- package/header/Icons.js +2 -2
- package/header/types.d.ts +2 -2
- package/layout/ApplicationLayout.js +3 -3
- package/layout/ApplicationLayout.stories.tsx +1 -0
- package/link/Link.js +1 -1
- package/link/Link.stories.tsx +12 -5
- package/link/types.d.ts +1 -1
- package/package.json +10 -10
- package/progress-bar/ProgressBar.d.ts +2 -2
- package/progress-bar/ProgressBar.js +56 -50
- package/progress-bar/ProgressBar.stories.jsx +3 -1
- package/progress-bar/ProgressBar.test.js +67 -22
- package/progress-bar/types.d.ts +3 -4
- package/radio-group/RadioGroup.js +11 -13
- package/select/Listbox.d.ts +1 -1
- package/select/Listbox.js +25 -2
- package/select/Select.js +14 -31
- package/select/Select.stories.tsx +6 -5
- package/select/Select.test.js +63 -50
- package/select/types.d.ts +2 -4
- package/sidenav/Sidenav.js +15 -3
- package/sidenav/types.d.ts +1 -1
- package/slider/Slider.js +114 -93
- package/slider/Slider.stories.tsx +7 -1
- package/slider/Slider.test.js +121 -21
- package/slider/types.d.ts +2 -2
- package/switch/Switch.d.ts +1 -1
- package/switch/Switch.js +111 -55
- package/switch/Switch.stories.tsx +8 -30
- package/switch/Switch.test.js +122 -8
- package/switch/types.d.ts +3 -4
- package/tabs/Tab.d.ts +4 -0
- package/tabs/Tab.js +135 -0
- package/tabs/Tabs.js +360 -104
- package/tabs/Tabs.stories.tsx +74 -0
- package/tabs/Tabs.test.js +217 -6
- package/tabs/types.d.ts +15 -5
- package/tabs-nav/NavTabs.js +5 -5
- package/tabs-nav/Tab.js +3 -5
- package/tabs-nav/types.d.ts +1 -1
- package/tag/Tag.js +1 -1
- package/tag/types.d.ts +1 -1
- package/text-input/Icons.d.ts +8 -0
- package/text-input/Icons.js +60 -0
- package/text-input/Suggestion.js +7 -5
- package/text-input/Suggestions.d.ts +4 -0
- package/text-input/Suggestions.js +134 -0
- package/text-input/TextInput.js +115 -222
- package/text-input/TextInput.stories.tsx +189 -182
- package/text-input/TextInput.test.js +163 -162
- package/text-input/types.d.ts +17 -3
- package/toggle-group/types.d.ts +1 -1
- package/wizard/types.d.ts +1 -1
package/switch/Switch.js
CHANGED
|
@@ -19,8 +19,6 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
19
19
|
|
|
20
20
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
21
21
|
|
|
22
|
-
var _core = require("@material-ui/core");
|
|
23
|
-
|
|
24
22
|
var _uuid = require("uuid");
|
|
25
23
|
|
|
26
24
|
var _variables = require("../common/variables.js");
|
|
@@ -33,13 +31,15 @@ var _useTranslatedLabels = _interopRequireDefault(require("../useTranslatedLabel
|
|
|
33
31
|
|
|
34
32
|
var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext"));
|
|
35
33
|
|
|
36
|
-
var _templateObject, _templateObject2;
|
|
34
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
37
35
|
|
|
38
36
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
39
37
|
|
|
40
38
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
41
39
|
|
|
42
40
|
var DxcSwitch = function DxcSwitch(_ref) {
|
|
41
|
+
var _ref2;
|
|
42
|
+
|
|
43
43
|
var defaultChecked = _ref.defaultChecked,
|
|
44
44
|
checked = _ref.checked,
|
|
45
45
|
value = _ref.value,
|
|
@@ -71,9 +71,32 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
71
71
|
innerChecked = _useState4[0],
|
|
72
72
|
setInnerChecked = _useState4[1];
|
|
73
73
|
|
|
74
|
+
var _useState5 = (0, _react.useState)((_ref2 = label !== "" && label !== null && label !== undefined) !== null && _ref2 !== void 0 ? _ref2 : false),
|
|
75
|
+
_useState6 = (0, _slicedToArray2["default"])(_useState5, 1),
|
|
76
|
+
hasLabel = _useState6[0];
|
|
77
|
+
|
|
74
78
|
var colorsTheme = (0, _useTheme["default"])();
|
|
75
79
|
var translatedLabels = (0, _useTranslatedLabels["default"])();
|
|
76
80
|
var backgroundType = (0, _react.useContext)(_BackgroundColorContext["default"]);
|
|
81
|
+
var refTrack = (0, _react.useRef)(null);
|
|
82
|
+
|
|
83
|
+
var handleOnKeyDown = function handleOnKeyDown(event) {
|
|
84
|
+
switch (event.key) {
|
|
85
|
+
case "Enter":
|
|
86
|
+
case " ":
|
|
87
|
+
//Space
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
refTrack.current.focus();
|
|
90
|
+
var isChecked = !(checked !== null && checked !== void 0 ? checked : innerChecked);
|
|
91
|
+
setInnerChecked(isChecked);
|
|
92
|
+
|
|
93
|
+
if (typeof onChange === "function") {
|
|
94
|
+
onChange(isChecked);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
77
100
|
|
|
78
101
|
var handlerSwitchChange = function handlerSwitchChange(event) {
|
|
79
102
|
if (checked === undefined) {
|
|
@@ -81,40 +104,64 @@ var DxcSwitch = function DxcSwitch(_ref) {
|
|
|
81
104
|
|
|
82
105
|
var isChecked = (_event$target$checked = event.target.checked) !== null && _event$target$checked !== void 0 ? _event$target$checked : !innerChecked;
|
|
83
106
|
setInnerChecked(isChecked);
|
|
84
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(isChecked);
|
|
85
|
-
} else onChange === null || onChange === void 0 ? void 0 : onChange(!checked);
|
|
86
|
-
};
|
|
87
107
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
108
|
+
if (typeof onChange === "function") {
|
|
109
|
+
onChange(isChecked);
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
if (typeof onChange === "function") {
|
|
113
|
+
onChange(!checked);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
95
117
|
|
|
96
118
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
97
119
|
theme: colorsTheme["switch"]
|
|
98
120
|
}, /*#__PURE__*/_react["default"].createElement(SwitchContainer, {
|
|
99
121
|
margin: margin,
|
|
122
|
+
size: size,
|
|
123
|
+
onKeyDown: handleOnKeyDown
|
|
124
|
+
}, labelPosition === "before" && hasLabel && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
125
|
+
id: labelId,
|
|
126
|
+
labelPosition: labelPosition,
|
|
127
|
+
onClick: !disabled ? handlerSwitchChange : undefined,
|
|
100
128
|
disabled: disabled,
|
|
129
|
+
backgroundType: backgroundType,
|
|
130
|
+
hasLabel: hasLabel
|
|
131
|
+
}, label, " ", optional && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, translatedLabels.formFields.optionalLabel)), /*#__PURE__*/_react["default"].createElement(SwitchBase, {
|
|
101
132
|
labelPosition: labelPosition,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
tabIndex: tabIndex
|
|
112
|
-
},
|
|
113
|
-
onChange: handlerSwitchChange,
|
|
133
|
+
hasLabel: hasLabel,
|
|
134
|
+
htmlFor: labelId,
|
|
135
|
+
onClick: disabled === true ? function () {} : handlerSwitchChange
|
|
136
|
+
}, /*#__PURE__*/_react["default"].createElement(SwitchInput, {
|
|
137
|
+
type: "checkbox",
|
|
138
|
+
role: "switch",
|
|
139
|
+
name: name,
|
|
140
|
+
id: labelId,
|
|
141
|
+
disabled: disabled,
|
|
114
142
|
value: value,
|
|
143
|
+
"aria-labelledby": labelId,
|
|
144
|
+
"aria-label": hasLabel ? label : undefined,
|
|
145
|
+
"aria-checked": checked !== null && checked !== void 0 ? checked : innerChecked,
|
|
146
|
+
defaultChecked: defaultChecked !== null && defaultChecked !== void 0 ? defaultChecked : undefined,
|
|
147
|
+
tabIndex: -1
|
|
148
|
+
}), disabled ? /*#__PURE__*/_react["default"].createElement(DisabledSwitchTrack, {
|
|
149
|
+
backgroundType: backgroundType,
|
|
150
|
+
"data-checked": checked !== null && checked !== void 0 ? checked : innerChecked ? innerChecked : undefined,
|
|
151
|
+
tabIndex: -1
|
|
152
|
+
}) : /*#__PURE__*/_react["default"].createElement(SwitchTrack, {
|
|
153
|
+
backgroundType: backgroundType,
|
|
154
|
+
"data-checked": checked !== null && checked !== void 0 ? checked : innerChecked ? innerChecked : undefined,
|
|
155
|
+
tabIndex: tabIndex,
|
|
156
|
+
ref: refTrack
|
|
157
|
+
})), labelPosition === "after" && hasLabel && /*#__PURE__*/_react["default"].createElement(LabelContainer, {
|
|
158
|
+
id: labelId,
|
|
159
|
+
labelPosition: labelPosition,
|
|
160
|
+
onClick: !disabled ? handlerSwitchChange : undefined,
|
|
115
161
|
disabled: disabled,
|
|
116
|
-
|
|
117
|
-
|
|
162
|
+
backgroundType: backgroundType,
|
|
163
|
+
hasLabel: hasLabel
|
|
164
|
+
}, optional && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, translatedLabels.formFields.optionalLabel), " ", label)));
|
|
118
165
|
};
|
|
119
166
|
|
|
120
167
|
var sizes = {
|
|
@@ -122,14 +169,14 @@ var sizes = {
|
|
|
122
169
|
medium: "240px",
|
|
123
170
|
large: "480px",
|
|
124
171
|
fillParent: "100%",
|
|
125
|
-
fitContent: "
|
|
172
|
+
fitContent: "fit-content"
|
|
126
173
|
};
|
|
127
174
|
|
|
128
175
|
var calculateWidth = function calculateWidth(margin, size) {
|
|
129
176
|
return size === "fillParent" ? "calc(".concat(sizes[size], " - ").concat((0, _utils.getMargin)(margin, "left"), " - ").concat((0, _utils.getMargin)(margin, "right"), ")") : sizes[size];
|
|
130
177
|
};
|
|
131
178
|
|
|
132
|
-
var SwitchContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n
|
|
179
|
+
var SwitchContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n align-items: center;\n width: ", ";\n height: 40px;\n\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n"])), function (props) {
|
|
133
180
|
return calculateWidth(props.margin, props.size);
|
|
134
181
|
}, function (props) {
|
|
135
182
|
return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
|
|
@@ -141,16 +188,38 @@ var SwitchContainer = _styledComponents["default"].div(_templateObject || (_temp
|
|
|
141
188
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
|
|
142
189
|
}, function (props) {
|
|
143
190
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
var LabelContainer = _styledComponents["default"].span(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n color: ", ";\n opacity: 1;\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n cursor: ", ";\n\n ", ";\n\n ", "\n"])), function (props) {
|
|
194
|
+
return props.disabled ? props.backgroundType === "dark" ? props.theme.disabledLabelFontColorOnDark : props.theme.disabledLabelFontColor : props.backgroundType === "dark" ? props.theme.labelFontColorOnDark : props.theme.labelFontColor;
|
|
144
195
|
}, function (props) {
|
|
145
|
-
return props.
|
|
196
|
+
return props.theme.labelFontFamily;
|
|
146
197
|
}, function (props) {
|
|
147
|
-
return props.theme.
|
|
198
|
+
return props.theme.labelFontSize;
|
|
148
199
|
}, function (props) {
|
|
149
|
-
return
|
|
200
|
+
return props.disabled ? props.theme.disabledLabelFontStyle : props.theme.labelFontStyle;
|
|
150
201
|
}, function (props) {
|
|
151
|
-
return props.
|
|
202
|
+
return props.theme.labelFontWeight;
|
|
203
|
+
}, function (props) {
|
|
204
|
+
return props.disabled === true ? "not-allowed" : "pointer";
|
|
205
|
+
}, function (props) {
|
|
206
|
+
return !props.hasLabel ? "margin: 0px;" : props.labelPosition === "after" ? "margin-left: ".concat(props.theme.spaceBetweenLabelSwitch, ";") : "margin-right: ".concat(props.theme.spaceBetweenLabelSwitch, ";");
|
|
207
|
+
}, function (props) {
|
|
208
|
+
return props.labelPosition === "before" && "order: -1";
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
var SwitchBase = _styledComponents["default"].label(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n align-items: center;\n justify-content: space-between;\n cursor: pointer;\n margin: ", ";\n"])), function (props) {
|
|
212
|
+
return !props.hasLabel ? "0px 4px" : props.labelPosition === "before" ? "0 4px 0 12px" : "0 12px 0 4px";
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
var SwitchInput = _styledComponents["default"].input(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n opacity: 0;\n width: 0;\n height: 0;\n margin: 0px;\n"])));
|
|
216
|
+
|
|
217
|
+
var SwitchTrack = _styledComponents["default"].span(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n border-radius: 15px;\n width: ", ";\n height: ", ";\n position: relative;\n transition: transform 0.2s ease;\n\n &:focus-visible {\n outline: none;\n ::before {\n outline: ", ";\n outline-offset: 6px;\n }\n }\n\n /* Thumb element */\n ::before {\n content: \"\";\n transform: initial;\n transition: transform 0.2s ease;\n position: absolute;\n width: ", ";\n height: ", ";\n border-radius: 50%;\n z-index: 1;\n box-shadow: 0px 2px 1px -1px rgb(0 0 0 / 20%), 0px 1px 1px 0px rgb(0 0 0 / 14%), 0px 1px 3px 0px rgb(0 0 0 / 12%);\n bottom: -6px;\n left: -4px;\n transform: translateX(0px);\n background-color: ", ";\n }\n\n /* Unchecked */\n background-color: ", ";\n\n /* Checked */\n &[data-checked=\"true\"] {\n background-color: ", ";\n ::before {\n transform: translateX(", ");\n background-color: ", ";\n }\n }\n"])), function (props) {
|
|
218
|
+
return props.theme.trackWidth;
|
|
152
219
|
}, function (props) {
|
|
153
220
|
return props.theme.trackHeight;
|
|
221
|
+
}, function (props) {
|
|
222
|
+
return "".concat(props.backgroundType === "dark" ? props.theme.thumbFocusColorOnDark : props.theme.thumbFocusColor, " solid 2px");
|
|
154
223
|
}, function (props) {
|
|
155
224
|
return props.theme.thumbWidth;
|
|
156
225
|
}, function (props) {
|
|
@@ -158,38 +227,25 @@ var SwitchContainer = _styledComponents["default"].div(_templateObject || (_temp
|
|
|
158
227
|
}, function (props) {
|
|
159
228
|
return props.backgroundType === "dark" ? props.theme.uncheckedThumbBackgroundColorOnDark : props.theme.uncheckedThumbBackgroundColor;
|
|
160
229
|
}, function (props) {
|
|
161
|
-
return props.backgroundType === "dark" ? props.theme.
|
|
162
|
-
}, function (props) {
|
|
163
|
-
return props.backgroundType === "dark" ? props.theme.disabledUncheckedTrackBackgroundColorOnDark : props.theme.disabledUncheckedTrackBackgroundColor;
|
|
164
|
-
}, function (props) {
|
|
165
|
-
return props.backgroundType === "dark" ? props.theme.disabledCheckedThumbBackgroundColorOnDark : props.theme.disabledCheckedThumbBackgroundColor;
|
|
166
|
-
}, function (props) {
|
|
167
|
-
return props.backgroundType === "dark" ? props.theme.disabledCheckedTrackBackgroundColorOnDark : props.theme.disabledCheckedTrackBackgroundColor;
|
|
230
|
+
return props.backgroundType === "dark" ? props.theme.uncheckedTrackBackgroundColorOnDark : props.theme.uncheckedTrackBackgroundColor;
|
|
168
231
|
}, function (props) {
|
|
169
|
-
return props.backgroundType === "dark" ? props.theme.
|
|
232
|
+
return props.backgroundType === "dark" ? props.theme.checkedTrackBackgroundColorOnDark : props.theme.checkedTrackBackgroundColor;
|
|
170
233
|
}, function (props) {
|
|
171
234
|
return props.theme.thumbShift;
|
|
172
235
|
}, function (props) {
|
|
173
|
-
return props.backgroundType === "dark" ? props.theme.
|
|
236
|
+
return props.backgroundType === "dark" ? props.theme.checkedThumbBackgroundColorOnDark : props.theme.checkedThumbBackgroundColor;
|
|
174
237
|
});
|
|
175
238
|
|
|
176
|
-
var
|
|
177
|
-
return props.
|
|
178
|
-
}, function (props) {
|
|
179
|
-
return props.theme.labelFontFamily;
|
|
180
|
-
}, function (props) {
|
|
181
|
-
return props.theme.labelFontSize;
|
|
182
|
-
}, function (props) {
|
|
183
|
-
return props.disabled ? props.theme.disabledLabelFontStyle : props.theme.labelFontStyle;
|
|
239
|
+
var DisabledSwitchTrack = (0, _styledComponents["default"])(SwitchTrack)(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2["default"])(["\n cursor: not-allowed;\n\n /* Unchecked */\n background-color: ", ";\n\n ::before {\n background-color: ", ";\n }\n\n /* Checked */\n &[data-checked=\"true\"] {\n background-color: ", ";\n\n ::before {\n transform: translateX(", ");\n background-color: ", ";\n }\n }\n"])), function (props) {
|
|
240
|
+
return props.backgroundType === "dark" ? props.theme.disabledUncheckedTrackBackgroundColorOnDark : props.theme.disabledUncheckedTrackBackgroundColor;
|
|
184
241
|
}, function (props) {
|
|
185
|
-
return props.theme.
|
|
242
|
+
return props.backgroundType === "dark" ? props.theme.disabledUncheckedThumbBackgroundColorOnDark : props.theme.disabledUncheckedThumbBackgroundColor;
|
|
186
243
|
}, function (props) {
|
|
187
|
-
return props.
|
|
244
|
+
return props.backgroundType === "dark" ? props.theme.disabledCheckedTrackBackgroundColorOnDark : props.theme.disabledCheckedTrackBackgroundColor;
|
|
188
245
|
}, function (props) {
|
|
189
|
-
return props.
|
|
246
|
+
return props.theme.thumbShift;
|
|
190
247
|
}, function (props) {
|
|
191
|
-
return props.
|
|
248
|
+
return props.backgroundType === "dark" ? props.theme.disabledCheckedThumbBackgroundColorOnDark : props.theme.disabledCheckedThumbBackgroundColor;
|
|
192
249
|
});
|
|
193
|
-
|
|
194
250
|
var _default = DxcSwitch;
|
|
195
251
|
exports["default"] = _default;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { userEvent, within } from "@storybook/testing-library";
|
|
3
2
|
import DxcSwitch from "./Switch";
|
|
4
3
|
import { BackgroundColorProvider } from "../BackgroundColorContext";
|
|
5
4
|
import Title from "../../.storybook/components/Title";
|
|
@@ -21,6 +20,10 @@ export const Chromatic = () => (
|
|
|
21
20
|
<Title title="Without label" theme="light" level={4} />
|
|
22
21
|
<DxcSwitch />
|
|
23
22
|
</ExampleContainer>
|
|
23
|
+
<ExampleContainer pseudoState="pseudo-focus-visible">
|
|
24
|
+
<Title title="Focused" theme="light" level={4} />
|
|
25
|
+
<DxcSwitch label="Switch" labelPosition="after" />
|
|
26
|
+
</ExampleContainer>
|
|
24
27
|
<ExampleContainer>
|
|
25
28
|
<Title title="Checked" theme="light" level={4} />
|
|
26
29
|
<DxcSwitch label="Switch" defaultChecked />
|
|
@@ -47,6 +50,10 @@ export const Chromatic = () => (
|
|
|
47
50
|
<Title title="With label" theme="dark" level={4} />
|
|
48
51
|
<DxcSwitch label="Switch" />
|
|
49
52
|
</ExampleContainer>
|
|
53
|
+
<ExampleContainer pseudoState="pseudo-focus-visible">
|
|
54
|
+
<Title title="Focused" theme="dark" level={4} />
|
|
55
|
+
<DxcSwitch label="Switch" labelPosition="after" />
|
|
56
|
+
</ExampleContainer>
|
|
50
57
|
<ExampleContainer>
|
|
51
58
|
<Title title="Checked" theme="dark" level={4} />
|
|
52
59
|
<DxcSwitch label="Switch" defaultChecked />
|
|
@@ -129,32 +136,3 @@ export const Chromatic = () => (
|
|
|
129
136
|
</ExampleContainer>
|
|
130
137
|
</>
|
|
131
138
|
);
|
|
132
|
-
|
|
133
|
-
const Switch = () => (
|
|
134
|
-
<ExampleContainer>
|
|
135
|
-
<Title title="Focused" theme="light" level={4} />
|
|
136
|
-
<DxcSwitch label="Switch" />
|
|
137
|
-
</ExampleContainer>
|
|
138
|
-
);
|
|
139
|
-
export const FocusedSwitch = Switch.bind({});
|
|
140
|
-
FocusedSwitch.play = async ({ canvasElement }) => {
|
|
141
|
-
const canvas = within(canvasElement);
|
|
142
|
-
canvas.getByRole("switch").focus();
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const DarkSwitch = () => (
|
|
146
|
-
<BackgroundColorProvider color="#333333">
|
|
147
|
-
<DarkContainer>
|
|
148
|
-
<ExampleContainer>
|
|
149
|
-
<Title title="Focused" theme="dark" level={4} />
|
|
150
|
-
<DxcSwitch label="Switch" />
|
|
151
|
-
</ExampleContainer>
|
|
152
|
-
</DarkContainer>
|
|
153
|
-
</BackgroundColorProvider>
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
export const FocusedSwitchOnDark = DarkSwitch.bind({});
|
|
157
|
-
FocusedSwitchOnDark.play = async ({ canvasElement }) => {
|
|
158
|
-
const canvas = within(canvasElement);
|
|
159
|
-
canvas.getByRole("switch").focus();
|
|
160
|
-
};
|
package/switch/Switch.test.js
CHANGED
|
@@ -37,7 +37,7 @@ describe("Switch component tests", function () {
|
|
|
37
37
|
|
|
38
38
|
expect(onChange).toHaveBeenCalled();
|
|
39
39
|
});
|
|
40
|
-
test("
|
|
40
|
+
test("Calls correct function on key down", function () {
|
|
41
41
|
var onChange = jest.fn();
|
|
42
42
|
|
|
43
43
|
var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
@@ -47,6 +47,30 @@ describe("Switch component tests", function () {
|
|
|
47
47
|
})),
|
|
48
48
|
getByText = _render3.getByText;
|
|
49
49
|
|
|
50
|
+
_react2.fireEvent.focus(getByText("SwitchComponent"));
|
|
51
|
+
|
|
52
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
53
|
+
key: "Enter"
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(onChange).toHaveBeenCalled();
|
|
57
|
+
|
|
58
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
59
|
+
key: " "
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expect(onChange).toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
test("Everytime the user clicks the component the onchange function is called with the correct value CONTROLLED COMPONENT", function () {
|
|
65
|
+
var onChange = jest.fn();
|
|
66
|
+
|
|
67
|
+
var _render4 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
68
|
+
label: "SwitchComponent",
|
|
69
|
+
checked: false,
|
|
70
|
+
onChange: onChange
|
|
71
|
+
})),
|
|
72
|
+
getByText = _render4.getByText;
|
|
73
|
+
|
|
50
74
|
_react2.fireEvent.click(getByText("SwitchComponent"));
|
|
51
75
|
|
|
52
76
|
_react2.fireEvent.click(getByText("SwitchComponent"));
|
|
@@ -54,14 +78,60 @@ describe("Switch component tests", function () {
|
|
|
54
78
|
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
55
79
|
expect(onChange.mock.calls[1][0]).toBe(true);
|
|
56
80
|
});
|
|
81
|
+
test("Everytime the user use enter in the component, the onchange function is called with the correct value CONTROLLED COMPONENT", function () {
|
|
82
|
+
var onChange = jest.fn();
|
|
83
|
+
|
|
84
|
+
var _render5 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
85
|
+
label: "SwitchComponent",
|
|
86
|
+
checked: false,
|
|
87
|
+
onChange: onChange
|
|
88
|
+
})),
|
|
89
|
+
getByText = _render5.getByText;
|
|
90
|
+
|
|
91
|
+
_react2.fireEvent.focus(getByText("SwitchComponent"));
|
|
92
|
+
|
|
93
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
94
|
+
key: "Enter"
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
98
|
+
key: "Enter"
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
102
|
+
expect(onChange.mock.calls[1][0]).toBe(true);
|
|
103
|
+
});
|
|
104
|
+
test("Everytime the user use space in the component, the onchange function is called with the correct value CONTROLLED COMPONENT", function () {
|
|
105
|
+
var onChange = jest.fn();
|
|
106
|
+
|
|
107
|
+
var _render6 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
108
|
+
label: "SwitchComponent",
|
|
109
|
+
checked: false,
|
|
110
|
+
onChange: onChange
|
|
111
|
+
})),
|
|
112
|
+
getByText = _render6.getByText;
|
|
113
|
+
|
|
114
|
+
_react2.fireEvent.focus(getByText("SwitchComponent"));
|
|
115
|
+
|
|
116
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
117
|
+
key: " "
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
121
|
+
key: " "
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
125
|
+
expect(onChange.mock.calls[1][0]).toBe(true);
|
|
126
|
+
});
|
|
57
127
|
test("Everytime the user clicks the component the onchange function is called with the correct value UNCONTROLLED COMPONENT", function () {
|
|
58
128
|
var onChange = jest.fn();
|
|
59
129
|
|
|
60
|
-
var
|
|
130
|
+
var _render7 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
61
131
|
label: "SwitchComponent",
|
|
62
132
|
onChange: onChange
|
|
63
133
|
})),
|
|
64
|
-
getByText =
|
|
134
|
+
getByText = _render7.getByText;
|
|
65
135
|
|
|
66
136
|
_react2.fireEvent.click(getByText("SwitchComponent"));
|
|
67
137
|
|
|
@@ -70,13 +140,57 @@ describe("Switch component tests", function () {
|
|
|
70
140
|
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
71
141
|
expect(onChange.mock.calls[1][0]).toBe(false);
|
|
72
142
|
});
|
|
143
|
+
test("Everytime the user use enter in the component, the onchange function is called with the correct value UNCONTROLLED COMPONENT", function () {
|
|
144
|
+
var onChange = jest.fn();
|
|
145
|
+
|
|
146
|
+
var _render8 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
147
|
+
label: "SwitchComponent",
|
|
148
|
+
onChange: onChange
|
|
149
|
+
})),
|
|
150
|
+
getByText = _render8.getByText;
|
|
151
|
+
|
|
152
|
+
_react2.fireEvent.focus(getByText("SwitchComponent"));
|
|
153
|
+
|
|
154
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
155
|
+
key: "Enter"
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
159
|
+
key: "Enter"
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
163
|
+
expect(onChange.mock.calls[1][0]).toBe(false);
|
|
164
|
+
});
|
|
165
|
+
test("Everytime the user use space in the component, the onchange function is called with the correct value UNCONTROLLED COMPONENT", function () {
|
|
166
|
+
var onChange = jest.fn();
|
|
167
|
+
|
|
168
|
+
var _render9 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
169
|
+
label: "SwitchComponent",
|
|
170
|
+
onChange: onChange
|
|
171
|
+
})),
|
|
172
|
+
getByText = _render9.getByText;
|
|
173
|
+
|
|
174
|
+
_react2.fireEvent.focus(getByText("SwitchComponent"));
|
|
175
|
+
|
|
176
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
177
|
+
key: " "
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
_react2.fireEvent.keyDown(getByText("SwitchComponent"), {
|
|
181
|
+
key: " "
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
expect(onChange.mock.calls[0][0]).toBe(true);
|
|
185
|
+
expect(onChange.mock.calls[1][0]).toBe(false);
|
|
186
|
+
});
|
|
73
187
|
test("Renders with correct initial value and initial state when it is uncontrolled", function () {
|
|
74
|
-
var
|
|
188
|
+
var _render10 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
75
189
|
label: "Default label",
|
|
76
190
|
defaultChecked: true,
|
|
77
191
|
value: "test-defaultChecked"
|
|
78
192
|
})),
|
|
79
|
-
getByRole =
|
|
193
|
+
getByRole = _render10.getByRole;
|
|
80
194
|
|
|
81
195
|
var inputEl = getByRole("switch");
|
|
82
196
|
expect(inputEl.checked).toBe(true);
|
|
@@ -84,11 +198,11 @@ describe("Switch component tests", function () {
|
|
|
84
198
|
expect(inputEl.getAttribute("aria-checked")).toBe("true");
|
|
85
199
|
});
|
|
86
200
|
test("Renders with correct aria attributes", function () {
|
|
87
|
-
var
|
|
201
|
+
var _render11 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Switch["default"], {
|
|
88
202
|
label: "Default label"
|
|
89
203
|
})),
|
|
90
|
-
getByRole =
|
|
91
|
-
getByText =
|
|
204
|
+
getByRole = _render11.getByRole,
|
|
205
|
+
getByText = _render11.getByText;
|
|
92
206
|
|
|
93
207
|
var inputEl = getByRole("switch");
|
|
94
208
|
var label = getByText("Default label");
|
package/switch/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
declare type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
|
|
2
|
-
declare type Margin = {
|
|
1
|
+
export declare type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
|
|
2
|
+
export declare type Margin = {
|
|
3
3
|
top?: Space;
|
|
4
4
|
bottom?: Space;
|
|
5
5
|
left?: Space;
|
|
6
6
|
right?: Space;
|
|
7
7
|
};
|
|
8
|
-
declare type
|
|
8
|
+
export declare type SwitchPropsType = {
|
|
9
9
|
/**
|
|
10
10
|
* Initial state of the switch, only when it is uncontrolled.
|
|
11
11
|
*/
|
|
@@ -59,4 +59,3 @@ declare type Props = {
|
|
|
59
59
|
*/
|
|
60
60
|
tabIndex?: number;
|
|
61
61
|
};
|
|
62
|
-
export default Props;
|
package/tabs/Tab.d.ts
ADDED