@dxc-technology/halstack-react 0.0.0-1c4cbc0 → 0.0.0-1d5e7bf
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.js +15 -14
- package/accordion/Accordion.stories.tsx +1 -1
- package/accordion-group/AccordionGroup.js +1 -0
- 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 +62 -63
- package/bleed/types.d.ts +1 -1
- package/box/Box.js +22 -32
- package/card/Card.js +34 -36
- package/common/variables.js +19 -14
- package/dropdown/Dropdown.stories.tsx +1 -1
- package/footer/Icons.js +1 -1
- package/inline/Inline.d.ts +4 -0
- package/inline/Inline.js +60 -0
- package/inline/Inline.stories.tsx +319 -0
- package/inline/types.d.ts +36 -0
- package/{radio → inline}/types.js +0 -0
- package/inset/Inset.js +1 -34
- package/inset/Inset.stories.tsx +33 -33
- package/inset/types.d.ts +1 -1
- package/layout/ApplicationLayout.d.ts +4 -3
- package/layout/ApplicationLayout.js +83 -102
- package/layout/ApplicationLayout.stories.tsx +14 -59
- 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 +5 -10
- package/link/Link.d.ts +2 -2
- package/link/Link.js +23 -49
- package/link/Link.stories.tsx +1 -1
- package/link/types.d.ts +2 -3
- package/list/List.js +1 -1
- package/list/List.stories.tsx +16 -22
- package/list/types.d.ts +1 -1
- package/main.d.ts +3 -2
- package/main.js +16 -8
- package/package.json +2 -1
- package/paginator/Paginator.test.js +42 -0
- package/progress-bar/ProgressBar.js +1 -1
- package/progress-bar/ProgressBar.stories.jsx +11 -11
- package/quick-nav/QuickNav.js +65 -18
- package/quick-nav/QuickNav.stories.tsx +30 -3
- package/radio-group/RadioGroup.js +2 -1
- package/resultsetTable/ResultsetTable.test.js +42 -0
- package/select/Listbox.d.ts +1 -1
- package/select/Listbox.js +30 -7
- package/select/Select.js +73 -67
- package/select/Select.stories.tsx +130 -98
- package/select/Select.test.js +299 -194
- package/select/types.d.ts +3 -4
- package/sidenav/Sidenav.d.ts +1 -1
- package/sidenav/Sidenav.js +20 -9
- package/stack/Stack.d.ts +2 -1
- package/stack/Stack.js +29 -70
- package/stack/Stack.stories.tsx +189 -90
- package/stack/types.d.ts +15 -7
- 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/tabs-nav/types.js +5 -0
- 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/select/Listbox.js
CHANGED
|
@@ -11,7 +11,7 @@ exports["default"] = void 0;
|
|
|
11
11
|
|
|
12
12
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
13
13
|
|
|
14
|
-
var _react =
|
|
14
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
15
15
|
|
|
16
16
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
17
17
|
|
|
@@ -37,7 +37,7 @@ var groupsHaveOptions = function groupsHaveOptions(options) {
|
|
|
37
37
|
}) : true;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
var Listbox =
|
|
40
|
+
var Listbox = function Listbox(_ref) {
|
|
41
41
|
var id = _ref.id,
|
|
42
42
|
currentValue = _ref.currentValue,
|
|
43
43
|
options = _ref.options,
|
|
@@ -47,9 +47,11 @@ var Listbox = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
47
47
|
optional = _ref.optional,
|
|
48
48
|
optionalItem = _ref.optionalItem,
|
|
49
49
|
searchable = _ref.searchable,
|
|
50
|
-
handleOptionOnClick = _ref.handleOptionOnClick
|
|
50
|
+
handleOptionOnClick = _ref.handleOptionOnClick,
|
|
51
|
+
styles = _ref.styles;
|
|
51
52
|
var colorsTheme = (0, _useTheme["default"])();
|
|
52
53
|
var translatedLabels = (0, _useTranslatedLabels["default"])();
|
|
54
|
+
var listboxRef = (0, _react.useRef)(null);
|
|
53
55
|
var globalIndex = optional && !multiple ? 0 : -1; // index for options, starting from 0 to options.length -1
|
|
54
56
|
|
|
55
57
|
var mapOptionFunc = function mapOptionFunc(option, mapIndex) {
|
|
@@ -92,6 +94,26 @@ var Listbox = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
92
94
|
}
|
|
93
95
|
};
|
|
94
96
|
|
|
97
|
+
(0, _react.useLayoutEffect)(function () {
|
|
98
|
+
if (currentValue && !multiple) {
|
|
99
|
+
var _listEl$scrollTo;
|
|
100
|
+
|
|
101
|
+
var listEl = listboxRef === null || listboxRef === void 0 ? void 0 : listboxRef.current;
|
|
102
|
+
var selectedListOptionEl = listEl === null || listEl === void 0 ? void 0 : listEl.querySelector("[aria-selected='true']");
|
|
103
|
+
listEl === null || listEl === void 0 ? void 0 : (_listEl$scrollTo = listEl.scrollTo) === null || _listEl$scrollTo === void 0 ? void 0 : _listEl$scrollTo.call(listEl, {
|
|
104
|
+
top: (selectedListOptionEl === null || selectedListOptionEl === void 0 ? void 0 : selectedListOptionEl.offsetTop) - (listEl === null || listEl === void 0 ? void 0 : listEl.clientHeight) / 2
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}, [currentValue, multiple]);
|
|
108
|
+
(0, _react.useLayoutEffect)(function () {
|
|
109
|
+
var _listboxRef$current, _visualFocusedOptionE;
|
|
110
|
+
|
|
111
|
+
var visualFocusedOptionEl = listboxRef === null || listboxRef === void 0 ? void 0 : (_listboxRef$current = listboxRef.current) === null || _listboxRef$current === void 0 ? void 0 : _listboxRef$current.querySelectorAll("[role='option']")[visualFocusIndex];
|
|
112
|
+
visualFocusedOptionEl === null || visualFocusedOptionEl === void 0 ? void 0 : (_visualFocusedOptionE = visualFocusedOptionEl.scrollIntoView) === null || _visualFocusedOptionE === void 0 ? void 0 : _visualFocusedOptionE.call(visualFocusedOptionEl, {
|
|
113
|
+
block: "nearest",
|
|
114
|
+
inline: "start"
|
|
115
|
+
});
|
|
116
|
+
}, [visualFocusIndex]);
|
|
95
117
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
96
118
|
theme: colorsTheme.select
|
|
97
119
|
}, /*#__PURE__*/_react["default"].createElement(ListboxContainer, {
|
|
@@ -102,10 +124,11 @@ var Listbox = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
102
124
|
onMouseDown: function onMouseDown(event) {
|
|
103
125
|
event.preventDefault();
|
|
104
126
|
},
|
|
105
|
-
ref:
|
|
127
|
+
ref: listboxRef,
|
|
106
128
|
role: "listbox",
|
|
107
129
|
"aria-multiselectable": multiple,
|
|
108
|
-
"aria-orientation": "vertical"
|
|
130
|
+
"aria-orientation": "vertical",
|
|
131
|
+
style: styles
|
|
109
132
|
}, searchable && (options.length === 0 || !groupsHaveOptions(options)) ? /*#__PURE__*/_react["default"].createElement(OptionsSystemMessage, null, /*#__PURE__*/_react["default"].createElement(NoMatchesFoundIcon, null, _Icons["default"].searchOff), translatedLabels.select.noMatchesErrorMessage) : optional && !multiple && /*#__PURE__*/_react["default"].createElement(_Option["default"], {
|
|
110
133
|
key: "option-".concat(optionalItem.value),
|
|
111
134
|
id: "option-".concat(0),
|
|
@@ -117,9 +140,9 @@ var Listbox = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
117
140
|
isLastOption: lastOptionIndex === 0,
|
|
118
141
|
isSelected: multiple ? currentValue.includes(optionalItem.value) : currentValue === optionalItem.value
|
|
119
142
|
}), options.map(mapOptionFunc)));
|
|
120
|
-
}
|
|
143
|
+
};
|
|
121
144
|
|
|
122
|
-
var ListboxContainer = _styledComponents["default"].ul(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n
|
|
145
|
+
var ListboxContainer = _styledComponents["default"].ul(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n box-sizing: border-box;\n max-height: 304px;\n overflow-y: auto;\n margin: 0;\n padding: 0.25rem 0;\n background-color: ", ";\n border: 1px solid ", ";\n border-radius: 0.25rem;\n box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);\n cursor: default;\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n"])), function (props) {
|
|
123
146
|
return props.theme.listDialogBackgroundColor;
|
|
124
147
|
}, function (props) {
|
|
125
148
|
return props.theme.listDialogBorderColor;
|
package/select/Select.js
CHANGED
|
@@ -35,6 +35,8 @@ var _Icons = _interopRequireDefault(require("./Icons"));
|
|
|
35
35
|
|
|
36
36
|
var _Listbox = _interopRequireDefault(require("./Listbox"));
|
|
37
37
|
|
|
38
|
+
var Popover = _interopRequireWildcard(require("@radix-ui/react-popover"));
|
|
39
|
+
|
|
38
40
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17;
|
|
39
41
|
|
|
40
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); }
|
|
@@ -55,6 +57,10 @@ var filteredGroupsHaveOptions = function filteredGroupsHaveOptions(filteredOptio
|
|
|
55
57
|
}) : true;
|
|
56
58
|
};
|
|
57
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
|
+
|
|
58
64
|
var filterOptionsBySearchValue = function filterOptionsBySearchValue(options, searchValue) {
|
|
59
65
|
if ((options === null || options === void 0 ? void 0 : options.length) > 0) {
|
|
60
66
|
if (options[0].options) return options.map(function (optionGroup) {
|
|
@@ -130,6 +136,10 @@ var getSelectedOption = function getSelectedOption(value, options, multiple, opt
|
|
|
130
136
|
};
|
|
131
137
|
};
|
|
132
138
|
|
|
139
|
+
var notOptionalCheck = function notOptionalCheck(value, multiple, optional) {
|
|
140
|
+
return !optional && (multiple ? value.length === 0 : value === "");
|
|
141
|
+
};
|
|
142
|
+
|
|
133
143
|
var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
134
144
|
var _selectedOption$label;
|
|
135
145
|
|
|
@@ -187,9 +197,13 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
187
197
|
isOpen = _useState10[0],
|
|
188
198
|
changeIsOpen = _useState10[1];
|
|
189
199
|
|
|
190
|
-
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);
|
|
191
206
|
var selectSearchInputRef = (0, _react.useRef)(null);
|
|
192
|
-
var selectOptionsListRef = (0, _react.useRef)(null);
|
|
193
207
|
var colorsTheme = (0, _useTheme["default"])();
|
|
194
208
|
var translatedLabels = (0, _useTranslatedLabels["default"])();
|
|
195
209
|
var optionalItem = {
|
|
@@ -209,20 +223,8 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
209
223
|
selectedOption = _useMemo.selectedOption,
|
|
210
224
|
singleSelectionIndex = _useMemo.singleSelectionIndex;
|
|
211
225
|
|
|
212
|
-
var notOptionalCheck = function notOptionalCheck(value) {
|
|
213
|
-
return !optional && value === "";
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
var notOptionalMultipleCheck = function notOptionalMultipleCheck(value) {
|
|
217
|
-
return !optional && value.length === 0;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
var canBeOpenOptions = function canBeOpenOptions() {
|
|
221
|
-
return !disabled && (options === null || options === void 0 ? void 0 : options.length) > 0 && groupsHaveOptions(options);
|
|
222
|
-
};
|
|
223
|
-
|
|
224
226
|
var openOptions = function openOptions() {
|
|
225
|
-
if (!isOpen &&
|
|
227
|
+
if (!isOpen && canOpenOptions(options, disabled)) changeIsOpen(true);
|
|
226
228
|
};
|
|
227
229
|
|
|
228
230
|
var closeOptions = function closeOptions() {
|
|
@@ -233,27 +235,21 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
233
235
|
};
|
|
234
236
|
|
|
235
237
|
var handleSelectChangeValue = function handleSelectChangeValue(newOption) {
|
|
238
|
+
var newValue;
|
|
239
|
+
|
|
236
240
|
if (multiple) {
|
|
237
|
-
|
|
238
|
-
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) {
|
|
239
242
|
return optionVal !== newOption.value;
|
|
240
|
-
});else
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (notOptionalCheck(newOption.value)) onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
251
|
-
value: newOption.value,
|
|
252
|
-
error: translatedLabels.formFields.requiredValueErrorMessage
|
|
253
|
-
});else onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
254
|
-
value: newOption.value
|
|
255
|
-
});
|
|
256
|
-
}
|
|
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
|
+
});
|
|
257
253
|
};
|
|
258
254
|
|
|
259
255
|
var handleSelectOnClick = function handleSelectOnClick() {
|
|
@@ -274,11 +270,12 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
274
270
|
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
275
271
|
closeOptions();
|
|
276
272
|
setSearchValue("");
|
|
277
|
-
|
|
278
|
-
|
|
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,
|
|
279
276
|
error: translatedLabels.formFields.requiredValueErrorMessage
|
|
280
|
-
})
|
|
281
|
-
value:
|
|
277
|
+
}) : onBlur === null || onBlur === void 0 ? void 0 : onBlur({
|
|
278
|
+
value: currentValue
|
|
282
279
|
});
|
|
283
280
|
}
|
|
284
281
|
};
|
|
@@ -368,26 +365,23 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
368
365
|
!multiple && closeOptions();
|
|
369
366
|
setSearchValue("");
|
|
370
367
|
}, [handleSelectChangeValue, closeOptions, multiple]);
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
top: (selectedListOptionEl === null || selectedListOptionEl === void 0 ? void 0 : selectedListOptionEl.offsetTop) - (listEl === null || listEl === void 0 ? void 0 : listEl.clientHeight) / 2
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
}, [isOpen]);
|
|
382
|
-
(0, _react.useLayoutEffect)(function () {
|
|
383
|
-
var _selectOptionsListRef, _visualFocusedOptionE;
|
|
384
|
-
|
|
385
|
-
var visualFocusedOptionEl = selectOptionsListRef === null || selectOptionsListRef === void 0 ? void 0 : (_selectOptionsListRef = selectOptionsListRef.current) === null || _selectOptionsListRef === void 0 ? void 0 : _selectOptionsListRef.querySelectorAll("[role='option']")[visualFocusIndex];
|
|
386
|
-
visualFocusedOptionEl === null || visualFocusedOptionEl === void 0 ? void 0 : (_visualFocusedOptionE = visualFocusedOptionEl.scrollIntoView) === null || _visualFocusedOptionE === void 0 ? void 0 : _visualFocusedOptionE.call(visualFocusedOptionEl, {
|
|
387
|
-
block: "nearest",
|
|
388
|
-
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
|
|
389
375
|
});
|
|
390
|
-
}
|
|
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]);
|
|
391
385
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
392
386
|
theme: colorsTheme.select
|
|
393
387
|
}, /*#__PURE__*/_react["default"].createElement(SelectContainer, {
|
|
@@ -398,12 +392,16 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
398
392
|
id: selectLabelId,
|
|
399
393
|
disabled: disabled,
|
|
400
394
|
onClick: function onClick() {
|
|
401
|
-
|
|
395
|
+
selectRef.current.focus();
|
|
402
396
|
},
|
|
403
397
|
helperText: helperText
|
|
404
398
|
}, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, translatedLabels.formFields.optionalLabel)), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
|
|
405
399
|
disabled: disabled
|
|
406
|
-
}, 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, {
|
|
407
405
|
id: selectId,
|
|
408
406
|
disabled: disabled,
|
|
409
407
|
error: error,
|
|
@@ -411,14 +409,14 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
411
409
|
onClick: handleSelectOnClick,
|
|
412
410
|
onFocus: handleSelectOnFocus,
|
|
413
411
|
onKeyDown: handleSelectOnKeyDown,
|
|
414
|
-
ref:
|
|
412
|
+
ref: selectRef,
|
|
415
413
|
tabIndex: tabIndex,
|
|
416
414
|
role: "combobox",
|
|
417
415
|
"aria-controls": optionsListId,
|
|
418
416
|
"aria-disabled": disabled,
|
|
419
417
|
"aria-expanded": isOpen,
|
|
420
418
|
"aria-haspopup": "listbox",
|
|
421
|
-
"aria-labelledby": selectLabelId,
|
|
419
|
+
"aria-labelledby": label ? selectLabelId : undefined,
|
|
422
420
|
"aria-activedescendant": visualFocusIndex >= 0 ? "option-".concat(visualFocusIndex) : undefined,
|
|
423
421
|
"aria-invalid": error ? "true" : "false",
|
|
424
422
|
"aria-errormessage": error ? errorId : undefined,
|
|
@@ -467,7 +465,17 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
467
465
|
"aria-label": translatedLabels.select.actionClearSearchTitle
|
|
468
466
|
}, _Icons["default"].clear), /*#__PURE__*/_react["default"].createElement(CollapseIndicator, {
|
|
469
467
|
disabled: disabled
|
|
470
|
-
}, 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"], {
|
|
471
479
|
id: optionsListId,
|
|
472
480
|
currentValue: value !== null && value !== void 0 ? value : innerValue,
|
|
473
481
|
options: searchable ? filteredOptions : options,
|
|
@@ -478,8 +486,8 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
|
478
486
|
optionalItem: optionalItem,
|
|
479
487
|
searchable: searchable,
|
|
480
488
|
handleOptionOnClick: handleOptionOnClick,
|
|
481
|
-
|
|
482
|
-
})), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
|
|
489
|
+
styles: listboxStyles
|
|
490
|
+
}))), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
|
|
483
491
|
id: errorId,
|
|
484
492
|
"aria-live": error ? "assertive" : "off"
|
|
485
493
|
}, error)));
|
|
@@ -578,9 +586,7 @@ var SelectionNumber = _styledComponents["default"].span(_templateObject7 || (_te
|
|
|
578
586
|
return props.disabled ? "cursor: not-allowed;" : "cursor: default;";
|
|
579
587
|
});
|
|
580
588
|
|
|
581
|
-
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
|
|
582
|
-
return props.theme.fontFamily;
|
|
583
|
-
}, 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) {
|
|
584
590
|
return props.disabled ? "cursor: not-allowed;" : "cursor: pointer;";
|
|
585
591
|
}, function (props) {
|
|
586
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,7 +454,7 @@ 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
460
|
<DxcSelect
|
|
@@ -380,7 +466,6 @@ const SearchableWithValue = () => (
|
|
|
380
466
|
/>
|
|
381
467
|
</ExampleContainer>
|
|
382
468
|
);
|
|
383
|
-
|
|
384
469
|
const MultipleSelect = () => (
|
|
385
470
|
<>
|
|
386
471
|
<ExampleContainer expanded>
|
|
@@ -443,36 +528,7 @@ const MultipleGroupedOptionsSelectWithIcons = () => (
|
|
|
443
528
|
/>
|
|
444
529
|
</ExampleContainer>
|
|
445
530
|
);
|
|
446
|
-
|
|
447
|
-
<ExampleContainer pseudoState="pseudo-hover" expanded>
|
|
448
|
-
<Title title="Hovered Option" theme="light" level={4} />
|
|
449
|
-
<DxcSelect label="Hovered" options={one_option} placeholder="Choose an option" />
|
|
450
|
-
</ExampleContainer>
|
|
451
|
-
);
|
|
452
|
-
const OnlyOneOptionFocused = () => (
|
|
453
|
-
<ExampleContainer pseudoState="pseudo-focus" expanded>
|
|
454
|
-
<Title title="Focused Option" theme="light" level={4} />
|
|
455
|
-
<DxcSelect label="Focused" options={one_option} placeholder="Choose an option" />
|
|
456
|
-
</ExampleContainer>
|
|
457
|
-
);
|
|
458
|
-
const OnlyOneOptionActived = () => (
|
|
459
|
-
<ExampleContainer pseudoState="pseudo-active" expanded>
|
|
460
|
-
<Title title="Actived Option" theme="light" level={4} />
|
|
461
|
-
<DxcSelect label="Actived" options={one_option} placeholder="Choose an option" />
|
|
462
|
-
</ExampleContainer>
|
|
463
|
-
);
|
|
464
|
-
const SelectedOptionHovered = () => (
|
|
465
|
-
<ExampleContainer pseudoState="pseudo-hover" expanded>
|
|
466
|
-
<Title title="Hovered Selected Option" theme="light" level={4} />
|
|
467
|
-
<DxcSelect label="Hovered" defaultValue="1" options={one_option} placeholder="Choose an option" />
|
|
468
|
-
</ExampleContainer>
|
|
469
|
-
);
|
|
470
|
-
const SelectedOptionActived = () => (
|
|
471
|
-
<ExampleContainer pseudoState="pseudo-active" expanded>
|
|
472
|
-
<Title title="Actived Selected Option" theme="light" level={4} />
|
|
473
|
-
<DxcSelect label="Actived" defaultValue="1" options={one_option} placeholder="Choose an option" />
|
|
474
|
-
</ExampleContainer>
|
|
475
|
-
);
|
|
531
|
+
|
|
476
532
|
const MultipleSearchable = () => (
|
|
477
533
|
<ExampleContainer expanded>
|
|
478
534
|
<Title title="Searchable multiple select with value" theme="light" level={4} />
|
|
@@ -486,12 +542,20 @@ const MultipleSearchable = () => (
|
|
|
486
542
|
/>
|
|
487
543
|
</ExampleContainer>
|
|
488
544
|
);
|
|
489
|
-
|
|
490
|
-
|
|
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 }) => {
|
|
491
554
|
const canvas = within(canvasElement);
|
|
492
555
|
const select = canvas.getByRole("combobox");
|
|
493
556
|
await userEvent.click(select);
|
|
494
557
|
};
|
|
558
|
+
|
|
495
559
|
export const Searchable = SearchableSelect.bind({});
|
|
496
560
|
Searchable.play = async ({ canvasElement }) => {
|
|
497
561
|
const canvas = within(canvasElement);
|
|
@@ -500,14 +564,15 @@ Searchable.play = async ({ canvasElement }) => {
|
|
|
500
564
|
userEvent.type(canvas.getByRole("combobox"), "r");
|
|
501
565
|
});
|
|
502
566
|
};
|
|
503
|
-
|
|
504
|
-
|
|
567
|
+
|
|
568
|
+
export const SearchableWithValue = SearchValue.bind({});
|
|
569
|
+
SearchableWithValue.play = async ({ canvasElement }) => {
|
|
505
570
|
const canvas = within(canvasElement);
|
|
506
571
|
await userEvent.click(canvas.getByRole("combobox"));
|
|
507
572
|
};
|
|
508
573
|
|
|
509
|
-
export const
|
|
510
|
-
|
|
574
|
+
export const MultipleSearchableWithValue = MultipleSearchable.bind({});
|
|
575
|
+
MultipleSearchableWithValue.play = async ({ canvasElement }) => {
|
|
511
576
|
const canvas = within(canvasElement);
|
|
512
577
|
await userEvent.click(canvas.getAllByRole("combobox")[0]);
|
|
513
578
|
};
|
|
@@ -519,75 +584,42 @@ GroupOptionsDisplayed.play = async ({ canvasElement }) => {
|
|
|
519
584
|
await userEvent.click(select);
|
|
520
585
|
};
|
|
521
586
|
|
|
522
|
-
export const
|
|
523
|
-
|
|
587
|
+
export const MultipleOptionsDisplayed = MultipleSelect.bind({});
|
|
588
|
+
MultipleOptionsDisplayed.play = async ({ canvasElement }) => {
|
|
524
589
|
const canvas = within(canvasElement);
|
|
525
590
|
await userEvent.click(canvas.getAllByRole("combobox")[0]);
|
|
526
591
|
};
|
|
527
592
|
|
|
528
|
-
export const
|
|
529
|
-
|
|
530
|
-
const canvas = within(canvasElement);
|
|
531
|
-
const select = canvas.getByRole("combobox");
|
|
532
|
-
await userEvent.click(select);
|
|
533
|
-
};
|
|
534
|
-
export const SelectWithIconsDisplayed = SelectWithIcons.bind({});
|
|
535
|
-
SelectWithIconsDisplayed.play = async ({ canvasElement }) => {
|
|
593
|
+
export const MultipleGroupedOptionsDisplayed = MultipleGroupedOptionsSelect.bind({});
|
|
594
|
+
MultipleGroupedOptionsDisplayed.play = async ({ canvasElement }) => {
|
|
536
595
|
const canvas = within(canvasElement);
|
|
537
596
|
const select = canvas.getByRole("combobox");
|
|
538
597
|
await userEvent.click(select);
|
|
539
598
|
};
|
|
540
599
|
|
|
541
|
-
export const
|
|
542
|
-
|
|
543
|
-
const canvas = within(canvasElement);
|
|
544
|
-
const select = canvas.getByRole("combobox");
|
|
545
|
-
await userEvent.click(select);
|
|
546
|
-
};
|
|
547
|
-
export const SelectMultipleWithIconsDisplayed = SelectMultipleWithIcons.bind({});
|
|
548
|
-
SelectMultipleWithIconsDisplayed.play = async ({ canvasElement }) => {
|
|
600
|
+
export const WithIconsDisplayed = SelectWithIcons.bind({});
|
|
601
|
+
WithIconsDisplayed.play = async ({ canvasElement }) => {
|
|
549
602
|
const canvas = within(canvasElement);
|
|
550
603
|
const select = canvas.getByRole("combobox");
|
|
551
604
|
await userEvent.click(select);
|
|
552
605
|
};
|
|
553
606
|
|
|
554
|
-
export const
|
|
555
|
-
|
|
607
|
+
export const WithRescaledIconsDisplayed = RescaledIcons.bind({});
|
|
608
|
+
WithRescaledIconsDisplayed.play = async ({ canvasElement }) => {
|
|
556
609
|
const canvas = within(canvasElement);
|
|
557
610
|
const select = canvas.getByRole("combobox");
|
|
558
611
|
await userEvent.click(select);
|
|
559
612
|
};
|
|
560
613
|
|
|
561
|
-
export const
|
|
562
|
-
|
|
614
|
+
export const MultipleWithIconsDisplayed = SelectMultipleWithIcons.bind({});
|
|
615
|
+
MultipleWithIconsDisplayed.play = async ({ canvasElement }) => {
|
|
563
616
|
const canvas = within(canvasElement);
|
|
564
617
|
const select = canvas.getByRole("combobox");
|
|
565
618
|
await userEvent.click(select);
|
|
566
619
|
};
|
|
567
620
|
|
|
568
|
-
export const
|
|
569
|
-
|
|
570
|
-
const canvas = within(canvasElement);
|
|
571
|
-
const select = canvas.getByRole("combobox");
|
|
572
|
-
await userEvent.click(select);
|
|
573
|
-
await waitFor(async () => {
|
|
574
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
575
|
-
});
|
|
576
|
-
};
|
|
577
|
-
export const OptionActived = OnlyOneOptionActived.bind({});
|
|
578
|
-
OptionActived.play = async ({ canvasElement }) => {
|
|
579
|
-
const canvas = within(canvasElement);
|
|
580
|
-
const select = canvas.getByRole("combobox");
|
|
581
|
-
await userEvent.click(select);
|
|
582
|
-
};
|
|
583
|
-
export const OptionSelectedHovered = SelectedOptionHovered.bind({});
|
|
584
|
-
OptionSelectedHovered.play = async ({ canvasElement }) => {
|
|
585
|
-
const canvas = within(canvasElement);
|
|
586
|
-
const select = canvas.getByRole("combobox");
|
|
587
|
-
await userEvent.click(select);
|
|
588
|
-
};
|
|
589
|
-
export const OptionSelectedActived = SelectedOptionActived.bind({});
|
|
590
|
-
OptionSelectedActived.play = async ({ canvasElement }) => {
|
|
621
|
+
export const MultipleGroupedWithIconsDisplayed = MultipleGroupedOptionsSelectWithIcons.bind({});
|
|
622
|
+
MultipleGroupedWithIconsDisplayed.play = async ({ canvasElement }) => {
|
|
591
623
|
const canvas = within(canvasElement);
|
|
592
624
|
const select = canvas.getByRole("combobox");
|
|
593
625
|
await userEvent.click(select);
|