@dxc-technology/halstack-react 0.0.0-8b133ff → 0.0.0-8b5e703

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.
Files changed (59) hide show
  1. package/HalstackContext.d.ts +4 -2
  2. package/HalstackContext.js +111 -56
  3. package/alert/Alert.js +4 -1
  4. package/badge/Badge.d.ts +1 -1
  5. package/badge/Badge.js +5 -3
  6. package/badge/types.d.ts +1 -0
  7. package/button/Button.js +3 -1
  8. package/checkbox/Checkbox.js +4 -1
  9. package/common/variables.js +177 -64
  10. package/date-input/DateInput.js +5 -2
  11. package/file-input/FileInput.js +9 -6
  12. package/file-input/FileItem.js +7 -5
  13. package/footer/Footer.js +7 -5
  14. package/header/Header.js +7 -4
  15. package/link/Link.d.ts +3 -2
  16. package/link/Link.js +50 -70
  17. package/link/Link.stories.tsx +87 -52
  18. package/link/Link.test.js +7 -15
  19. package/link/types.d.ts +7 -23
  20. package/main.d.ts +3 -2
  21. package/main.js +14 -0
  22. package/number-input/types.d.ts +1 -1
  23. package/package.json +2 -1
  24. package/paginator/Paginator.js +17 -38
  25. package/password-input/PasswordInput.js +7 -4
  26. package/password-input/PasswordInput.test.js +1 -2
  27. package/password-input/types.d.ts +1 -1
  28. package/progress-bar/ProgressBar.js +1 -1
  29. package/progress-bar/ProgressBar.stories.jsx +11 -11
  30. package/quick-nav/QuickNav.js +63 -15
  31. package/quick-nav/QuickNav.stories.tsx +2 -2
  32. package/quick-nav/types.d.ts +4 -4
  33. package/radio-group/Radio.js +1 -1
  34. package/radio-group/RadioGroup.js +8 -6
  35. package/select/Listbox.js +5 -1
  36. package/select/Select.js +37 -47
  37. package/select/Select.stories.tsx +14 -2
  38. package/select/Select.test.js +257 -194
  39. package/spinner/Spinner.js +1 -1
  40. package/switch/Switch.js +4 -1
  41. package/tabs/Tabs.stories.tsx +0 -6
  42. package/tabs-nav/NavTabs.d.ts +7 -0
  43. package/tabs-nav/NavTabs.js +106 -0
  44. package/tabs-nav/NavTabs.stories.tsx +170 -0
  45. package/tabs-nav/NavTabs.test.js +82 -0
  46. package/tabs-nav/Tab.d.ts +4 -0
  47. package/tabs-nav/Tab.js +117 -0
  48. package/tabs-nav/types.d.ts +51 -0
  49. package/tabs-nav/types.js +5 -0
  50. package/text-input/Suggestion.d.ts +4 -0
  51. package/text-input/Suggestion.js +55 -0
  52. package/text-input/TextInput.js +46 -72
  53. package/text-input/TextInput.test.js +1 -1
  54. package/text-input/types.d.ts +14 -2
  55. package/textarea/Textarea.js +10 -19
  56. package/textarea/types.d.ts +1 -1
  57. package/useTranslatedLabels.d.ts +2 -0
  58. package/useTranslatedLabels.js +20 -0
  59. package/wizard/Wizard.js +27 -25
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");
@@ -39,10 +41,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
39
41
 
40
42
  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
43
 
