@dxc-technology/halstack-react 0.0.0-8d633bd → 0.0.0-9196773

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 (43) hide show
  1. package/dist/ThemeContext.js +69 -61
  2. package/dist/alert/Alert.js +4 -4
  3. package/dist/alert/index.d.ts +30 -5
  4. package/dist/common/variables.js +199 -47
  5. package/dist/date/Date.js +4 -6
  6. package/dist/{new-date/NewDate.js → date-input/DateInput.js} +69 -72
  7. package/dist/date-input/index.d.ts +95 -0
  8. package/dist/file-input/FileInput.js +11 -8
  9. package/dist/file-input/FileItem.js +25 -8
  10. package/dist/file-input/index.d.ts +81 -0
  11. package/dist/input-text/InputText.js +3 -3
  12. package/dist/main.d.ts +7 -1
  13. package/dist/main.js +22 -14
  14. package/dist/new-select/NewSelect.js +836 -0
  15. package/dist/new-select/index.d.ts +53 -0
  16. package/dist/new-textarea/NewTextarea.js +52 -48
  17. package/dist/new-textarea/index.d.ts +117 -0
  18. package/dist/{number/Number.js → number-input/NumberInput.js} +9 -11
  19. package/dist/{number/NumberContext.js → number-input/NumberInputContext.js} +2 -2
  20. package/dist/number-input/index.d.ts +113 -0
  21. package/dist/{password/Password.js → password-input/PasswordInput.js} +11 -13
  22. package/dist/password-input/index.d.ts +94 -0
  23. package/dist/slider/Slider.js +89 -14
  24. package/dist/{new-input-text/NewInputText.js → text-input/TextInput.js} +129 -135
  25. package/dist/text-input/index.d.ts +135 -0
  26. package/dist/toggle-group/ToggleGroup.js +132 -28
  27. package/dist/upload/Upload.js +3 -3
  28. package/dist/upload/readme.md +2 -2
  29. package/package.json +1 -1
  30. package/test/{NewDate.test.js → DateInput.test.js} +66 -27
  31. package/test/FileInput.test.js +164 -2
  32. package/test/InputText.test.js +24 -16
  33. package/test/NewTextarea.test.js +71 -128
  34. package/test/{Number.test.js → NumberInput.test.js} +84 -66
  35. package/test/PasswordInput.test.js +83 -0
  36. package/test/{NewInputText.test.js → TextInput.test.js} +134 -268
  37. package/test/ToggleGroup.test.js +5 -1
  38. package/test/Upload.test.js +5 -5
  39. package/dist/footer/Footer.stories.js +0 -94
  40. package/dist/input-text/InputText.stories.js +0 -209
  41. package/dist/password/styles.css +0 -3
  42. package/dist/slider/Slider.stories.js +0 -241
  43. package/test/Password.test.js +0 -76
@@ -33,11 +33,21 @@ var _uuid = require("uuid");
33
33
 
34
34
  var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext.js"));
35
35
 
36
- var _NumberContext = _interopRequireDefault(require("../number/NumberContext.js"));
36
+ var _NumberInputContext = _interopRequireDefault(require("../number-input/NumberInputContext.js"));
37
37
 
