@dxc-technology/halstack-react 5.0.0 → 6.0.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/HalstackContext.d.ts +4 -2
- package/HalstackContext.js +110 -58
- package/accordion/Accordion.stories.tsx +1 -1
- package/accordion-group/AccordionGroup.js +1 -0
- package/alert/Alert.js +4 -1
- package/badge/Badge.d.ts +1 -1
- package/badge/Badge.js +5 -3
- package/badge/types.d.ts +1 -0
- package/bleed/Bleed.js +1 -34
- package/bleed/Bleed.stories.tsx +94 -95
- package/bleed/types.d.ts +1 -1
- package/box/Box.js +22 -32
- package/bulleted-list/BulletedList.d.ts +7 -0
- package/bulleted-list/BulletedList.js +123 -0
- package/bulleted-list/BulletedList.stories.tsx +200 -0
- package/bulleted-list/types.d.ts +11 -0
- package/{list → bulleted-list}/types.js +0 -0
- package/button/Button.js +3 -1
- package/card/Card.js +34 -36
- package/checkbox/Checkbox.js +4 -1
- package/common/variables.js +211 -88
- package/date-input/DateInput.js +5 -2
- package/dropdown/Dropdown.stories.tsx +1 -1
- package/file-input/FileInput.js +9 -6
- package/file-input/FileItem.js +7 -5
- package/flex/Flex.d.ts +4 -0
- package/flex/Flex.js +57 -0
- package/flex/Flex.stories.tsx +103 -0
- package/flex/types.d.ts +21 -0
- package/{radio → flex}/types.js +0 -0
- package/footer/Footer.js +7 -5
- package/footer/Icons.js +1 -1
- package/header/Header.js +7 -4
- package/inset/Inset.js +1 -34
- package/inset/Inset.stories.tsx +36 -36
- package/inset/types.d.ts +1 -1
- package/layout/ApplicationLayout.d.ts +16 -6
- package/layout/ApplicationLayout.js +70 -117
- package/layout/ApplicationLayout.stories.tsx +83 -93
- package/layout/Icons.d.ts +5 -0
- package/layout/Icons.js +13 -2
- package/layout/SidenavContext.d.ts +5 -0
- package/layout/SidenavContext.js +19 -0
- package/layout/types.d.ts +18 -33
- package/link/Link.d.ts +3 -2
- package/link/Link.js +57 -70
- package/link/Link.stories.tsx +88 -53
- package/link/Link.test.js +7 -15
- package/link/types.d.ts +7 -23
- package/main.d.ts +7 -10
- package/main.js +38 -56
- package/number-input/types.d.ts +1 -1
- package/package.json +3 -1
- package/paginator/Paginator.js +17 -38
- package/paginator/Paginator.test.js +42 -0
- package/paragraph/Paragraph.d.ts +6 -0
- package/paragraph/Paragraph.js +38 -0
- package/paragraph/Paragraph.stories.tsx +44 -0
- package/password-input/PasswordInput.js +7 -4
- package/password-input/PasswordInput.test.js +1 -2
- package/password-input/types.d.ts +1 -1
- package/progress-bar/ProgressBar.js +1 -1
- package/progress-bar/ProgressBar.stories.jsx +11 -11
- package/quick-nav/QuickNav.js +74 -20
- package/quick-nav/QuickNav.stories.tsx +43 -16
- package/quick-nav/types.d.ts +4 -4
- package/radio-group/Radio.js +1 -1
- package/radio-group/RadioGroup.js +10 -7
- package/resultsetTable/ResultsetTable.test.js +42 -0
- package/select/Listbox.d.ts +1 -1
- package/select/Listbox.js +35 -8
- package/select/Select.js +83 -78
- package/select/Select.stories.tsx +144 -100
- package/select/Select.test.js +299 -194
- package/select/types.d.ts +3 -4
- package/sidenav/Sidenav.d.ts +6 -5
- package/sidenav/Sidenav.js +172 -52
- package/sidenav/Sidenav.stories.tsx +154 -156
- package/sidenav/Sidenav.test.js +25 -37
- package/sidenav/types.d.ts +50 -27
- package/spinner/Spinner.js +1 -1
- package/switch/Switch.js +4 -1
- package/tabs/Tabs.stories.tsx +0 -6
- package/tabs-nav/NavTabs.d.ts +8 -0
- package/tabs-nav/NavTabs.js +125 -0
- package/tabs-nav/NavTabs.stories.tsx +170 -0
- package/tabs-nav/NavTabs.test.js +82 -0
- package/tabs-nav/Tab.d.ts +4 -0
- package/tabs-nav/Tab.js +132 -0
- package/tabs-nav/types.d.ts +53 -0
- package/{row → tabs-nav}/types.js +0 -0
- package/text-input/Suggestion.d.ts +4 -0
- package/text-input/Suggestion.js +55 -0
- package/text-input/TextInput.js +46 -72
- package/text-input/TextInput.test.js +1 -1
- package/text-input/types.d.ts +14 -2
- package/textarea/Textarea.js +10 -19
- package/textarea/types.d.ts +1 -1
- package/typography/Typography.d.ts +4 -0
- package/typography/Typography.js +131 -0
- package/typography/Typography.stories.tsx +198 -0
- package/typography/types.d.ts +18 -0
- package/{stack → typography}/types.js +0 -0
- package/useTranslatedLabels.d.ts +2 -0
- package/useTranslatedLabels.js +20 -0
- package/wizard/Wizard.js +36 -41
- package/wizard/Wizard.stories.tsx +20 -1
- package/wizard/types.d.ts +4 -3
- package/list/List.d.ts +0 -4
- package/list/List.js +0 -47
- package/list/List.stories.tsx +0 -95
- package/list/types.d.ts +0 -7
- package/radio/Radio.d.ts +0 -4
- package/radio/Radio.js +0 -173
- package/radio/Radio.stories.tsx +0 -192
- package/radio/Radio.test.js +0 -71
- package/radio/types.d.ts +0 -54
- package/row/Row.d.ts +0 -3
- package/row/Row.js +0 -127
- package/row/Row.stories.tsx +0 -237
- package/row/types.d.ts +0 -28
- package/stack/Stack.d.ts +0 -3
- package/stack/Stack.js +0 -97
- package/stack/Stack.stories.tsx +0 -164
- package/stack/types.d.ts +0 -24
- package/text/Text.d.ts +0 -7
- package/text/Text.js +0 -30
- package/text/Text.stories.tsx +0 -19
package/select/Select.js
CHANGED
|
@@ -23,6 +23,8 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
|
23
23
|
|
|
24
24
|
var _useTheme = _interopRequireDefault(require("../useTheme"));
|
|
25
25
|
|
|
26
|
+
var _useTranslatedLabels = _interopRequireDefault(require("../useTranslatedLabels"));
|
|
27
|
+
|
|
26
28
|
var _variables = require("../common/variables.js");
|
|
27
29
|
|
|
28
30
|
var _uuid = require("uuid");
|
|
@@ -33,16 +35,14 @@ var _Icons = _interopRequireDefault(require("./Icons"));
|
|
|
33
35
|
|
|
34
36
|
var _Listbox = _interopRequireDefault(require("./Listbox"));
|
|
35
37
|
|
|
38
|
+
var Popover = _interopRequireWildcard(require("@radix-ui/react-popover"));
|
|
39
|
+
|
|
36
40
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17;
|
|
37
41
|
|
|
38
42
|
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
43
|
|
|
40
44
|
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
45
|
|
|
42
|
-
var getNotOptionalErrorMessage = function getNotOptionalErrorMessage() {
|
|
43
|
-
return "This field is required. Please, enter a value.";
|
|
44
|
-
};
|
|
45
|
-
|
|
46
46
|
var groupsHaveOptions = function groupsHaveOptions(innerOptions) {
|
|
47
47
|
return innerOptions[0].hasOwnProperty("options") ? innerOptions[0].options ? innerOptions.some(function (groupOption) {
|
|
48
48
|
return groupOption.options.length > 0;
|
|
@@ -57,6 +57,10 @@ var filteredGroupsHaveOptions = function filteredGroupsHaveOptions(filteredOptio
|
|
|
57
57
|
}) : true;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
+
var canOpenOptions = function canOpenOptions(options, disabled) {
|
|
61
|
+
return !disabled && (options === null || options === void 0 ? void 0 : options.length) > 0 && groupsHaveOptions(options);
|
|
62
|
+
};
|
|
63
|
+
|
|
60
64
|
var filterOptionsBySearchValue = function filterOptionsBySearchValue(options, searchValue) {
|
|
61
65
|
if ((options === null || options === void 0 ? void 0 : options.length) > 0) {
|
|
62
66
|
if (options[0].options) return options.map(function (optionGroup) {
|
|
@@ -132,6 +136,10 @@ var getSelectedOption = function getSelectedOption(value, options, multiple, opt
|
|
|
132
136
|
};
|
|
133
137
|
};
|
|
134
138
|
|
|
139
|
+
var notOptionalCheck = function notOptionalCheck(value, multiple, optional) {
|
|
140
|
+
return !optional && (multiple ? value.length === 0 : value === "");
|
|
141
|
+
};
|
|
142
|
+
|
|
135
143
|
var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
136
144
|
var _selectedOption$label;
|
|
137
145
|
|
|
@@ -189,10 +197,15 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
189
197
|
isOpen = _useState10[0],
|
|
190
198
|
changeIsOpen = _useState10[1];
|
|
191
199
|
|
|
192
|
-
var
|
|
200
|
+
var _useState11 = (0, _react.useState)(null),
|
|
201
|
+
_useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
|
|
202
|
+
listboxStyles = _useState12[0],
|
|
203
|
+
setListboxStyles = _useState12[1];
|
|
204
|
+
|
|
205
|
+
var selectRef = (0, _react.useRef)(null);
|
|
193
206
|
var selectSearchInputRef = (0, _react.useRef)(null);
|
|
194
|
-
var selectOptionsListRef = (0, _react.useRef)(null);
|
|
195
207
|
var colorsTheme = (0, _useTheme["default"])();
|
|
208
|
+
var translatedLabels = (0, _useTranslatedLabels["default"])();
|
|
196
209
|
var optionalItem = {
|
|
197
210
|
label: placeholder,
|
|
198
211
|
value: ""
|
|
@@ -210,20 +223,8 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
210
223
|
selectedOption = _useMemo.selectedOption,
|
|
211
224
|
singleSelectionIndex = _useMemo.singleSelectionIndex;
|
|
212
225
|
|
|
213
|
-
var notOptionalCheck = function notOptionalCheck(value) {
|
|
214
|
-
return !optional && value === "";
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
var notOptionalMultipleCheck = function notOptionalMultipleCheck(value) {
|
|
218
|
-
return !optional && value.length === 0;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
var canBeOpenOptions = function canBeOpenOptions() {
|
|
222
|
-
return !disabled && (options === null || options === void 0 ? void 0 : options.length) > 0 && groupsHaveOptions(options);
|
|
223
|
-
};
|
|
224
|
-
|
|
225
226
|
var openOptions = function openOptions() {
|
|
226
|
-
if (!isOpen &&
|
|
227
|
+
if (!isOpen && canOpenOptions(options, disabled)) changeIsOpen(true);
|
|
227
228
|
};
|
|
228
229
|
|
|
229
230
|
var closeOptions = function closeOptions() {
|
|
@@ -234,27 +235,21 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
234
235
|
};
|
|
235
236
|
|
|
236
237
|
var handleSelectChangeValue = function handleSelectChangeValue(newOption) {
|
|
238
|
+
var newValue;
|
|
239
|
+
|
|
237
240
|
if (multiple) {
|
|
238
|
-
|
|
239
|
-
if ((value !== null && value !== void 0 ? value : innerValue).includes(newOption.value)) res = (value !== null && value !== void 0 ? value : innerValue).filter(function (optionVal) {
|
|
241
|
+
if ((value !== null && value !== void 0 ? value : innerValue).includes(newOption.value)) newValue = (value !== null && value !== void 0 ? value : innerValue).filter(function (optionVal) {
|
|
240
242
|
return optionVal !== newOption.value;
|
|
241
|
-
});else
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (notOptionalCheck(newOption.value)) onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
252
|
-
value: newOption.value,
|
|
253
|
-
error: getNotOptionalErrorMessage()
|
|
254
|
-
});else onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
255
|
-
value: newOption.value
|
|
256
|
-
});
|
|
257
|
-
}
|
|
243
|
+
});else newValue = [].concat((0, _toConsumableArray2["default"])(value !== null && value !== void 0 ? value : innerValue), [newOption.value]);
|
|
244
|
+
} else newValue = newOption.value;
|
|
245
|
+
|
|
246
|
+
value !== null && value !== void 0 ? value : setInnerValue(newValue);
|
|
247
|
+
notOptionalCheck(newValue, multiple, optional) ? onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
248
|
+
value: newValue,
|
|
249
|
+
error: translatedLabels.formFields.requiredValueErrorMessage
|
|
250
|
+
}) : onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
251
|
+
value: newValue
|
|
252
|
+
});
|
|
258
253
|
};
|
|
259
254
|
|
|
260
255
|
var handleSelectOnClick = function handleSelectOnClick() {
|
|
@@ -275,11 +270,12 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
275
270
|
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
276
271
|
closeOptions();
|
|
277
272
|
setSearchValue("");
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
273
|
+
var currentValue = value !== null && value !== void 0 ? value : innerValue;
|
|
274
|
+
notOptionalCheck(currentValue, multiple, optional) ? onBlur === null || onBlur === void 0 ? void 0 : onBlur({
|
|
275
|
+
value: currentValue,
|
|
276
|
+
error: translatedLabels.formFields.requiredValueErrorMessage
|
|
277
|
+
}) : onBlur === null || onBlur === void 0 ? void 0 : onBlur({
|
|
278
|
+
value: currentValue
|
|
283
279
|
});
|
|
284
280
|
}
|
|
285
281
|
};
|
|
@@ -353,7 +349,7 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
353
349
|
value !== null && value !== void 0 ? value : setInnerValue([]);
|
|
354
350
|
!optional ? onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
355
351
|
value: [],
|
|
356
|
-
error:
|
|
352
|
+
error: translatedLabels.formFields.requiredValueErrorMessage
|
|
357
353
|
}) : onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
358
354
|
value: []
|
|
359
355
|
});
|
|
@@ -369,26 +365,23 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
369
365
|
!multiple && closeOptions();
|
|
370
366
|
setSearchValue("");
|
|
371
367
|
}, [handleSelectChangeValue, closeOptions, multiple]);
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
top: (selectedListOptionEl === null || selectedListOptionEl === void 0 ? void 0 : selectedListOptionEl.offsetTop) - (listEl === null || listEl === void 0 ? void 0 : listEl.clientHeight) / 2
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
}, [isOpen]);
|
|
383
|
-
(0, _react.useLayoutEffect)(function () {
|
|
384
|
-
var _selectOptionsListRef, _visualFocusedOptionE;
|
|
385
|
-
|
|
386
|
-
var visualFocusedOptionEl = selectOptionsListRef === null || selectOptionsListRef === void 0 ? void 0 : (_selectOptionsListRef = selectOptionsListRef.current) === null || _selectOptionsListRef === void 0 ? void 0 : _selectOptionsListRef.querySelectorAll("[role='option']")[visualFocusIndex];
|
|
387
|
-
visualFocusedOptionEl === null || visualFocusedOptionEl === void 0 ? void 0 : (_visualFocusedOptionE = visualFocusedOptionEl.scrollIntoView) === null || _visualFocusedOptionE === void 0 ? void 0 : _visualFocusedOptionE.call(visualFocusedOptionEl, {
|
|
388
|
-
block: "nearest",
|
|
389
|
-
inline: "start"
|
|
368
|
+
|
|
369
|
+
var handleListboxResize = function handleListboxResize() {
|
|
370
|
+
var _selectRef$current;
|
|
371
|
+
|
|
372
|
+
var rect = selectRef === null || selectRef === void 0 ? void 0 : (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 ? void 0 : _selectRef$current.getBoundingClientRect();
|
|
373
|
+
setListboxStyles({
|
|
374
|
+
width: rect === null || rect === void 0 ? void 0 : rect.width
|
|
390
375
|
});
|
|
391
|
-
}
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
(0, _react.useEffect)(function () {
|
|
379
|
+
handleListboxResize();
|
|
380
|
+
window.addEventListener("resize", handleListboxResize);
|
|
381
|
+
return function () {
|
|
382
|
+
window.removeEventListener("resize", handleListboxResize);
|
|
383
|
+
};
|
|
384
|
+
}, [setListboxStyles]);
|
|
392
385
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
393
386
|
theme: colorsTheme.select
|
|
394
387
|
}, /*#__PURE__*/_react["default"].createElement(SelectContainer, {
|
|
@@ -399,12 +392,16 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
399
392
|
id: selectLabelId,
|
|
400
393
|
disabled: disabled,
|
|
401
394
|
onClick: function onClick() {
|
|
402
|
-
|
|
395
|
+
selectRef.current.focus();
|
|
403
396
|
},
|
|
404
397
|
helperText: helperText
|
|
405
|
-
}, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null,
|
|
398
|
+
}, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, translatedLabels.formFields.optionalLabel)), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
|
|
406
399
|
disabled: disabled
|
|
407
|
-
}, helperText), /*#__PURE__*/_react["default"].createElement(
|
|
400
|
+
}, helperText), /*#__PURE__*/_react["default"].createElement(Popover.Root, {
|
|
401
|
+
open: isOpen
|
|
402
|
+
}, /*#__PURE__*/_react["default"].createElement(Popover.Trigger, {
|
|
403
|
+
asChild: true
|
|
404
|
+
}, /*#__PURE__*/_react["default"].createElement(Select, {
|
|
408
405
|
id: selectId,
|
|
409
406
|
disabled: disabled,
|
|
410
407
|
error: error,
|
|
@@ -412,14 +409,14 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
412
409
|
onClick: handleSelectOnClick,
|
|
413
410
|
onFocus: handleSelectOnFocus,
|
|
414
411
|
onKeyDown: handleSelectOnKeyDown,
|
|
415
|
-
ref:
|
|
412
|
+
ref: selectRef,
|
|
416
413
|
tabIndex: tabIndex,
|
|
417
414
|
role: "combobox",
|
|
418
415
|
"aria-controls": optionsListId,
|
|
419
416
|
"aria-disabled": disabled,
|
|
420
417
|
"aria-expanded": isOpen,
|
|
421
418
|
"aria-haspopup": "listbox",
|
|
422
|
-
"aria-labelledby": selectLabelId,
|
|
419
|
+
"aria-labelledby": label ? selectLabelId : undefined,
|
|
423
420
|
"aria-activedescendant": visualFocusIndex >= 0 ? "option-".concat(visualFocusIndex) : undefined,
|
|
424
421
|
"aria-invalid": error ? "true" : "false",
|
|
425
422
|
"aria-errormessage": error ? errorId : undefined,
|
|
@@ -434,8 +431,8 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
434
431
|
},
|
|
435
432
|
onClick: handleClearOptionsActionOnClick,
|
|
436
433
|
tabIndex: -1,
|
|
437
|
-
title:
|
|
438
|
-
"aria-label":
|
|
434
|
+
title: translatedLabels.select.actionClearSelectionTitle,
|
|
435
|
+
"aria-label": translatedLabels.select.actionClearSelectionTitle
|
|
439
436
|
}, _Icons["default"].clear)), /*#__PURE__*/_react["default"].createElement(SearchableValueContainer, null, /*#__PURE__*/_react["default"].createElement(ValueInput, {
|
|
440
437
|
name: name,
|
|
441
438
|
value: multiple ? (value !== null && value !== void 0 ? value : innerValue).join(",") : value !== null && value !== void 0 ? value : innerValue,
|
|
@@ -464,11 +461,21 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
464
461
|
},
|
|
465
462
|
onClick: handleClearSearchActionOnClick,
|
|
466
463
|
tabIndex: -1,
|
|
467
|
-
title:
|
|
468
|
-
"aria-label":
|
|
464
|
+
title: translatedLabels.select.actionClearSearchTitle,
|
|
465
|
+
"aria-label": translatedLabels.select.actionClearSearchTitle
|
|
469
466
|
}, _Icons["default"].clear), /*#__PURE__*/_react["default"].createElement(CollapseIndicator, {
|
|
470
467
|
disabled: disabled
|
|
471
|
-
}, isOpen ? _Icons["default"].arrowUp : _Icons["default"].arrowDown),
|
|
468
|
+
}, isOpen ? _Icons["default"].arrowUp : _Icons["default"].arrowDown))), /*#__PURE__*/_react["default"].createElement(Popover.Content, {
|
|
469
|
+
sideOffset: 4,
|
|
470
|
+
onOpenAutoFocus: function onOpenAutoFocus(event) {
|
|
471
|
+
// Avoid select to lose focus when the list is opened
|
|
472
|
+
event.preventDefault();
|
|
473
|
+
},
|
|
474
|
+
onCloseAutoFocus: function onCloseAutoFocus(event) {
|
|
475
|
+
// Avoid select to lose focus when the list is closed
|
|
476
|
+
event.preventDefault();
|
|
477
|
+
}
|
|
478
|
+
}, /*#__PURE__*/_react["default"].createElement(_Listbox["default"], {
|
|
472
479
|
id: optionsListId,
|
|
473
480
|
currentValue: value !== null && value !== void 0 ? value : innerValue,
|
|
474
481
|
options: searchable ? filteredOptions : options,
|
|
@@ -479,8 +486,8 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
479
486
|
optionalItem: optionalItem,
|
|
480
487
|
searchable: searchable,
|
|
481
488
|
handleOptionOnClick: handleOptionOnClick,
|
|
482
|
-
|
|
483
|
-
})), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
|
|
489
|
+
styles: listboxStyles
|
|
490
|
+
}))), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
|
|
484
491
|
id: errorId,
|
|
485
492
|
"aria-live": error ? "assertive" : "off"
|
|
486
493
|
}, error)));
|
|
@@ -579,9 +586,7 @@ var SelectionNumber = _styledComponents["default"].span(_templateObject7 || (_te
|
|
|
579
586
|
return props.disabled ? "cursor: not-allowed;" : "cursor: default;";
|
|
580
587
|
});
|
|
581
588
|
|
|
582
|
-
var ClearOptionsAction = _styledComponents["default"].button(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n align-content: center;\n width: 23px;\n height: 22px;\n
|
|
583
|
-
return props.theme.fontFamily;
|
|
584
|
-
}, function (props) {
|
|
589
|
+
var ClearOptionsAction = _styledComponents["default"].button(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n align-content: center;\n width: 23px;\n height: 22px;\n border: none;\n padding: 0.25rem;\n ", "\n background-color: ", ";\n color: ", ";\n\n :focus-visible {\n outline: none;\n }\n ", "\n\n svg {\n line-height: 18px;\n }\n"])), function (props) {
|
|
585
590
|
return props.disabled ? "cursor: not-allowed;" : "cursor: pointer;";
|
|
586
591
|
}, function (props) {
|
|
587
592
|
return props.disabled ? "transparent" : props.theme.enabledSelectionIndicatorActionBackgroundColor;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
3
2
|
import { userEvent, within, waitFor } from "@storybook/testing-library";
|
|
4
|
-
import { fireEvent } from "@testing-library/react";
|
|
5
|
-
|
|
6
3
|
import Title from "../../.storybook/components/Title";
|
|
7
4
|
import ExampleContainer from "../../.storybook/components/ExampleContainer";
|
|
8
|
-
|
|
9
5
|
import DxcSelect from "./Select";
|
|
6
|
+
import Listbox from "./Listbox";
|
|
7
|
+
import DxcButton from "../button/Button";
|
|
8
|
+
import DxcCheckbox from "../checkbox/Checkbox";
|
|
10
9
|
|
|
11
10
|
export default {
|
|
12
11
|
title: "Select",
|
|
@@ -340,7 +339,7 @@ const Select = () => (
|
|
|
340
339
|
<DxcSelect label="Label" options={single_options} multiple defaultValue={["1", "2", "3", "4"]} />
|
|
341
340
|
<Title title="Value with ellipsis" theme="light" level={4} />
|
|
342
341
|
<DxcSelect label="Label" options={optionsWithEllipsisMedium} defaultValue="1" size="medium" />
|
|
343
|
-
<Title title="
|
|
342
|
+
<Title title="Options with ellipsis" theme="light" level={4} />
|
|
344
343
|
<DxcSelect
|
|
345
344
|
label="Label"
|
|
346
345
|
placeholder="Choose an option"
|
|
@@ -351,16 +350,103 @@ const Select = () => (
|
|
|
351
350
|
</ExampleContainer>
|
|
352
351
|
</>
|
|
353
352
|
);
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
353
|
+
const SelectListbox = () => (
|
|
354
|
+
<>
|
|
355
|
+
<Title title="Listbox" theme="light" level={2} />
|
|
356
|
+
<Title title="Default with opened listbox" theme="light" level={3} />
|
|
357
|
+
<ExampleContainer>
|
|
358
|
+
<div style={{ display: "flex", gap: "30px", flexDirection: "column", marginBottom: "80px" }}>
|
|
359
|
+
<DxcSelect label="Label" options={single_options} optional placeholder="Choose an option" />
|
|
360
|
+
<DxcCheckbox
|
|
361
|
+
label="You understand the selection and give your consent"
|
|
362
|
+
onChange={() => {}}
|
|
363
|
+
labelPosition="after"
|
|
364
|
+
/>
|
|
365
|
+
<DxcButton label="Submit" onClick={() => {}} size="medium" />
|
|
366
|
+
</div>
|
|
367
|
+
</ExampleContainer>
|
|
368
|
+
<Title title="Listbox option states" theme="light" level={3} />
|
|
369
|
+
<ExampleContainer pseudoState="pseudo-hover">
|
|
370
|
+
<Title title="Hovered option" theme="light" level={4} />
|
|
371
|
+
<Listbox
|
|
372
|
+
id="x"
|
|
373
|
+
currentValue=""
|
|
374
|
+
options={one_option}
|
|
375
|
+
visualFocusIndex={-1}
|
|
376
|
+
lastOptionIndex={0}
|
|
377
|
+
multiple={false}
|
|
378
|
+
optional={false}
|
|
379
|
+
optionalItem={{ label: "Empty", value: "" }}
|
|
380
|
+
searchable={false}
|
|
381
|
+
handleOptionOnClick={() => {}}
|
|
382
|
+
styles={{ width: 360 }}
|
|
383
|
+
/>
|
|
384
|
+
</ExampleContainer>
|
|
385
|
+
<ExampleContainer pseudoState="pseudo-active">
|
|
386
|
+
<Title title="Active option" theme="light" level={4} />
|
|
387
|
+
<Listbox
|
|
388
|
+
id="x"
|
|
389
|
+
currentValue=""
|
|
390
|
+
options={one_option}
|
|
391
|
+
visualFocusIndex={-1}
|
|
392
|
+
lastOptionIndex={0}
|
|
393
|
+
multiple={false}
|
|
394
|
+
optional={false}
|
|
395
|
+
optionalItem={{ label: "Empty", value: "" }}
|
|
396
|
+
searchable={false}
|
|
397
|
+
handleOptionOnClick={() => {}}
|
|
398
|
+
styles={{ width: 360 }}
|
|
399
|
+
/>
|
|
400
|
+
</ExampleContainer>
|
|
401
|
+
<ExampleContainer>
|
|
402
|
+
<Title title="Focused option" theme="light" level={4} />
|
|
403
|
+
<Listbox
|
|
404
|
+
id="x"
|
|
405
|
+
currentValue=""
|
|
406
|
+
options={one_option}
|
|
407
|
+
visualFocusIndex={0}
|
|
408
|
+
lastOptionIndex={0}
|
|
409
|
+
multiple={false}
|
|
410
|
+
optional={false}
|
|
411
|
+
optionalItem={{ label: "Empty", value: "" }}
|
|
412
|
+
searchable={false}
|
|
413
|
+
handleOptionOnClick={() => {}}
|
|
414
|
+
styles={{ width: 360 }}
|
|
415
|
+
/>
|
|
416
|
+
</ExampleContainer>
|
|
417
|
+
<ExampleContainer pseudoState="pseudo-hover">
|
|
418
|
+
<Title title="Hovered selected option" theme="light" level={4} />
|
|
419
|
+
<Listbox
|
|
420
|
+
id="x"
|
|
421
|
+
currentValue="1"
|
|
422
|
+
options={single_options}
|
|
423
|
+
visualFocusIndex={-1}
|
|
424
|
+
lastOptionIndex={3}
|
|
425
|
+
multiple={false}
|
|
426
|
+
optional={false}
|
|
427
|
+
optionalItem={{ label: "Empty", value: "" }}
|
|
428
|
+
searchable={false}
|
|
429
|
+
handleOptionOnClick={() => {}}
|
|
430
|
+
styles={{ width: 360 }}
|
|
431
|
+
/>
|
|
432
|
+
</ExampleContainer>
|
|
433
|
+
<ExampleContainer pseudoState="pseudo-active">
|
|
434
|
+
<Title title="Active selected option" theme="light" level={4} />
|
|
435
|
+
<Listbox
|
|
436
|
+
id="x"
|
|
437
|
+
currentValue="2"
|
|
438
|
+
options={single_options}
|
|
439
|
+
visualFocusIndex={0}
|
|
440
|
+
lastOptionIndex={3}
|
|
441
|
+
multiple={false}
|
|
442
|
+
optional={false}
|
|
443
|
+
optionalItem={{ label: "Empty", value: "" }}
|
|
444
|
+
searchable={false}
|
|
445
|
+
handleOptionOnClick={() => {}}
|
|
446
|
+
styles={{ width: 360 }}
|
|
447
|
+
/>
|
|
448
|
+
</ExampleContainer>
|
|
449
|
+
</>
|
|
364
450
|
);
|
|
365
451
|
const SearchableSelect = () => (
|
|
366
452
|
<ExampleContainer expanded>
|
|
@@ -368,13 +454,18 @@ const SearchableSelect = () => (
|
|
|
368
454
|
<DxcSelect label="Select Label" searchable options={single_options} placeholder="Choose an option" />
|
|
369
455
|
</ExampleContainer>
|
|
370
456
|
);
|
|
371
|
-
const
|
|
457
|
+
const SearchValue = () => (
|
|
372
458
|
<ExampleContainer expanded>
|
|
373
459
|
<Title title="Searchable select with value" theme="light" level={4} />
|
|
374
|
-
<DxcSelect
|
|
460
|
+
<DxcSelect
|
|
461
|
+
label="Select Label"
|
|
462
|
+
searchable
|
|
463
|
+
defaultValue="1"
|
|
464
|
+
options={single_options}
|
|
465
|
+
placeholder="Choose an option"
|
|
466
|
+
/>
|
|
375
467
|
</ExampleContainer>
|
|
376
468
|
);
|
|
377
|
-
|
|
378
469
|
const MultipleSelect = () => (
|
|
379
470
|
<>
|
|
380
471
|
<ExampleContainer expanded>
|
|
@@ -398,7 +489,13 @@ const DefaultGroupedOptionsSelect = () => (
|
|
|
398
489
|
const MultipleGroupedOptionsSelect = () => (
|
|
399
490
|
<ExampleContainer expanded>
|
|
400
491
|
<Title title="Grouped options multiple select" theme="light" level={4} />
|
|
401
|
-
<DxcSelect
|
|
492
|
+
<DxcSelect
|
|
493
|
+
label="Label"
|
|
494
|
+
options={group_options}
|
|
495
|
+
defaultValue={["0", "2"]}
|
|
496
|
+
multiple
|
|
497
|
+
placeholder="Choose an option"
|
|
498
|
+
/>
|
|
402
499
|
</ExampleContainer>
|
|
403
500
|
);
|
|
404
501
|
const RescaledIcons = () => (
|
|
@@ -431,36 +528,7 @@ const MultipleGroupedOptionsSelectWithIcons = () => (
|
|
|
431
528
|
/>
|
|
432
529
|
</ExampleContainer>
|
|
433
530
|
);
|
|
434
|
-
|
|
435
|
-
<ExampleContainer pseudoState="pseudo-hover" expanded>
|
|
436
|
-
<Title title="Hovered Option" theme="light" level={4} />
|
|
437
|
-
<DxcSelect label="Hovered" options={one_option} placeholder="Choose an option" />
|
|
438
|
-
</ExampleContainer>
|
|
439
|
-
);
|
|
440
|
-
const OnlyOneOptionFocused = () => (
|
|
441
|
-
<ExampleContainer pseudoState="pseudo-focus" expanded>
|
|
442
|
-
<Title title="Focused Option" theme="light" level={4} />
|
|
443
|
-
<DxcSelect label="Focused" options={one_option} placeholder="Choose an option" />
|
|
444
|
-
</ExampleContainer>
|
|
445
|
-
);
|
|
446
|
-
const OnlyOneOptionActived = () => (
|
|
447
|
-
<ExampleContainer pseudoState="pseudo-active" expanded>
|
|
448
|
-
<Title title="Actived Option" theme="light" level={4} />
|
|
449
|
-
<DxcSelect label="Actived" options={one_option} placeholder="Choose an option" />
|
|
450
|
-
</ExampleContainer>
|
|
451
|
-
);
|
|
452
|
-
const SelectedOptionHovered = () => (
|
|
453
|
-
<ExampleContainer pseudoState="pseudo-hover" expanded>
|
|
454
|
-
<Title title="Hovered Selected Option" theme="light" level={4} />
|
|
455
|
-
<DxcSelect label="Hovered" defaultValue="1" options={one_option} placeholder="Choose an option" />
|
|
456
|
-
</ExampleContainer>
|
|
457
|
-
);
|
|
458
|
-
const SelectedOptionActived = () => (
|
|
459
|
-
<ExampleContainer pseudoState="pseudo-active" expanded>
|
|
460
|
-
<Title title="Actived Selected Option" theme="light" level={4} />
|
|
461
|
-
<DxcSelect label="Actived" defaultValue="1" options={one_option} placeholder="Choose an option" />
|
|
462
|
-
</ExampleContainer>
|
|
463
|
-
);
|
|
531
|
+
|
|
464
532
|
const MultipleSearchable = () => (
|
|
465
533
|
<ExampleContainer expanded>
|
|
466
534
|
<Title title="Searchable multiple select with value" theme="light" level={4} />
|
|
@@ -474,12 +542,20 @@ const MultipleSearchable = () => (
|
|
|
474
542
|
/>
|
|
475
543
|
</ExampleContainer>
|
|
476
544
|
);
|
|
477
|
-
|
|
478
|
-
|
|
545
|
+
|
|
546
|
+
export const Chromatic = Select.bind({});
|
|
547
|
+
Chromatic.play = async ({ canvasElement }) => {
|
|
548
|
+
const canvas = within(canvasElement);
|
|
549
|
+
await userEvent.click(canvas.getAllByRole("combobox")[24]);
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
export const ListboxStates = SelectListbox.bind({});
|
|
553
|
+
ListboxStates.play = async ({ canvasElement }) => {
|
|
479
554
|
const canvas = within(canvasElement);
|
|
480
555
|
const select = canvas.getByRole("combobox");
|
|
481
556
|
await userEvent.click(select);
|
|
482
557
|
};
|
|
558
|
+
|
|
483
559
|
export const Searchable = SearchableSelect.bind({});
|
|
484
560
|
Searchable.play = async ({ canvasElement }) => {
|
|
485
561
|
const canvas = within(canvasElement);
|
|
@@ -488,14 +564,15 @@ Searchable.play = async ({ canvasElement }) => {
|
|
|
488
564
|
userEvent.type(canvas.getByRole("combobox"), "r");
|
|
489
565
|
});
|
|
490
566
|
};
|
|
491
|
-
|
|
492
|
-
|
|
567
|
+
|
|
568
|
+
export const SearchableWithValue = SearchValue.bind({});
|
|
569
|
+
SearchableWithValue.play = async ({ canvasElement }) => {
|
|
493
570
|
const canvas = within(canvasElement);
|
|
494
571
|
await userEvent.click(canvas.getByRole("combobox"));
|
|
495
572
|
};
|
|
496
573
|
|
|
497
|
-
export const
|
|
498
|
-
|
|
574
|
+
export const MultipleSearchableWithValue = MultipleSearchable.bind({});
|
|
575
|
+
MultipleSearchableWithValue.play = async ({ canvasElement }) => {
|
|
499
576
|
const canvas = within(canvasElement);
|
|
500
577
|
await userEvent.click(canvas.getAllByRole("combobox")[0]);
|
|
501
578
|
};
|
|
@@ -507,75 +584,42 @@ GroupOptionsDisplayed.play = async ({ canvasElement }) => {
|
|
|
507
584
|
await userEvent.click(select);
|
|
508
585
|
};
|
|
509
586
|
|
|
510
|
-
export const
|
|
511
|
-
|
|
587
|
+
export const MultipleOptionsDisplayed = MultipleSelect.bind({});
|
|
588
|
+
MultipleOptionsDisplayed.play = async ({ canvasElement }) => {
|
|
512
589
|
const canvas = within(canvasElement);
|
|
513
590
|
await userEvent.click(canvas.getAllByRole("combobox")[0]);
|
|
514
591
|
};
|
|
515
592
|
|
|
516
|
-
export const
|
|
517
|
-
|
|
518
|
-
const canvas = within(canvasElement);
|
|
519
|
-
const select = canvas.getByRole("combobox");
|
|
520
|
-
await userEvent.click(select);
|
|
521
|
-
};
|
|
522
|
-
export const SelectWithIconsDisplayed = SelectWithIcons.bind({});
|
|
523
|
-
SelectWithIconsDisplayed.play = async ({ canvasElement }) => {
|
|
593
|
+
export const MultipleGroupedOptionsDisplayed = MultipleGroupedOptionsSelect.bind({});
|
|
594
|
+
MultipleGroupedOptionsDisplayed.play = async ({ canvasElement }) => {
|
|
524
595
|
const canvas = within(canvasElement);
|
|
525
596
|
const select = canvas.getByRole("combobox");
|
|
526
597
|
await userEvent.click(select);
|
|
527
598
|
};
|
|
528
599
|
|
|
529
|
-
export const
|
|
530
|
-
|
|
531
|
-
const canvas = within(canvasElement);
|
|
532
|
-
const select = canvas.getByRole("combobox");
|
|
533
|
-
await userEvent.click(select);
|
|
534
|
-
};
|
|
535
|
-
export const SelectMultipleWithIconsDisplayed = SelectMultipleWithIcons.bind({});
|
|
536
|
-
SelectMultipleWithIconsDisplayed.play = async ({ canvasElement }) => {
|
|
600
|
+
export const WithIconsDisplayed = SelectWithIcons.bind({});
|
|
601
|
+
WithIconsDisplayed.play = async ({ canvasElement }) => {
|
|
537
602
|
const canvas = within(canvasElement);
|
|
538
603
|
const select = canvas.getByRole("combobox");
|
|
539
604
|
await userEvent.click(select);
|
|
540
605
|
};
|
|
541
606
|
|
|
542
|
-
export const
|
|
543
|
-
|
|
607
|
+
export const WithRescaledIconsDisplayed = RescaledIcons.bind({});
|
|
608
|
+
WithRescaledIconsDisplayed.play = async ({ canvasElement }) => {
|
|
544
609
|
const canvas = within(canvasElement);
|
|
545
610
|
const select = canvas.getByRole("combobox");
|
|
546
611
|
await userEvent.click(select);
|
|
547
612
|
};
|
|
548
613
|
|
|
549
|
-
export const
|
|
550
|
-
|
|
614
|
+
export const MultipleWithIconsDisplayed = SelectMultipleWithIcons.bind({});
|
|
615
|
+
MultipleWithIconsDisplayed.play = async ({ canvasElement }) => {
|
|
551
616
|
const canvas = within(canvasElement);
|
|
552
617
|
const select = canvas.getByRole("combobox");
|
|
553
618
|
await userEvent.click(select);
|
|
554
619
|
};
|
|
555
620
|
|
|
556
|
-
export const
|
|
557
|
-
|
|
558
|
-
const canvas = within(canvasElement);
|
|
559
|
-
const select = canvas.getByRole("combobox");
|
|
560
|
-
await userEvent.click(select);
|
|
561
|
-
await waitFor(async () => {
|
|
562
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
563
|
-
});
|
|
564
|
-
};
|
|
565
|
-
export const OptionActived = OnlyOneOptionActived.bind({});
|
|
566
|
-
OptionActived.play = async ({ canvasElement }) => {
|
|
567
|
-
const canvas = within(canvasElement);
|
|
568
|
-
const select = canvas.getByRole("combobox");
|
|
569
|
-
await userEvent.click(select);
|
|
570
|
-
};
|
|
571
|
-
export const OptionSelectedHovered = SelectedOptionHovered.bind({});
|
|
572
|
-
OptionSelectedHovered.play = async ({ canvasElement }) => {
|
|
573
|
-
const canvas = within(canvasElement);
|
|
574
|
-
const select = canvas.getByRole("combobox");
|
|
575
|
-
await userEvent.click(select);
|
|
576
|
-
};
|
|
577
|
-
export const OptionSelectedActived = SelectedOptionActived.bind({});
|
|
578
|
-
OptionSelectedActived.play = async ({ canvasElement }) => {
|
|
621
|
+
export const MultipleGroupedWithIconsDisplayed = MultipleGroupedOptionsSelectWithIcons.bind({});
|
|
622
|
+
MultipleGroupedWithIconsDisplayed.play = async ({ canvasElement }) => {
|
|
579
623
|
const canvas = within(canvasElement);
|
|
580
624
|
const select = canvas.getByRole("combobox");
|
|
581
625
|
await userEvent.click(select);
|