42
- var getNotOptionalErrorMessage = function getNotOptionalErrorMessage() {
43
- return "This field is required. Please, enter a value.";
44
- };
45
-
46
44
  var groupsHaveOptions = function groupsHaveOptions(innerOptions) {
47
45
  return innerOptions[0].hasOwnProperty("options") ? innerOptions[0].options ? innerOptions.some(function (groupOption) {
48
46
  return groupOption.options.length > 0;
@@ -57,6 +55,10 @@ var filteredGroupsHaveOptions = function filteredGroupsHaveOptions(filteredOptio
57
55
  }) : true;
58
56
  };
59
57
 
58
+ var canOpenOptions = function canOpenOptions(options, disabled) {
59
+ return !disabled && (options === null || options === void 0 ? void 0 : options.length) > 0 && groupsHaveOptions(options);
60
+ };
61
+
60
62
  var filterOptionsBySearchValue = function filterOptionsBySearchValue(options, searchValue) {
61
63
  if ((options === null || options === void 0 ? void 0 : options.length) > 0) {
62
64
  if (options[0].options) return options.map(function (optionGroup) {
@@ -132,6 +134,10 @@ var getSelectedOption = function getSelectedOption(value, options, multiple, opt
132
134
  };
133
135
  };
134
136
 
137
+ var notOptionalCheck = function notOptionalCheck(value, multiple, optional) {
138
+ return !optional && (multiple ? value.length === 0 : value === "");
139
+ };
140
+
135
141
  var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
136
142
  var _selectedOption$label;
137
143
 
@@ -193,6 +199,7 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
193
199
  var selectSearchInputRef = (0, _react.useRef)(null);
194
200
  var selectOptionsListRef = (0, _react.useRef)(null);
195
201
  var colorsTheme = (0, _useTheme["default"])();
202
+ var translatedLabels = (0, _useTranslatedLabels["default"])();
196
203
  var optionalItem = {
197
204
  label: placeholder,
198
205
  value: ""
@@ -210,20 +217,8 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
210
217
  selectedOption = _useMemo.selectedOption,
211
218
  singleSelectionIndex = _useMemo.singleSelectionIndex;
212
219
 
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
220
  var openOptions = function openOptions() {
226
- if (!isOpen && canBeOpenOptions()) changeIsOpen(true);
221
+ if (!isOpen && canOpenOptions(options, disabled)) changeIsOpen(true);
227
222
  };
228
223
 
229
224
  var closeOptions = function closeOptions() {
@@ -234,27 +229,21 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
234
229
  };
235
230
 
236
231
  var handleSelectChangeValue = function handleSelectChangeValue(newOption) {
232
+ var newValue;
233
+
237
234
  if (multiple) {
238
- var res = [];
239
- if ((value !== null && value !== void 0 ? value : innerValue).includes(newOption.value)) res = (value !== null && value !== void 0 ? value : innerValue).filter(function (optionVal) {
235
+ if ((value !== null && value !== void 0 ? value : innerValue).includes(newOption.value)) newValue = (value !== null && value !== void 0 ? value : innerValue).filter(function (optionVal) {
240
236
  return optionVal !== newOption.value;
241
- });else res = [].concat((0, _toConsumableArray2["default"])(value !== null && value !== void 0 ? value : innerValue), [newOption.value]);
242
- value !== null && value !== void 0 ? value : setInnerValue(res);
243
- if (notOptionalMultipleCheck(res)) onChange === null || onChange === void 0 ? void 0 : onChange({
244
- value: res,
245
- error: getNotOptionalErrorMessage()
246
- });else onChange === null || onChange === void 0 ? void 0 : onChange({
247
- value: res
248
- });
249
- } else {
250
- value !== null && value !== void 0 ? value : setInnerValue(newOption.value);
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
- }
237
+ });else newValue = [].concat((0, _toConsumableArray2["default"])(value !== null && value !== void 0 ? value : innerValue), [newOption.value]);
238
+ } else newValue = newOption.value;
239
+
240
+ value !== null && value !== void 0 ? value : setInnerValue(newValue);
241
+ notOptionalCheck(newValue, multiple, optional) ? onChange === null || onChange === void 0 ? void 0 : onChange({
242
+ value: newValue,
243
+ error: translatedLabels.formFields.requiredValueErrorMessage
244
+ }) : onChange === null || onChange === void 0 ? void 0 : onChange({
245
+ value: newValue
246
+ });
258
247
  };
259
248
 
260
249
  var handleSelectOnClick = function handleSelectOnClick() {
@@ -275,11 +264,12 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
275
264
  if (!event.currentTarget.contains(event.relatedTarget)) {
276
265
  closeOptions();
277
266
  setSearchValue("");
278
- if (notOptionalCheck(value !== null && value !== void 0 ? value : innerValue)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
279
- value: value !== null && value !== void 0 ? value : innerValue,
280
- error: getNotOptionalErrorMessage()
281
- });else onBlur === null || onBlur === void 0 ? void 0 : onBlur({
282
- value: value !== null && value !== void 0 ? value : innerValue
267
+ var currentValue = value !== null && value !== void 0 ? value : innerValue;
268
+ notOptionalCheck(currentValue, multiple, optional) ? onBlur === null || onBlur === void 0 ? void 0 : onBlur({
269
+ value: currentValue,
270
+ error: translatedLabels.formFields.requiredValueErrorMessage
271
+ }) : onBlur === null || onBlur === void 0 ? void 0 : onBlur({
272
+ value: currentValue
283
273
  });
284
274
  }
285
275
  };
@@ -353,7 +343,7 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
353
343
  value !== null && value !== void 0 ? value : setInnerValue([]);
354
344
  !optional ? onChange === null || onChange === void 0 ? void 0 : onChange({
355
345
  value: [],
356
- error: getNotOptionalErrorMessage()
346
+ error: translatedLabels.formFields.requiredValueErrorMessage
357
347
  }) : onChange === null || onChange === void 0 ? void 0 : onChange({
358
348
  value: []
359
349
  });
@@ -402,7 +392,7 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
402
392
  selectContainerRef.current.focus();
403
393
  },
404
394
  helperText: helperText
405
- }, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, "(Optional)")), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
395
+ }, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, translatedLabels.formFields.optionalLabel)), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
406
396
  disabled: disabled
