@dxc-technology/halstack-react 10.0.0 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HalstackContext.d.ts +8 -0
- package/README.md +47 -0
- package/common/variables.d.ts +8 -0
- package/common/variables.js +8 -0
- package/footer/Footer.stories.tsx +8 -7
- package/image/Image.d.ts +4 -0
- package/image/Image.js +85 -0
- package/image/Image.stories.tsx +127 -0
- package/image/types.d.ts +72 -0
- package/layout/ApplicationLayout.js +11 -11
- package/layout/ApplicationLayout.stories.tsx +1 -1
- package/layout/Icons.d.ts +7 -4
- package/layout/Icons.js +52 -56
- package/main.d.ts +2 -1
- package/main.js +8 -0
- package/number-input/NumberInput.d.ts +7 -0
- package/number-input/NumberInput.js +6 -4
- package/number-input/NumberInput.test.js +278 -95
- package/package.json +2 -2
- package/password-input/Icons.d.ts +6 -0
- package/password-input/Icons.js +39 -0
- package/password-input/PasswordInput.js +35 -82
- package/password-input/PasswordInput.stories.tsx +1 -0
- package/password-input/PasswordInput.test.js +27 -34
- package/select/Select.stories.tsx +3 -3
- package/select/Select.test.js +4 -4
- package/text-input/TextInput.js +61 -77
- package/toggle-group/ToggleGroup.js +79 -56
- package/toggle-group/ToggleGroup.stories.tsx +6 -3
- package/toggle-group/ToggleGroup.test.js +37 -23
- package/toggle-group/types.d.ts +22 -13
- package/useTheme.d.ts +8 -0
- package/number-input/NumberInputContext.d.ts +0 -4
- package/number-input/NumberInputContext.js +0 -19
- package/number-input/numberInputContextTypes.d.ts +0 -19
- /package/{number-input/numberInputContextTypes.js → image/types.js} +0 -0
package/text-input/TextInput.js
CHANGED
|
@@ -29,7 +29,7 @@ var _utils = require("../common/utils");
|
|
|
29
29
|
|
|
30
30
|
var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext"));
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var _NumberInput = require("../number-input/NumberInput");
|
|
33
33
|
|
|
34
34
|
var _Suggestions = _interopRequireDefault(require("./Suggestions"));
|
|
35
35
|
|
|
@@ -88,20 +88,20 @@ var hasSuggestions = function hasSuggestions(suggestions) {
|
|
|
88
88
|
return typeof suggestions === "function" || (suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) > 0;
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
var
|
|
91
|
+
var isRequired = function isRequired(value, optional) {
|
|
92
92
|
return value === "" && !optional;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
var isLengthIncorrect = function isLengthIncorrect(value, minLength, maxLength) {
|
|
96
|
-
return value
|
|
96
|
+
return value != null && (value.length < minLength || value.length > maxLength);
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
var isNumberIncorrect = function isNumberIncorrect(value, minNumber, maxNumber) {
|
|
100
|
-
return
|
|
100
|
+
return value < minNumber || value > maxNumber;
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
var
|
|
104
|
-
return pattern && !new RegExp(pattern).test(value);
|
|
103
|
+
var patternMismatch = function patternMismatch(pattern, value) {
|
|
104
|
+
return pattern != null && !new RegExp(pattern).test(value);
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
|
|
@@ -182,10 +182,10 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, re
|
|
|
182
182
|
var colorsTheme = (0, _useTheme["default"])();
|
|
183
183
|
var translatedLabels = (0, _useTranslatedLabels["default"])();
|
|
184
184
|
var backgroundType = (0, _react.useContext)(_BackgroundColorContext["default"]);
|
|
185
|
-
var numberInputContext = (0, _react.useContext)(
|
|
185
|
+
var numberInputContext = (0, _react.useContext)(_NumberInput.NumberInputContext);
|
|
186
186
|
|
|
187
187
|
var getNumberErrorMessage = function getNumberErrorMessage(value) {
|
|
188
|
-
if (
|
|
188
|
+
if (value < (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber)) return translatedLabels.numberInput.valueGreaterThanOrEqualToErrorMessage(numberInputContext.minNumber);else if (value > (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber)) return translatedLabels.numberInput.valueLessThanOrEqualToErrorMessage(numberInputContext.maxNumber);
|
|
189
189
|
};
|
|
190
190
|
|
|
191
191
|
var getTextInputWidth = (0, _react.useCallback)(function () {
|
|
@@ -207,22 +207,22 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, re
|
|
|
207
207
|
};
|
|
208
208
|
|
|
209
209
|
var changeValue = function changeValue(newValue) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (
|
|
213
|
-
value:
|
|
210
|
+
var formattedValue = typeof newValue === "number" ? newValue.toString() : newValue;
|
|
211
|
+
value !== null && value !== void 0 ? value : setInnerValue(formattedValue);
|
|
212
|
+
if (isRequired(formattedValue, optional)) onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
213
|
+
value: formattedValue,
|
|
214
214
|
error: translatedLabels.formFields.requiredValueErrorMessage
|
|
215
|
-
});else if (isLengthIncorrect(
|
|
216
|
-
value:
|
|
215
|
+
});else if (isLengthIncorrect(formattedValue, minLength, maxLength)) onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
216
|
+
value: formattedValue,
|
|
217
217
|
error: translatedLabels.formFields.lengthErrorMessage(minLength, maxLength)
|
|
218
|
-
});else if (
|
|
219
|
-
value:
|
|
218
|
+
});else if (patternMismatch(pattern, formattedValue)) onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
219
|
+
value: formattedValue,
|
|
220
220
|
error: translatedLabels.formFields.formatRequestedErrorMessage
|
|
221
|
-
});else if (isNumberIncorrect(newValue, numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber, numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber)) onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
222
|
-
value:
|
|
223
|
-
error: getNumberErrorMessage(newValue)
|
|
221
|
+
});else if ((numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.typeNumber) === "number" && isNumberIncorrect(Number(newValue), numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber, numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber)) onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
222
|
+
value: formattedValue,
|
|
223
|
+
error: getNumberErrorMessage(Number(newValue))
|
|
224
224
|
});else onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
225
|
-
value:
|
|
225
|
+
value: formattedValue
|
|
226
226
|
});
|
|
227
227
|
};
|
|
228
228
|
|
|
@@ -242,18 +242,18 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, re
|
|
|
242
242
|
|
|
243
243
|
var handleInputOnBlur = function handleInputOnBlur(event) {
|
|
244
244
|
closeSuggestions();
|
|
245
|
-
if (
|
|
245
|
+
if (isRequired(event.target.value, optional)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
|
|
246
246
|
value: event.target.value,
|
|
247
247
|
error: translatedLabels.formFields.requiredValueErrorMessage
|
|
248
248
|
});else if (isLengthIncorrect(event.target.value, minLength, maxLength)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
|
|
249
249
|
value: event.target.value,
|
|
250
250
|
error: translatedLabels.formFields.lengthErrorMessage(minLength, maxLength)
|
|
251
|
-
});else if (
|
|
251
|
+
});else if (patternMismatch(pattern, event.target.value)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
|
|
252
252
|
value: event.target.value,
|
|
253
253
|
error: translatedLabels.formFields.formatRequestedErrorMessage
|
|
254
|
-
});else if (isNumberIncorrect(event.target.value, numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber, numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
|
|
254
|
+
});else if ((numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.typeNumber) === "number" && isNumberIncorrect(Number(event.target.value), numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber, numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber)) onBlur === null || onBlur === void 0 ? void 0 : onBlur({
|
|
255
255
|
value: event.target.value,
|
|
256
|
-
error: getNumberErrorMessage(event.target.value)
|
|
256
|
+
error: getNumberErrorMessage(Number(event.target.value))
|
|
257
257
|
});else onBlur === null || onBlur === void 0 ? void 0 : onBlur({
|
|
258
258
|
value: event.target.value
|
|
259
259
|
});
|
|
@@ -338,49 +338,33 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, re
|
|
|
338
338
|
var setNumberProps = function setNumberProps(type, min, max, step) {
|
|
339
339
|
var _inputRef$current2, _inputRef$current3, _inputRef$current4, _inputRef$current5;
|
|
340
340
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
341
|
+
min && (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.setAttribute("min", min));
|
|
342
|
+
max && (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 ? void 0 : _inputRef$current3.setAttribute("max", max));
|
|
343
|
+
inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current4 = inputRef.current) === null || _inputRef$current4 === void 0 ? void 0 : _inputRef$current4.setAttribute("step", step);
|
|
344
|
+
inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current5 = inputRef.current) === null || _inputRef$current5 === void 0 ? void 0 : _inputRef$current5.setAttribute("type", type);
|
|
345
345
|
};
|
|
346
346
|
|
|
347
347
|
var decrementNumber = function decrementNumber() {
|
|
348
|
-
var
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber);
|
|
354
|
-
} 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))) {
|
|
355
|
-
changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber);
|
|
356
|
-
} 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 !== "") {
|
|
357
|
-
changeValue(parseInt(numberValue) - (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber));
|
|
358
|
-
} else if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.stepNumber && numberValue == "") {
|
|
359
|
-
changeValue(-(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber));
|
|
360
|
-
} else if (numberValue === "") {
|
|
361
|
-
changeValue(-1);
|
|
348
|
+
var currentValue = value !== null && value !== void 0 ? value : innerValue;
|
|
349
|
+
var numberValue = Number(currentValue);
|
|
350
|
+
var steppedValue = Math.round((numberValue - (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber) + Number.EPSILON) * 100) / 100;
|
|
351
|
+
|
|
352
|
+
if (currentValue !== "") {
|
|
353
|
+
if (numberValue < (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber) || steppedValue < (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber)) changeValue(numberValue);else if (numberValue > (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber)) changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber);else if (numberValue === (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber)) changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber);else changeValue(steppedValue);
|
|
362
354
|
} else {
|
|
363
|
-
changeValue(
|
|
355
|
+
if ((numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber) >= 0) changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber);else if ((numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber) < 0) changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber);else changeValue(-numberInputContext.stepNumber);
|
|
364
356
|
}
|
|
365
357
|
};
|
|
366
358
|
|
|
367
359
|
var incrementNumber = function incrementNumber() {
|
|
368
|
-
var
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber);
|
|
374
|
-
} 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))) {
|
|
375
|
-
changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber);
|
|
376
|
-
} 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 !== "") {
|
|
377
|
-
changeValue(parseInt(numberValue) + (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber));
|
|
378
|
-
} else if (numberInputContext !== null && numberInputContext !== void 0 && numberInputContext.stepNumber && numberValue == "") {
|
|
379
|
-
changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber);
|
|
380
|
-
} else if (numberValue === "") {
|
|
381
|
-
changeValue(1);
|
|
360
|
+
var currentValue = value !== null && value !== void 0 ? value : innerValue;
|
|
361
|
+
var numberValue = Number(currentValue);
|
|
362
|
+
var steppedValue = Math.round((numberValue + (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.stepNumber) + Number.EPSILON) * 100) / 100;
|
|
363
|
+
|
|
364
|
+
if (currentValue !== "") {
|
|
365
|
+
if (numberValue > (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber) || steppedValue > (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber)) changeValue(numberValue);else if (numberValue < (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber)) changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber);else if (numberValue === (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber)) changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber);else changeValue(steppedValue);
|
|
382
366
|
} else {
|
|
383
|
-
changeValue(
|
|
367
|
+
if ((numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber) > 0) changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.minNumber);else if ((numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber) <= 0) changeValue(numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.maxNumber);else changeValue(numberInputContext.stepNumber);
|
|
384
368
|
}
|
|
385
369
|
};
|
|
386
370
|
|
|
@@ -410,7 +394,7 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, re
|
|
|
410
394
|
changeVisualFocusIndex(-1);
|
|
411
395
|
}
|
|
412
396
|
|
|
413
|
-
|
|
397
|
+
numberInputContext != null && setNumberProps(numberInputContext.typeNumber, numberInputContext.minNumber, numberInputContext.maxNumber, numberInputContext.stepNumber);
|
|
414
398
|
}, [value, innerValue, suggestions, numberInputContext]);
|
|
415
399
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
416
400
|
theme: colorsTheme.textInput
|
|
@@ -502,51 +486,51 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, re
|
|
|
502
486
|
backgroundType: backgroundType,
|
|
503
487
|
"aria-label": "Error"
|
|
504
488
|
}, _Icons["default"].error), !disabled && clearable && (value !== null && value !== void 0 ? value : innerValue).length > 0 && /*#__PURE__*/_react["default"].createElement(Action, {
|
|
489
|
+
"aria-label": translatedLabels.textInput.clearFieldActionTitle,
|
|
505
490
|
onClick: handleClearActionOnClick,
|
|
506
491
|
onMouseDown: function onMouseDown(event) {
|
|
507
492
|
event.stopPropagation();
|
|
508
493
|
},
|
|
509
|
-
backgroundType: backgroundType,
|
|
510
494
|
tabIndex: tabIndex,
|
|
511
495
|
title: translatedLabels.textInput.clearFieldActionTitle,
|
|
512
|
-
"
|
|
513
|
-
|
|
496
|
+
type: "button",
|
|
497
|
+
backgroundType: backgroundType
|
|
514
498
|
}, _Icons["default"].clear), (numberInputContext === null || numberInputContext === void 0 ? void 0 : numberInputContext.typeNumber) === "number" && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(Action, {
|
|
515
|
-
|
|
499
|
+
"aria-label": translatedLabels.numberInput.decrementValueTitle,
|
|
516
500
|
disabled: disabled,
|
|
517
501
|
onClick: handleDecrementActionOnClick,
|
|
518
502
|
onMouseDown: function onMouseDown(event) {
|
|
519
503
|
event.stopPropagation();
|
|
520
504
|
},
|
|
521
|
-
|
|
505
|
+
ref: actionRef,
|
|
522
506
|
tabIndex: tabIndex,
|
|
523
507
|
title: translatedLabels.numberInput.decrementValueTitle,
|
|
524
|
-
"
|
|
525
|
-
|
|
508
|
+
type: "button",
|
|
509
|
+
backgroundType: backgroundType
|
|
526
510
|
}, _Icons["default"].decrement), /*#__PURE__*/_react["default"].createElement(Action, {
|
|
527
|
-
|
|
511
|
+
"aria-label": translatedLabels.numberInput.incrementValueTitle,
|
|
528
512
|
disabled: disabled,
|
|
529
513
|
onClick: handleIncrementActionOnClick,
|
|
530
514
|
onMouseDown: function onMouseDown(event) {
|
|
531
515
|
event.stopPropagation();
|
|
532
516
|
},
|
|
533
|
-
|
|
517
|
+
ref: actionRef,
|
|
534
518
|
tabIndex: tabIndex,
|
|
535
519
|
title: translatedLabels.numberInput.incrementValueTitle,
|
|
536
|
-
"
|
|
537
|
-
|
|
520
|
+
type: "button",
|
|
521
|
+
backgroundType: backgroundType
|
|
538
522
|
}, _Icons["default"].increment)), action && /*#__PURE__*/_react["default"].createElement(Action, {
|
|
539
|
-
|
|
523
|
+
"aria-label": action.title,
|
|
540
524
|
disabled: disabled,
|
|
541
525
|
onClick: action.onClick,
|
|
542
526
|
onMouseDown: function onMouseDown(event) {
|
|
543
527
|
event.stopPropagation();
|
|
544
528
|
},
|
|
545
|
-
|
|
546
|
-
"aria-label": action.title,
|
|
547
|
-
backgroundType: backgroundType,
|
|
529
|
+
ref: actionRef,
|
|
548
530
|
tabIndex: tabIndex,
|
|
549
|
-
|
|
531
|
+
title: action.title,
|
|
532
|
+
type: "button",
|
|
533
|
+
backgroundType: backgroundType
|
|
550
534
|
}, typeof action.icon === "string" ? /*#__PURE__*/_react["default"].createElement("img", {
|
|
551
535
|
src: action.icon
|
|
552
536
|
}) : action.icon), suffix && /*#__PURE__*/_react["default"].createElement(Suffix, {
|
|
@@ -559,7 +543,7 @@ var DxcTextInput = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, re
|
|
|
559
543
|
}, error)));
|
|
560
544
|
});
|
|
561
545
|
|
|
562
|
-
var TextInputContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: column;\n
|
|
546
|
+
var TextInputContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n width: ", ";\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n"])), function (props) {
|
|
563
547
|
return calculateWidth(props.margin, props.size);
|
|
564
548
|
}, function (props) {
|
|
565
549
|
return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
|
|
@@ -607,7 +591,7 @@ var HelperText = _styledComponents["default"].span(_templateObject4 || (_templat
|
|
|
607
591
|
return props.theme.helperTextLineHeight;
|
|
608
592
|
});
|
|
609
593
|
|
|
610
|
-
var InputContainer = _styledComponents["default"].div(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n
|
|
594
|
+
var InputContainer = _styledComponents["default"].div(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n position: relative;\n display: flex;\n align-items: center;\n height: calc(2.5rem - 2px);\n padding: 0 0.5rem;\n\n ", "\n box-shadow: 0 0 0 2px transparent;\n border-radius: 4px;\n border: 1px solid\n ", ";\n ", "\n ", ";\n\n ", ";\n"])), function (props) {
|
|
611
595
|
if (props.disabled) return props.backgroundType === "dark" ? "background-color: ".concat(props.theme.disabledContainerFillColorOnDark, ";") : "background-color: ".concat(props.theme.disabledContainerFillColor, ";");
|
|
612
596
|
}, function (props) {
|
|
613
597
|
if (props.disabled) return props.backgroundType === "dark" ? props.theme.disabledBorderColorOnDark : props.theme.disabledBorderColor;else return props.backgroundType === "dark" ? props.theme.enabledBorderColorOnDark : props.theme.enabledBorderColor;
|
|
@@ -27,7 +27,9 @@ var _useTheme = _interopRequireDefault(require("../useTheme"));
|
|
|
27
27
|
|
|
28
28
|
var _BackgroundColorContext = _interopRequireDefault(require("../BackgroundColorContext"));
|
|
29
29
|
|
|
30
|
-
var
|
|
30
|
+
var _Flex = _interopRequireDefault(require("../flex/Flex"));
|
|
31
|
+
|
|
32
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
|
|
31
33
|
|
|
32
34
|
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); }
|
|
33
35
|
|
|
@@ -47,17 +49,17 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
|
|
|
47
49
|
multiple = _ref$multiple === void 0 ? false : _ref$multiple,
|
|
48
50
|
_ref$tabIndex = _ref.tabIndex,
|
|
49
51
|
tabIndex = _ref$tabIndex === void 0 ? 0 : _ref$tabIndex;
|
|
50
|
-
var colorsTheme = (0, _useTheme["default"])();
|
|
51
52
|
|
|
52
|
-
var _useState = (0, _react.useState)(
|
|
53
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState,
|
|
54
|
-
|
|
55
|
-
setSelectedValue = _useState2[1];
|
|
53
|
+
var _useState = (0, _react.useState)("label-toggle-group-".concat((0, _uuid.v4)())),
|
|
54
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 1),
|
|
55
|
+
toggleGroupLabelId = _useState2[0];
|
|
56
56
|
|
|
57
|
-
var _useState3 = (0, _react.useState)(
|
|
58
|
-
_useState4 = (0, _slicedToArray2["default"])(_useState3,
|
|
59
|
-
|
|
57
|
+
var _useState3 = (0, _react.useState)(defaultValue !== null && defaultValue !== void 0 ? defaultValue : multiple ? [] : -1),
|
|
58
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
59
|
+
selectedValue = _useState4[0],
|
|
60
|
+
setSelectedValue = _useState4[1];
|
|
60
61
|
|
|
62
|
+
var colorsTheme = (0, _useTheme["default"])();
|
|
61
63
|
var backgroundType = (0, _react.useContext)(_BackgroundColorContext["default"]);
|
|
62
64
|
|
|
63
65
|
var handleToggleChange = function handleToggleChange(selectedOption) {
|
|
@@ -93,9 +95,13 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
|
|
|
93
95
|
onChange === null || onChange === void 0 ? void 0 : onChange(multiple ? newSelectedOptions : selectedOption);
|
|
94
96
|
};
|
|
95
97
|
|
|
96
|
-
var
|
|
97
|
-
event.
|
|
98
|
-
|
|
98
|
+
var handleOnKeyDown = function handleOnKeyDown(event, optionValue) {
|
|
99
|
+
switch (event.key) {
|
|
100
|
+
case "Enter":
|
|
101
|
+
case " ":
|
|
102
|
+
event.preventDefault();
|
|
103
|
+
handleToggleChange(optionValue);
|
|
104
|
+
}
|
|
99
105
|
};
|
|
100
106
|
|
|
101
107
|
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
@@ -103,40 +109,53 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
|
|
|
103
109
|
}, /*#__PURE__*/_react["default"].createElement(ToggleGroup, {
|
|
104
110
|
margin: margin
|
|
105
111
|
}, /*#__PURE__*/_react["default"].createElement(Label, {
|
|
106
|
-
|
|
112
|
+
id: toggleGroupLabelId,
|
|
107
113
|
disabled: disabled
|
|
108
114
|
}, label), /*#__PURE__*/_react["default"].createElement(HelperText, {
|
|
109
115
|
disabled: disabled
|
|
110
116
|
}, helperText), /*#__PURE__*/_react["default"].createElement(OptionsContainer, {
|
|
111
|
-
|
|
112
|
-
role: multiple ? "group" : "radiogroup"
|
|
117
|
+
"aria-labelledby": toggleGroupLabelId
|
|
113
118
|
}, options.map(function (option, i) {
|
|
114
|
-
return /*#__PURE__*/_react["default"].createElement(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
tabIndex: !disabled ? tabIndex : -1,
|
|
119
|
+
return /*#__PURE__*/_react["default"].createElement(ToggleButton, {
|
|
120
|
+
key: "toggle-".concat(i, "-").concat(option.label),
|
|
121
|
+
"aria-label": option.title,
|
|
122
|
+
"aria-pressed": multiple ? value ? Array.isArray(value) && value.includes(option.value) : Array.isArray(selectedValue) && selectedValue.includes(option.value) : value ? option.value === value : option.value === selectedValue,
|
|
123
|
+
disabled: disabled,
|
|
120
124
|
onClick: function onClick() {
|
|
121
|
-
|
|
125
|
+
handleToggleChange(option.value);
|
|
122
126
|
},
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
optionLabel: option.label,
|
|
126
|
-
disabled: disabled,
|
|
127
|
-
onKeyPress: function onKeyPress(event) {
|
|
128
|
-
handleKeyPress(event, option.value);
|
|
127
|
+
onKeyDown: function onKeyDown(event) {
|
|
128
|
+
handleOnKeyDown(event, option.value);
|
|
129
129
|
},
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
tabIndex: !disabled ? tabIndex : -1,
|
|
131
|
+
title: option.title,
|
|
132
|
+
backgroundType: backgroundType,
|
|
133
|
+
hasIcon: option.icon,
|
|
134
|
+
optionLabel: option.label,
|
|
135
|
+
selected: multiple ? value ? Array.isArray(value) && value.includes(option.value) : Array.isArray(selectedValue) && selectedValue.includes(option.value) : value ? option.value === value : option.value === selectedValue
|
|
136
|
+
}, /*#__PURE__*/_react["default"].createElement(_Flex["default"], {
|
|
137
|
+
alignItems: "center"
|
|
138
|
+
}, option.icon && /*#__PURE__*/_react["default"].createElement(IconContainer, {
|
|
132
139
|
optionLabel: option.label
|
|
133
|
-
}, typeof option.icon === "string" ? /*#__PURE__*/_react["default"].createElement(
|
|
140
|
+
}, typeof option.icon === "string" ? /*#__PURE__*/_react["default"].createElement("img", {
|
|
134
141
|
src: option.icon
|
|
135
142
|
}) : option.icon), option.label && /*#__PURE__*/_react["default"].createElement(LabelContainer, null, option.label)));
|
|
136
143
|
}))));
|
|
137
144
|
};
|
|
138
145
|
|
|
139
|
-
var
|
|
146
|
+
var ToggleGroup = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n flex-direction: column;\n margin: ", ";\n margin-top: ", ";\n margin-right: ", ";\n margin-bottom: ", ";\n margin-left: ", ";\n"])), function (props) {
|
|
147
|
+
return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
|
|
148
|
+
}, function (props) {
|
|
149
|
+
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.top ? _variables.spaces[props.margin.top] : "";
|
|
150
|
+
}, function (props) {
|
|
151
|
+
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.right ? _variables.spaces[props.margin.right] : "";
|
|
152
|
+
}, function (props) {
|
|
153
|
+
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
|
|
154
|
+
}, function (props) {
|
|
155
|
+
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
var Label = _styledComponents["default"].label(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n"])), function (props) {
|
|
140
159
|
return props.disabled ? props.theme.disabledLabelFontColor : props.theme.labelFontColor;
|
|
141
160
|
}, function (props) {
|
|
142
161
|
return props.theme.labelFontFamily;
|
|
@@ -150,7 +169,7 @@ var Label = _styledComponents["default"].label(_templateObject || (_templateObje
|
|
|
150
169
|
return props.theme.labelLineHeight;
|
|
151
170
|
});
|
|
152
171
|
|
|
153
|
-
var HelperText = _styledComponents["default"].span(
|
|
172
|
+
var HelperText = _styledComponents["default"].span(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n"])), function (props) {
|
|
154
173
|
return props.disabled ? props.theme.disabledHelperTextFontcolor : props.theme.helperTextFontColor;
|
|
155
174
|
}, function (props) {
|
|
156
175
|
return props.theme.helperTextFontFamily;
|
|
@@ -164,19 +183,7 @@ var HelperText = _styledComponents["default"].span(_templateObject2 || (_templat
|
|
|
164
183
|
return props.theme.helperTextLineHeight;
|
|
165
184
|
});
|
|
166
185
|
|
|
167
|
-
var
|
|
168
|
-
return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
|
|
169
|
-
}, function (props) {
|
|
170
|
-
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.top ? _variables.spaces[props.margin.top] : "";
|
|
171
|
-
}, function (props) {
|
|
172
|
-
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.right ? _variables.spaces[props.margin.right] : "";
|
|
173
|
-
}, function (props) {
|
|
174
|
-
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.bottom ? _variables.spaces[props.margin.bottom] : "";
|
|
175
|
-
}, function (props) {
|
|
176
|
-
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
var OptionsContainer = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: row;\n width: max-content;\n opacity: 1;\n height: calc(48px - 4px - 4px);\n border-width: ", ";\n border-style: ", ";\n border-radius: ", ";\n border-color: ", ";\n background-color: ", ";\n padding: 4px;\n margin-top: ", ";\n"])), function (props) {
|
|
186
|
+
var OptionsContainer = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n gap: 0.25rem;\n width: max-content;\n height: calc(48px - 4px - 4px);\n padding: 0.25rem;\n border-width: ", ";\n border-style: ", ";\n border-radius: ", ";\n border-color: ", ";\n margin-top: ", ";\n background-color: ", ";\n"])), function (props) {
|
|
180
187
|
return props.theme.containerBorderThickness;
|
|
181
188
|
}, function (props) {
|
|
182
189
|
return props.theme.containerBorderStyle;
|
|
@@ -184,16 +191,36 @@ var OptionsContainer = _styledComponents["default"].div(_templateObject4 || (_te
|
|
|
184
191
|
return props.theme.containerBorderRadius;
|
|
185
192
|
}, function (props) {
|
|
186
193
|
return props.theme.containerBorderColor;
|
|
187
|
-
}, function (props) {
|
|
188
|
-
return props.theme.containerBackgroundColor;
|
|
189
194
|
}, function (props) {
|
|
190
195
|
return props.theme.containerMarginTop;
|
|
196
|
+
}, function (props) {
|
|
197
|
+
return props.theme.containerBackgroundColor;
|
|
191
198
|
});
|
|
192
199
|
|
|
193
|
-
var
|
|
194
|
-
return
|
|
200
|
+
var ToggleButton = _styledComponents["default"].button(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: column;\n justify-content: center;\n padding-left: ", ";\n padding-right: ", ";\n border-width: ", ";\n border-style: ", ";\n border-radius: ", ";\n background-color: ", ";\n color: ", ";\n cursor: pointer;\n\n &:hover {\n background-color: ", ";\n }\n &:active {\n background-color: ", ";\n color: #ffffff;\n }\n &:focus {\n outline: none;\n box-shadow: ", ";\n }\n &:disabled {\n background-color: ", ";\n color: ", ";\n cursor: not-allowed;\n }\n"])), function (props) {
|
|
201
|
+
return props.optionLabel && props.hasIcon || props.optionLabel && !props.hasIcon ? props.theme.labelPaddingLeft : props.theme.iconPaddingLeft;
|
|
195
202
|
}, function (props) {
|
|
196
|
-
return
|
|
203
|
+
return props.optionLabel && props.hasIcon || props.optionLabel && !props.hasIcon ? props.theme.labelPaddingRight : props.theme.iconPaddingRight;
|
|
204
|
+
}, function (props) {
|
|
205
|
+
return props.theme.optionBorderThickness;
|
|
206
|
+
}, function (props) {
|
|
207
|
+
return props.theme.optionBorderStyle;
|
|
208
|
+
}, function (props) {
|
|
209
|
+
return props.theme.optionBorderRadius;
|
|
210
|
+
}, function (props) {
|
|
211
|
+
return props.selected ? props.theme.selectedBackgroundColor : props.theme.unselectedBackgroundColor;
|
|
212
|
+
}, function (props) {
|
|
213
|
+
return props.selected ? props.theme.selectedFontColor : props.theme.unselectedFontColor;
|
|
214
|
+
}, function (props) {
|
|
215
|
+
return props.selected ? props.theme.selectedHoverBackgroundColor : props.theme.unselectedHoverBackgroundColor;
|
|
216
|
+
}, function (props) {
|
|
217
|
+
return props.selected ? props.theme.selectedActiveBackgroundColor : props.theme.unselectedActiveBackgroundColor;
|
|
218
|
+
}, function (props) {
|
|
219
|
+
return "0 0 0 ".concat(props.theme.optionFocusBorderThickness, " ").concat(props.backgroundType === "dark" ? props.theme.focusColorOnDark : props.theme.focusColor);
|
|
220
|
+
}, function (props) {
|
|
221
|
+
return props.selected ? props.theme.selectedDisabledBackgroundColor : props.theme.unselectedDisabledBackgroundColor;
|
|
222
|
+
}, function (props) {
|
|
223
|
+
return props.selected ? props.theme.selectedDisabledFontColor : props.theme.unselectedDisabledFontColor;
|
|
197
224
|
});
|
|
198
225
|
|
|
199
226
|
var LabelContainer = _styledComponents["default"].span(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2["default"])(["\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n"])), function (props) {
|
|
@@ -206,11 +233,7 @@ var LabelContainer = _styledComponents["default"].span(_templateObject6 || (_tem
|
|
|
206
233
|
return props.theme.optionLabelFontWeight;
|
|
207
234
|
});
|
|
208
235
|
|
|
209
|
-
var
|
|
210
|
-
|
|
211
|
-
var Icon = _styledComponents["default"].img(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2["default"])([""])));
|
|
212
|
-
|
|
213
|
-
var IconContainer = _styledComponents["default"].div(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteral2["default"])(["\n margin-right: ", ";\n height: 24px;\n width: 24px;\n overflow: hidden;\n display: flex;\n img,\n svg {\n height: 100%;\n width: 100%;\n }\n"])), function (props) {
|
|
236
|
+
var IconContainer = _styledComponents["default"].div(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n height: 24px;\n width: 24px;\n margin-right: ", ";\n overflow: hidden;\n\n img,\n svg {\n height: 100%;\n width: 100%;\n }\n"])), function (props) {
|
|
214
237
|
return props.optionLabel && props.theme.iconMarginRight;
|
|
215
238
|
});
|
|
216
239
|
|
|
@@ -42,7 +42,7 @@ const options = [
|
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
value: 2,
|
|
45
|
-
label: "
|
|
45
|
+
label: "X",
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
value: 3,
|
|
@@ -53,14 +53,17 @@ const optionsWithIcon = [
|
|
|
53
53
|
{
|
|
54
54
|
value: 1,
|
|
55
55
|
icon: wifiSVG,
|
|
56
|
+
title: "WiFi connection",
|
|
56
57
|
},
|
|
57
58
|
{
|
|
58
59
|
value: 2,
|
|
59
60
|
icon: ethernetSVG,
|
|
61
|
+
title: "Ethernet connection",
|
|
60
62
|
},
|
|
61
63
|
{
|
|
62
64
|
value: 3,
|
|
63
65
|
icon: gMobileSVG,
|
|
66
|
+
title: "3G Mobile data connection",
|
|
64
67
|
},
|
|
65
68
|
];
|
|
66
69
|
const optionsWithIconAndLabel = [
|
|
@@ -87,7 +90,7 @@ const twoOptions = [
|
|
|
87
90
|
},
|
|
88
91
|
{
|
|
89
92
|
value: 2,
|
|
90
|
-
label: "
|
|
93
|
+
label: "X",
|
|
91
94
|
},
|
|
92
95
|
];
|
|
93
96
|
|
|
@@ -209,7 +212,7 @@ ToggleGroupSelectedActived.play = async ({ canvasElement }) => {
|
|
|
209
212
|
export const ToggleGroupUnselectedActived = OptionSelected.bind({});
|
|
210
213
|
ToggleGroupUnselectedActived.play = async ({ canvasElement }) => {
|
|
211
214
|
const canvas = within(canvasElement);
|
|
212
|
-
const option = canvas.getByText("
|
|
215
|
+
const option = canvas.getByText("X");
|
|
213
216
|
await userEvent.click(option);
|
|
214
217
|
userEvent.tab();
|
|
215
218
|
};
|