38
- function _templateObject16() {
38
+ function _templateObject17() {
39
39
  var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n padding: calc((39px - 1.75em) / 2) 0 calc((39px - 1.75em) / 2) 1em;\n align-items: center;\n font-size: 0.875rem;\n line-height: 1.75em;\n"]);
40
40
 
41
+ _templateObject17 = function _templateObject17() {
42
+ return data;
43
+ };
44
+
45
+ return data;
46
+ }
47
+
48
+ function _templateObject16() {
49
+ var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n align-content: center;\n margin-right: 0.5rem;\n height: 18px;\n width: 18px;\n color: ", ";\n\n svg {\n line-height: 1.75em;\n font-size: 0.875rem;\n }\n"]);
50
+
41
51
  _templateObject16 = function _templateObject16() {
42
52
  return data;
43
53
  };
@@ -86,7 +96,7 @@ function _templateObject12() {
86
96
  }
87
97
 
88
98
  function _templateObject11() {
89
- var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n align-content: center;\n padding: 3px;\n height: 18px;\n width: 18px;\n margin-left: calc(1rem * 0.25);\n pointer-events: none;\n color: ", ";\n\n svg {\n line-height: 18px;\n font-size: 1.25rem;\n }\n"]);
99
+ var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n align-content: center;\n padding: 3px;\n height: 18px;\n width: 18px;\n margin-left: calc(1rem * 0.25);\n color: ", ";\n\n svg {\n line-height: 18px;\n font-size: 1.25rem;\n }\n"]);
90
100
 
91
101
  _templateObject11 = function _templateObject11() {
92
102
  return data;
@@ -116,7 +126,7 @@ function _templateObject9() {
116
126
  }
117
127
 
118
128
  function _templateObject8() {
119
- var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n align-content: center;\n height: 24px;\n width: 24px;\n font-size: 1rem;\n font-family: ", ";\n border: 1px solid transparent;\n border-radius: 4px;\n padding: 3px;\n margin-left: calc(1rem * 0.25);\n ", "\n\n background-color: ", ";\n\n color: ", ";\n\n ", "\n\n svg {\n line-height: 18px;\n }\n"]);
129
+ var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n align-content: center;\n height: 24px;\n width: 24px;\n font-size: 1rem;\n font-family: ", ";\n border: 1px solid transparent;\n border-radius: 4px;\n padding: 3px;\n margin-left: calc(1rem * 0.25);\n ", "\n\n box-shadow: 0 0 0 2px transparent;\n background-color: ", ";\n\n color: ", ";\n\n ", "\n\n svg {\n line-height: 18px;\n }\n"]);
120
130
 
121
131
  _templateObject8 = function _templateObject8() {
122
132
  return data;
@@ -156,7 +166,7 @@ function _templateObject5() {
156
166
  }
157
167
 
158
168
  function _templateObject4() {
159
- var data = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: 1.5em;\n"]);
169
+ var data = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n"]);
160
170
 
161
171
  _templateObject4 = function _templateObject4() {
162
172
  return data;
@@ -176,7 +186,7 @@ function _templateObject3() {
176
186
  }
177
187
 
178
188
  function _templateObject2() {
179
- var data = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: 1.75em;\n"]);
189
+ var data = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n"]);
180
190
 
181
191
  _templateObject2 = function _templateObject2() {
182
192
  return data;
@@ -224,15 +234,15 @@ var getLengthErrorMessage = function getLengthErrorMessage(length) {
224
234
  return "Min length ".concat(length.min, ", max length ").concat(length.max, ".");
225
235
  };
226
236
 
227
- var patternMatch = function patternMatch(pattern, value) {
228
- return new RegExp(pattern).test(value);
229
- };
230
-
231
237
  var getPatternErrorMessage = function getPatternErrorMessage() {
232
238
  return "Please match the format requested.";
233
239
  };
234
240
 
235
- var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
241
+ var patternMatch = function patternMatch(pattern, value) {
242
+ return new RegExp(pattern).test(value);
243
+ };
244
+
245
+ var DxcTextInput = _react["default"].forwardRef(function (_ref, ref) {
236
246
  var _ref$label = _ref.label,
237
247
  label = _ref$label === void 0 ? "" : _ref$label,
238
248
  _ref$name = _ref.name,
@@ -257,14 +267,14 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
257
267
  onBlur = _ref.onBlur,
258
268
  _ref$error = _ref.error,
259
269
  error = _ref$error === void 0 ? "" : _ref$error,
260
- margin = _ref.margin,
261
- _ref$size = _ref.size,
262
- size = _ref$size === void 0 ? "medium" : _ref$size,
263
270
  suggestions = _ref.suggestions,
264
271
  pattern = _ref.pattern,
265
272
  length = _ref.length,
266
273
  _ref$autocomplete = _ref.autocomplete,
267
274
  autocomplete = _ref$autocomplete === void 0 ? "off" : _ref$autocomplete,
275
+ margin = _ref.margin,
276
+ _ref$size = _ref.size,
277
+ size = _ref$size === void 0 ? "medium" : _ref$size,
268
278
  _ref$tabIndex = _ref.tabIndex,
269
279
  tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
270
280
 
@@ -298,53 +308,30 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
298
308
  isAutosuggestError = _useState12[0],
299
309
  changeIsAutosuggestError = _useState12[1];
300
310
 
301
- var _useState13 = (0, _react.useState)(""),
311
+ var _useState13 = (0, _react.useState)([]),
302
312
  _useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
303
- validationError = _useState14[0],
304
- changeValidationError = _useState14[1];
313
+ filteredSuggestions = _useState14[0],
314
+ changeFilteredSuggestions = _useState14[1];
305
315
 
306
- var _useState15 = (0, _react.useState)([]),
316
+ var _useState15 = (0, _react.useState)(-1),
307
317
  _useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
308
- filteredSuggestions = _useState16[0],
309
- changeFilteredSuggestions = _useState16[1];
310
-
311
- var _useState17 = (0, _react.useState)(-1),
312
- _useState18 = (0, _slicedToArray2["default"])(_useState17, 2),
313
- visualFocusedSuggIndex = _useState18[0],
314
- changeVisualFocusedSuggIndex = _useState18[1];
318
+ visualFocusedSuggIndex = _useState16[0],
319
+ changeVisualFocusedSuggIndex = _useState16[1];
315
320
 
316
- var _useState19 = (0, _react.useState)(null),
317
- _useState20 = (0, _slicedToArray2["default"])(_useState19, 2),
318
- minNumber = _useState20[0],
319
- setMinNumber = _useState20[1];
320
-
321
- var _useState21 = (0, _react.useState)(null),
322
- _useState22 = (0, _slicedToArray2["default"])(_useState21, 2),
323
- maxNumber = _useState22[0],
324
- setMaxNumber = _useState22[1];
325
-
326
- var _useState23 = (0, _react.useState)(null),
327
- _useState24 = (0, _slicedToArray2["default"])(_useState23, 2),
328
- stepNumber = _useState24[0],
329
- setStepNumber = _useState24[1];
321
+ var _useState17 = (0, _react.useState)("input-".concat((0, _uuid.v4)())),
322
+ _useState18 = (0, _slicedToArray2["default"])(_useState17, 1),
323
+ inputId = _useState18[0];
330
324
 
331
325
  var suggestionsRef = (0, _react.useRef)(null);
332
326
  var inputRef = (0, _react.useRef)(null);
333
327
  var actionRef = (0, _react.useRef)(null);
334
328
  var colorsTheme = (0, _useTheme["default"])();
335
329
  var backgroundType = (0, _react.useContext)(_BackgroundColorContext["default"]);
336
- var inputId = "input-".concat((0, _uuid.v4)());
337
330
  var autosuggestId = "".concat(inputId, "-listBox");
338
331
  var errorId = "error-message-".concat(inputId);
339
- var numberContext = (0, _react.useContext)(_NumberContext["default"]);
340
-
341
- var changeValue = function changeValue(newValue) {
342
- var changedValue = typeof newValue === "number" ? newValue.toString() : newValue;
343
- value !== null && value !== void 0 ? value : setInnerValue(newValue);
344
- typeof onChange === "function" && onChange(changedValue);
345
- };
332
+ var numberInputContext = (0, _react.useContext)(_NumberInputContext["default"]);
346
333
 
347
- var notOptionalCheck = function notOptionalCheck(value) {
334
+ var isNotOptional = function isNotOptional(value) {
348
335
  return value === "" && !optional;
349
336
  };
350
337
 
@@ -353,11 +340,17 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
353
340
  };
354
341
 
355
342
  var isNumberIncorrect = function isNumberIncorrect(value) {
356
- return minNumber && parseInt(value) < minNumber || maxNumber && parseInt(value) > maxNumber;
343
+ return (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber) && parseInt(value) < (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber) || (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber) && parseInt(value) > (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber);
344
+ };
345
+
346
+ var isTextInputType = function isTextInputType() {
347
+ var _inputRef$current, _inputRef$current2;
348
+
349
+ return !(inputRef !== null && inputRef !== void 0 && (_inputRef$current = inputRef.current) !== null && _inputRef$current !== void 0 && _inputRef$current.getAttribute("type")) || (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.getAttribute("type")) === "text";
357
350
  };
358
351
 
359
352
  var getNumberErrorMessage = function getNumberErrorMessage(value) {
360
- if (minNumber && parseInt(value) < minNumber) return "Value must be greater than or equal to ".concat(minNumber, ".");else if (maxNumber && parseInt(value) > maxNumber) return "Value must be less than or equal to ".concat(maxNumber, ".");
353
+ if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.minNumber && parseInt(value) < (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber)) return "Value must be greater than or equal to ".concat(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber, ".");else if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.maxNumber && parseInt(value) > (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber)) return "Value must be less than or equal to ".concat(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber, ".");
361
354
  };
362
355
 
363
356
  var hasInputSuggestions = function hasInputSuggestions() {
@@ -373,6 +366,27 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
373
366
  changeVisualFocusedSuggIndex(-1);
374
367
  };
375
368
 
369
+ var changeValue = function changeValue(newValue) {
370
+ value !== null && value !== void 0 ? value : setInnerValue(newValue);
371
+ var changedValue = typeof newValue === "number" ? newValue.toString() : newValue;
372
+ if (isNotOptional(newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
373
+ value: changedValue,
374
+ error: getNotOptionalErrorMessage()
375
+ });else if (isLengthIncorrect(newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
376
+ value: changedValue,
377
+ error: getLengthErrorMessage(length)
378
+ });else if (newValue && pattern && !patternMatch(pattern, newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
379
+ value: changedValue,
380
+ error: getPatternErrorMessage()
381
+ });else if (newValue && isNumberIncorrect(newValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
382
+ value: changedValue,
383
+ error: getNumberErrorMessage(newValue)
384
+ });else onChange === null || onChange === void 0 ? void 0 : onChange({
385
+ value: changedValue,
386
+ error: null
387
+ });
388
+ };
389
+
376
390
  var handleInputContainerOnClick = function handleInputContainerOnClick() {
377
391
  document.activeElement !== actionRef.current && inputRef.current.focus();
378
392
  };
@@ -388,38 +402,22 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
388
402
 
389
403
  var handleIOnBlur = function handleIOnBlur(event) {
390
404
  suggestions && closeSuggestions();
391
-
392
- if (notOptionalCheck(event.target.value)) {
393
- changeValidationError(getNotOptionalErrorMessage());
394
- onBlur === null || onBlur === void 0 ? void 0 : onBlur({
395
- value: event.target.value,
396
- error: getNotOptionalErrorMessage()
397
- });
398
- } else if (isLengthIncorrect(event.target.value)) {
399
- changeValidationError(getLengthErrorMessage(length, event));
400
- onBlur === null || onBlur === void 0 ? void 0 : onBlur({
401
- value: event.target.value,
402
- error: getLengthErrorMessage(length)
403
- });
404
- } else if (event.target.value && pattern && !patternMatch(pattern, event.target.value)) {
405
- changeValidationError(getPatternErrorMessage());
406
- onBlur === null || onBlur === void 0 ? void 0 : onBlur({
407
- value: event.target.value,
408
- error: getPatternErrorMessage()
409
- });
410
- } else if (event.target.value && isNumberIncorrect(event.target.value)) {
411
- changeValidationError(getNumberErrorMessage(event.target.value));
412
- onBlur === null || onBlur === void 0 ? void 0 : onBlur({
413
- value: event.target.value,
414
- error: getNumberErrorMessage(event.target.value)
415
- });
416
- } else {
417
- changeValidationError("");
418
- onBlur === null || onBlur === void 0 ? void 0 : onBlur({
419
- value: event.target.value,
420
- error: null
421
- });
422
- }
405
+ if (isNotOptional(event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
406
+ value: event.target.value,
407
+ error: getNotOptionalErrorMessage()
408
+ });else if (isLengthIncorrect(event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
409
+ value: event.target.value,
410
+ error: getLengthErrorMessage(length)
411
+ });else if (event.target.value && pattern && !patternMatch(pattern, event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
412
+ value: event.target.value,
413
+ error: getPatternErrorMessage()
414
+ });else if (event.target.value && isNumberIncorrect(event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
415
+ value: event.target.value,
416
+ error: getNumberErrorMessage(event.target.value)
417
+ });else onBlur === null || onBlur === void 0 ? void 0 : onBlur({
418
+ value: event.target.value,
419
+ error: null
420
+ });
423
421
  };
424
422
 
425
423
  var handleIOnFocus = function handleIOnFocus() {
@@ -430,7 +428,7 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
430
428
  switch (event.keyCode) {
431
429
  case 40:
432
430
  // Arrow Down
433
- if (numberContext) {
431
+ if (numberInputContext) {
434
432
  decrementNumber();
435
433
  event.preventDefault();
436
434
  } else {
@@ -450,7 +448,7 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
450
448
 
451
449
  case 38:
452
450
  // Arrow Up
453
- if (numberContext) {
451
+ if (numberInputContext) {
454
452
  incrementNumber();
455
453
  event.preventDefault();
456
454
  } else {
@@ -492,15 +490,12 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
492
490
  };
493
491
 
494
492
  var setNumberProps = function setNumberProps(type, min, max, step) {
495
- var _inputRef$current, _inputRef$current2, _inputRef$current3, _inputRef$current4;
493
+ var _inputRef$current3, _inputRef$current4, _inputRef$current5, _inputRef$current6;
496
494
 
497
- type && (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.setAttribute("type", type));
498
- min && (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.setAttribute("min", min));
499
- max && (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 ? void 0 : _inputRef$current3.setAttribute("max", max));
500
- step && (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current4 = inputRef.current) === null || _inputRef$current4 === void 0 ? void 0 : _inputRef$current4.setAttribute("step", step));
501
- setMinNumber(min);
502
- setMaxNumber(max);
503
- setStepNumber(step);
495
+ type && (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 ? void 0 : _inputRef$current3.setAttribute("type", type));
496
+ min && (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current4 = inputRef.current) === null || _inputRef$current4 === void 0 ? void 0 : _inputRef$current4.setAttribute("min", min));
497
+ max && (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current5 = inputRef.current) === null || _inputRef$current5 === void 0 ? void 0 : _inputRef$current5.setAttribute("max", max));
498
+ step && (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current6 = inputRef.current) === null || _inputRef$current6 === void 0 ? void 0 : _inputRef$current6.setAttribute("step", step));
504
499
  };
505
500
 
506
501
  (0, _react.useLayoutEffect)(function () {
@@ -512,8 +507,6 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
512
507
  return changeIsScrollable(false);
513
508
  }, [isScrollable, visualFocusedSuggIndex]);
514
509
  (0, _react.useEffect)(function () {
515
- var _inputRef$current5;
516
-
517
510
  if (typeof suggestions === "function") {
518
511
  changeIsSearching(true);
519
512
  changeIsAutosuggestError(false);
@@ -539,10 +532,7 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
539
532
  changeVisualFocusedSuggIndex(-1);
540
533
  }
541
534
 
542
- numberContext && setNumberProps(numberContext.typeNumber, numberContext.minNumber, numberContext.maxNumber, numberContext.stepNumber);
543
- inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current5 = inputRef.current) === null || _inputRef$current5 === void 0 ? void 0 : _inputRef$current5.addEventListener("wheel", function (event) {
544
- return event.preventDefault();
545
- });
535
+ numberInputContext && setNumberProps(numberInputContext.typeNumber, numberInputContext.minNumber, numberInputContext.maxNumber, numberInputContext.stepNumber);
546
536
  }, [value, innerValue, suggestions]);
547
537
  var defaultClearAction = {
548
538
  onClick: function onClick() {
@@ -575,18 +565,18 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
575
565
  }));
576
566
 
577
567
  var decrementNumber = function decrementNumber() {
578
- var numberValue = value || innerValue;
568
+ var numberValue = value !== null && value !== void 0 ? value : innerValue;
579
569
 
580
- if (minNumber && parseInt(numberValue) < minNumber) {
570
+ if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.minNumber && parseInt(numberValue) < (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber)) {
581
571
  changeValue(parseInt(numberValue));
582
- } else if (maxNumber && parseInt(numberValue) > maxNumber) {
583
- changeValue(maxNumber);
584
- } else if (minNumber && (parseInt(numberValue) === minNumber || numberValue === "" || stepNumber && parseInt(numberValue) - stepNumber < minNumber)) {
585
- changeValue(minNumber);
586
- } else if (stepNumber && minNumber && parseInt(numberValue) - stepNumber >= minNumber || stepNumber && numberValue !== "") {
587
- changeValue(parseInt(numberValue) - stepNumber);
588
- } else if (stepNumber && numberValue == "") {
589
- changeValue(-stepNumber);
572
+ } else if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.maxNumber && parseInt(numberValue) > (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber)) {
573
+ changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber);
574
+ } else if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.minNumber && (parseInt(numberValue) === (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber) || numberValue === "" || numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.stepNumber && parseInt(numberValue) - (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber) < (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber))) {
575
+ changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber);
576
+ } else if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.stepNumber && numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.minNumber && parseInt(numberValue) - (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber) >= (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber) || numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.stepNumber && numberValue !== "") {
577
+ changeValue(parseInt(numberValue) - (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber));
578
+ } else if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.stepNumber && numberValue == "") {
579
+ changeValue(-(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber));
590
580
  } else if (numberValue === "") {
591
581
  changeValue(-1);
592
582
  } else {
@@ -595,18 +585,18 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
595
585
  };
596
586
 
597
587
  var incrementNumber = function incrementNumber() {
598
- var numberValue = value || innerValue;
588
+ var numberValue = value !== null && value !== void 0 ? value : innerValue;
599
589
 
600
- if (maxNumber && parseInt(numberValue) > maxNumber) {
590
+ if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.maxNumber && parseInt(numberValue) > (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber)) {
601
591
  changeValue(parseInt(numberValue));
602
- } else if (minNumber && (parseInt(numberValue) < minNumber || numberValue === "")) {
603
- changeValue(minNumber);
604
- } else if (maxNumber && (parseInt(numberValue) === maxNumber || stepNumber && parseInt(numberValue) + stepNumber > maxNumber)) {
605
- changeValue(maxNumber);
606
- } else if (stepNumber && maxNumber && parseInt(numberValue) + stepNumber <= maxNumber || stepNumber && numberValue !== "") {
607
- changeValue(parseInt(numberValue) + stepNumber);
608
- } else if (stepNumber && numberValue == "") {
609
- changeValue(stepNumber);
592
+ } else if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.minNumber && (parseInt(numberValue) < (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber) || numberValue === "")) {
593
+ changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber);
594
+ } else if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.maxNumber && (parseInt(numberValue) === (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber) || numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.stepNumber && parseInt(numberValue) + (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber) > (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber))) {
595
+ changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber);
596
+ } else if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.stepNumber && numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.maxNumber && parseInt(numberValue) + (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber) <= (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber) || numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.stepNumber && numberValue !== "") {
597
+ changeValue(parseInt(numberValue) + (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber));
598
+ } else if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.stepNumber && numberValue == "") {
599
+ changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber);
610
600
  } else if (numberValue === "") {
611
601
  changeValue(1);
612
602
  } else {
@@ -651,12 +641,6 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
651
641
  }))