407
397
  }, helperText), /*#__PURE__*/_react["default"].createElement(Select, {
408
398
  id: selectId,
@@ -434,8 +424,8 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
434
424
  },
435
425
  onClick: handleClearOptionsActionOnClick,
436
426
  tabIndex: -1,
437
- title: "Clear selection",
438
- "aria-label": "Clear selection"
427
+ title: translatedLabels.select.actionClearSelectionTitle,
428
+ "aria-label": translatedLabels.select.actionClearSelectionTitle
439
429
  }, _Icons["default"].clear)), /*#__PURE__*/_react["default"].createElement(SearchableValueContainer, null, /*#__PURE__*/_react["default"].createElement(ValueInput, {
440
430
  name: name,
441
431
  value: multiple ? (value !== null && value !== void 0 ? value : innerValue).join(",") : value !== null && value !== void 0 ? value : innerValue,
@@ -464,8 +454,8 @@ var DxcSelect = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
464
454
  },
465
455
  onClick: handleClearSearchActionOnClick,
466
456
  tabIndex: -1,
467
- title: "Clear search",
468
- "aria-label": "Clear search"
457
+ title: translatedLabels.select.actionClearSearchTitle,
458
+ "aria-label": translatedLabels.select.actionClearSearchTitle
469
459
  }, _Icons["default"].clear), /*#__PURE__*/_react["default"].createElement(CollapseIndicator, {
470
460
  disabled: disabled
471
461
  }, isOpen ? _Icons["default"].arrowUp : _Icons["default"].arrowDown), isOpen && /*#__PURE__*/_react["default"].createElement(_Listbox["default"], {
@@ -371,7 +371,13 @@ const SearchableSelect = () => (
371
371
  const SearchableWithValue = () => (
372
372
  <ExampleContainer expanded>
373
373
  <Title title="Searchable select with value" theme="light" level={4} />
374
- <DxcSelect label="Select Label" searchable defaultValue="1" options={single_options} placeholder="Choose an option" />
374
+ <DxcSelect
375
+ label="Select Label"
376
+ searchable
377
+ defaultValue="1"
378
+ options={single_options}
379
+ placeholder="Choose an option"
380
+ />
375
381
  </ExampleContainer>
376
382
  );
377
383
 
@@ -398,7 +404,13 @@ const DefaultGroupedOptionsSelect = () => (
398
404
  const MultipleGroupedOptionsSelect = () => (
399
405
  <ExampleContainer expanded>
400
406
  <Title title="Grouped options multiple select" theme="light" level={4} />
401
- <DxcSelect label="Label" options={group_options} defaultValue={["0", "2"]} multiple placeholder="Choose an option" />
407
+ <DxcSelect
408
+ label="Label"
409
+ options={group_options}
410
+ defaultValue={["0", "2"]}
411
+ multiple
412
+ placeholder="Choose an option"
413
+ />
402
414
  </ExampleContainer>
403
415
  );
404
416
  const RescaledIcons = () => (