652
642
  };
653
643
 
654
- var isTextInputType = function isTextInputType() {
655
- var _inputRef$current6, _inputRef$current7;
656
-
657
- return !(inputRef !== null && inputRef !== void 0 && (_inputRef$current6 = inputRef.current) !== null && _inputRef$current6 !== void 0 && _inputRef$current6.getAttribute("type")) || (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current7 = inputRef.current) === null || _inputRef$current7 === void 0 ? void 0 : _inputRef$current7.getAttribute("type")) === "text";
658
- };
659
-
660
644
  var HighlightedSuggestion = function HighlightedSuggestion(_ref2) {
661
645
  var suggestion = _ref2.suggestion,
662
646
  index = _ref2.index;
@@ -689,7 +673,7 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
689
673
  };
690
674
 
691
675
  return _react["default"].createElement(_styledComponents.ThemeProvider, {
692
- theme: colorsTheme.newInputText
676
+ theme: colorsTheme.textInput
693
677
  }, _react["default"].createElement(DxcInput, {
694
678
  margin: margin,
695
679
  ref: ref,
@@ -702,7 +686,7 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
702
686
  disabled: disabled,
703
687
  backgroundType: backgroundType
704
688
  }, helperText), _react["default"].createElement(InputContainer, {
705
- error: error || validationError,
689
+ error: error,
706
690
  disabled: disabled,
707
691
  backgroundType: backgroundType,
708
692
  onClick: handleInputContainerOnClick
@@ -723,6 +707,8 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
723
707
  ref: inputRef,
724
708
  backgroundType: backgroundType,
725
709
  pattern: pattern,
710
+ minLength: length === null || length === void 0 ? void 0 : length.min,
711
+ maxLength: length === null || length === void 0 ? void 0 : length.max,
726
712
  autoComplete: autocomplete,
727
713
  tabIndex: tabIndex,
728
714
  role: isTextInputType() && hasInputSuggestions() ? "combobox" : "textbox",
@@ -730,10 +716,10 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
730
716
  "aria-controls": isTextInputType() && hasInputSuggestions() ? inputId : undefined,
731
717
  "aria-expanded": isTextInputType() && hasInputSuggestions() ? isOpen ? "true" : "false" : undefined,
732
718
  "aria-activedescendant": isTextInputType() && hasInputSuggestions() && isOpen && visualFocusedSuggIndex !== -1 ? "suggestion-".concat(visualFocusedSuggIndex) : undefined,
733
- "aria-invalid": error || validationError ? "true" : "false",
734
- "aria-describedby": error || validationError ? errorId : undefined,
719
+ "aria-invalid": error ? "true" : "false",
720
+ "aria-describedby": error ? errorId : undefined,
735
721
  "aria-required": optional ? "false" : "true"
736
- }), !disabled && (error || validationError) && _react["default"].createElement(ErrorIcon, {
722
+ }), !disabled && error && _react["default"].createElement(ErrorIcon, {
737
723
  backgroundType: backgroundType,
738
724
  "aria-label": "Error"
739
725
  }, errorIcon), !disabled && clearable && (value !== null && value !== void 0 ? value : innerValue).length > 0 && _react["default"].createElement(Action, {
@@ -741,7 +727,7 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
741
727
  backgroundType: backgroundType,
742
728
  tabIndex: tabIndex,
743
729
  "aria-label": "Clear"
744
- }, defaultClearAction.icon), (numberContext === null || numberContext === void 0 ? void 0 : numberContext.typeNumber) === "number" ? _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(Action, {
730
+ }, defaultClearAction.icon), (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.typeNumber) === "number" ? _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(Action, {
745
731
  ref: actionRef,
746
732
  disabled: disabled,
747
733
  onClick: decrementAction.onClick,
@@ -784,12 +770,12 @@ var DxcNewInputText = _react["default"].forwardRef(function (_ref, ref) {
784
770
  suggestion: suggestion,
785
771
  index: index
786
772
  });
787
- }), isSearching && _react["default"].createElement(SuggestionsSystemMessage, null, "Searching..."), isAutosuggestError && _react["default"].createElement(SuggestionsError, null, _react["default"].createElement(ErrorIcon, {
773
+ }), isSearching && _react["default"].createElement(SuggestionsSystemMessage, null, "Searching..."), isAutosuggestError && _react["default"].createElement(SuggestionsError, null, _react["default"].createElement(SuggestionsErrorIcon, {
788
774
  backgroundType: backgroundType
789
775
  }, errorIcon), "Error fetching data"))), !disabled && _react["default"].createElement(Error, {
790
776
  id: errorId,
791
777
  backgroundType: backgroundType
792
- }, error || validationError)));
778
+ }, error)));
793
779
  });
794
780
 
795
781
  var sizes = {
@@ -827,6 +813,8 @@ var Label = _styledComponents["default"].label(_templateObject2(), function (pro
827
813
  return props.theme.labelFontStyle;
828
814
  }, function (props) {
829
815
  return props.theme.labelFontWeight;
816
+ }, function (props) {
817
+ return props.theme.labelLineHeight;
830
818
  });
831
819
 
832
820
  var OptionalLabel = _styledComponents["default"].span(_templateObject3(), function (props) {
@@ -843,6 +831,8 @@ var HelperText = _styledComponents["default"].span(_templateObject4(), function
843
831
  return props.theme.helperTextFontStyle;
844
832
  }, function (props) {
845
833
  return props.theme.helperTextFontWeight;
834
+ }, function (props) {
835
+ return props.theme.helperTextLineHeight;
846
836
  });
847
837
 
848
838
  var InputContainer = _styledComponents["default"].div(_templateObject5(), function (props) {
@@ -935,9 +925,13 @@ var SuggestionsSystemMessage = _styledComponents["default"].span(_templateObject
935
925
  return props.theme.systemMessageFontColor;
936
926
  });
937
927
 
938
- var SuggestionsError = _styledComponents["default"].span(_templateObject16());
928
+ var SuggestionsErrorIcon = _styledComponents["default"].span(_templateObject16(), function (props) {
929
+ return props.backgroundType === "dark" ? props.theme.errorIconColorOnDark : props.theme.errorIconColor;
930
+ });
931
+
932
+ var SuggestionsError = _styledComponents["default"].span(_templateObject17());
939
933
 
940
- DxcNewInputText.propTypes = {
934
+ DxcTextInput.propTypes = {
941
935
  label: _propTypes["default"].string,
942
936
  name: _propTypes["default"].string,
943
937
  value: _propTypes["default"].string,
@@ -973,5 +967,5 @@ DxcNewInputText.propTypes = {
973
967
  }),
974
968
  tabIndex: _propTypes["default"].number
975
969
  };
976
- var _default = DxcNewInputText;
970
+ var _default = DxcTextInput;
977
971
  exports["default"] = _default;
@@ -0,0 +1,135 @@
1
+ type Size = "small" | "medium" | "large" | "fillParent";
2
+ type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
3
+ type Margin = {
4
+ top?: Space;
5
+ bottom?: Space;
6
+ left?: Space;
7
+ right?: Space;
8
+ };
9
+ type SVG = string | (HTMLElement & SVGElement);
10
+ type Action = {
11
+ onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
12
+ icon: SVG;
13
+ };
14
+
15
+ type Props = {
16
+ /**
17
+ * Text to be placed above the input. This label will be used as the aria-label attribute of the list of suggestions.
18
+ */
19
+ label?: string;
20
+ /**
21
+ * Name attribute of the input element.
22
+ */
23
+ name?: string;
24
+ /**
25
+ * Value of the input. If undefined, the component will be uncontrolled and the value will be managed internally by the component.
26
+ */
27
+ value?: string;
28
+ /**
29
+ * Helper text to be placed above the input.
30
+ */
31
+ helperText?: string;
32
+ /**
33
+ * Text to be put as placeholder of the input.
34
+ */
35
+ placeholder?: string;
36
+ /**
37
+ * Action to be shown in the input. This is an object composed of an onClick function and an icon,
38
+ * being the latter either an inline svg or a URL to the image.
39
+ */
40
+ action?: Action;
41
+ /**
42
+ * If true, the input will have an action to clear the entered value.
43
+ */
44
+ clearable?: boolean;
45
+ /**
46
+ * If true, the component will be disabled.
47
+ */
48
+ disabled?: boolean;
49
+ /**
50
+ * If true, the input will be optional, showing '(Optional)'
51
+ * next to the label. Otherwise, the field will be considered required and an error will be
52
+ * passed as a parameter to the OnBlur and onChange functions when it has
53
+ * not been filled.
54
+ */
55
+ optional?: boolean;
56
+ /**
57
+ * Prefix to be placed before the input value.
58
+ */
59
+ prefix?: string;
60
+ /**
61
+ * Suffix to be placed after the input value.
62
+ */
63
+ suffix?: string;
64
+ /**
65
+ * This function will be called when the user types within the input
66
+ * element of the component. An object including the current value and
67
+ * the error (if the value entered is not valid) will be passed to this
68
+ * function. If there is no error, error will be null.
69
+ */
70
+ onChange?: (val: { value: string; error: string }) => void;
71
+ /**
72
+ * This function will be called when the input element loses the focus.
73
+ * An object including the input value and the error (if the value
74
+ * entered is not valid) will be passed to this function. If there is no error,
75
+ * error will be null.
76
+ */
77
+ onBlur?: (obj: { value: string; error: string }) => void;
78
+ /**
79
+ * If it is defined, the component will change its appearance, showing
80
+ * the error below the input component. If it is not defined, the error
81
+ * messages will be managed internally, but never displayed on its own.
82
+ */
83
+ error?: string;
84
+ /**
85
+ * These are the options to be displayed as suggestions. It can be either an array or a function:
86
+ * - Array: Array of options that will be filtered by the component.
87
+ * - Function: This function will be called when the user changes the value, we will send as a parameter the new value;
88
+ * apart from that this function should return one promise on which we should make 'then' to get the suggestions filtered.
89
+ */
90
+ suggestions?: string[] | (() => void);
91
+ /**
92
+ * Regular expression that defines the valid format allowed by the input.
93
+ * This will be checked both when the input element loses the focus and
94
+ * while typing within it. If the string entered does not match the
95
+ * pattern, the onBlur and onChange functions will be called with the
96
+ * current value and an internal error informing that this value does not
97
+ * match the pattern. If the pattern is met, the error parameter of both
98
+ * events will be null.
99
+ */
100
+ pattern?: string;
101
+ /**
102
+ * Specifies the minimun and maximum length allowed by the input.
103
+ * This will be checked both when the input element loses the
104
+ * focus and while typing within it. If the string entered does not
105
+ * comply the length, the onBlur and onChange functions will be called
106
+ * with the current value and an internal error informing that the value
107
+ * length does not comply the specified range. If a valid length is
108
+ * reached, the error parameter of both events will be null.
109
+ */
110
+ length?: { min?: number; max?: number };
111
+ /**
112
+ * HTML autocomplete attribute. Lets the user specify if any permission the user agent has to provide automated assistance in filling out the input value.
113
+ * Its value must be one of all the possible values of the HTML autocomplete attribute: 'on', 'off', 'email', 'username', 'new-password', ...
114
+ */
115
+ autocomplete?: string;
116
+ /**
117
+ * Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
118
+ * You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
119
+ */
120
+ margin?: Space | Margin;
121
+ /**
122
+ * Size of the component ('small' | 'medium' | 'large' | 'fillParent').
123
+ */
124
+ size?: Size;
125
+ /**
126
+ * Value of the tabindex attribute.
127
+ */
128
+ tabIndex?: number;
129
+ /**
130
+ * Reference to the component.
131
+ */
132
+ ref?: React.RefObject<HTMLDivElement>;
133
+ };
134
+
135
+ export default function DxcTextInput(props: Props): JSX.Element;