@dxc-technology/halstack-react 0.0.0-38849bf → 0.0.0-38c90fa
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/BackgroundColorContext.d.ts +10 -0
- package/BackgroundColorContext.js +1 -4
- package/ThemeContext.d.ts +15 -0
- package/ThemeContext.js +5 -8
- package/V3Select/V3Select.js +2 -2
- package/V3Textarea/V3Textarea.js +2 -2
- package/accordion/Accordion.js +2 -2
- package/accordion/Accordion.stories.tsx +307 -0
- package/accordion/types.d.ts +1 -1
- package/accordion-group/AccordionGroup.js +2 -2
- package/accordion-group/AccordionGroup.stories.tsx +225 -0
- package/accordion-group/types.d.ts +1 -1
- package/alert/Alert.js +2 -2
- package/alert/types.d.ts +1 -1
- package/badge/Badge.js +1 -1
- package/bleed/Bleed.d.ts +3 -0
- package/bleed/Bleed.js +84 -0
- package/bleed/Bleed.stories.tsx +342 -0
- package/bleed/types.d.ts +13 -0
- package/bleed/types.js +5 -0
- package/box/Box.d.ts +1 -1
- package/box/Box.js +4 -7
- package/box/types.d.ts +0 -4
- package/button/Button.d.ts +1 -1
- package/button/Button.js +13 -19
- package/button/Button.stories.tsx +6 -8
- package/button/types.d.ts +5 -9
- package/card/Card.js +5 -6
- package/card/Card.stories.tsx +201 -0
- package/card/ice-cream.jpg +0 -0
- package/card/types.d.ts +4 -6
- package/checkbox/Checkbox.js +2 -2
- package/checkbox/types.d.ts +2 -2
- package/chip/Chip.d.ts +4 -0
- package/chip/Chip.js +5 -27
- package/chip/Chip.stories.tsx +121 -0
- package/chip/types.d.ts +53 -0
- package/chip/types.js +5 -0
- package/common/variables.js +57 -22
- package/date/Date.js +1 -1
- package/date-input/DateInput.js +10 -13
- package/dialog/Dialog.js +4 -3
- package/dialog/Dialog.stories.tsx +212 -0
- package/dropdown/Dropdown.js +1 -1
- package/dropdown/Dropdown.stories.tsx +247 -0
- package/dropdown/types.d.ts +1 -1
- package/file-input/FileInput.d.ts +4 -0
- package/file-input/FileInput.js +167 -109
- package/file-input/FileInput.stories.tsx +507 -0
- package/file-input/FileItem.d.ts +14 -0
- package/file-input/FileItem.js +12 -21
- package/file-input/types.d.ts +112 -0
- package/file-input/types.js +5 -0
- package/footer/Footer.d.ts +1 -1
- package/footer/Footer.js +28 -36
- package/footer/{Footer.stories.jsx → Footer.stories.tsx} +1 -22
- package/footer/Icons.d.ts +2 -0
- package/footer/Icons.js +3 -3
- package/footer/types.d.ts +22 -18
- package/header/Header.js +2 -2
- package/header/Header.stories.tsx +162 -0
- package/header/Icons.d.ts +2 -0
- package/header/types.d.ts +4 -2
- package/heading/Heading.d.ts +4 -0
- package/heading/Heading.js +7 -24
- package/heading/Heading.stories.tsx +54 -0
- package/heading/types.d.ts +33 -0
- package/heading/types.js +5 -0
- package/input-text/InputText.js +2 -2
- package/inset/Inset.d.ts +3 -0
- package/inset/Inset.js +84 -0
- package/inset/Inset.stories.tsx +229 -0
- package/inset/types.d.ts +13 -0
- package/inset/types.js +5 -0
- package/layout/ApplicationLayout.d.ts +10 -0
- package/layout/ApplicationLayout.js +9 -19
- package/layout/ApplicationLayout.stories.tsx +171 -0
- package/layout/types.d.ts +57 -0
- package/layout/types.js +5 -0
- package/link/Link.js +3 -3
- package/link/Link.stories.tsx +76 -0
- package/list/List.d.ts +4 -0
- package/list/List.js +47 -0
- package/list/List.stories.tsx +95 -0
- package/list/types.d.ts +7 -0
- package/list/types.js +5 -0
- package/main.d.ts +7 -3
- package/main.js +34 -2
- package/number-input/NumberInput.js +3 -6
- package/number-input/NumberInputContext.d.ts +4 -0
- package/number-input/NumberInputContext.js +5 -2
- package/number-input/numberInputContextTypes.d.ts +19 -0
- package/number-input/numberInputContextTypes.js +5 -0
- package/package.json +4 -2
- package/paginator/Paginator.js +2 -8
- package/password-input/PasswordInput.js +19 -18
- package/password-input/PasswordInput.stories.tsx +3 -3
- package/password-input/types.d.ts +17 -10
- package/progress-bar/ProgressBar.js +4 -4
- package/radio/Radio.js +2 -2
- package/radio/types.d.ts +2 -2
- package/radio-group/Radio.d.ts +4 -0
- package/radio-group/Radio.js +140 -0
- package/radio-group/RadioGroup.d.ts +4 -0
- package/radio-group/RadioGroup.js +273 -0
- package/radio-group/RadioGroup.stories.tsx +79 -0
- package/radio-group/RadioGroup.test.js +248 -0
- package/radio-group/types.d.ts +36 -0
- package/radio-group/types.js +5 -0
- package/resultsetTable/ResultsetTable.d.ts +4 -0
- package/resultsetTable/ResultsetTable.js +5 -28
- package/resultsetTable/ResultsetTable.stories.tsx +275 -0
- package/resultsetTable/types.d.ts +67 -0
- package/resultsetTable/types.js +5 -0
- package/row/Row.d.ts +3 -0
- package/row/Row.js +127 -0
- package/row/Row.stories.tsx +237 -0
- package/row/types.d.ts +10 -0
- package/row/types.js +5 -0
- package/select/Select.d.ts +4 -0
- package/select/Select.js +20 -22
- package/select/Select.stories.tsx +572 -0
- package/select/types.d.ts +170 -0
- package/select/types.js +5 -0
- package/sidenav/Sidenav.js +2 -2
- package/sidenav/Sidenav.stories.tsx +182 -0
- package/slider/Slider.js +8 -8
- package/slider/Slider.stories.tsx +6 -1
- package/spinner/Spinner.js +2 -2
- package/spinner/Spinner.stories.jsx +1 -0
- package/stack/Stack.d.ts +3 -0
- package/stack/Stack.js +97 -0
- package/stack/Stack.stories.tsx +164 -0
- package/stack/types.d.ts +9 -0
- package/stack/types.js +5 -0
- package/switch/Switch.js +2 -2
- package/switch/Switch.stories.tsx +1 -1
- package/table/Table.js +3 -3
- package/table/Table.stories.jsx +2 -1
- package/tabs/Tabs.js +11 -9
- package/tabs/Tabs.stories.tsx +120 -0
- package/tabs/types.d.ts +25 -18
- package/tag/Tag.js +1 -1
- package/tag/Tag.stories.tsx +1 -1
- package/text/Text.d.ts +7 -0
- package/text/Text.js +30 -0
- package/text/Text.stories.tsx +19 -0
- package/text-input/TextInput.d.ts +4 -0
- package/text-input/TextInput.js +54 -85
- package/text-input/TextInput.stories.tsx +456 -0
- package/text-input/types.d.ts +159 -0
- package/text-input/types.js +5 -0
- package/textarea/Textarea.d.ts +4 -0
- package/textarea/Textarea.js +27 -60
- package/textarea/Textarea.stories.jsx +4 -3
- package/textarea/types.d.ts +130 -0
- package/textarea/types.js +5 -0
- package/toggle/Toggle.js +1 -1
- package/toggle-group/ToggleGroup.d.ts +4 -0
- package/toggle-group/ToggleGroup.js +16 -45
- package/toggle-group/ToggleGroup.stories.tsx +173 -0
- package/toggle-group/types.d.ts +97 -0
- package/toggle-group/types.js +5 -0
- package/upload/buttons-upload/ButtonsUpload.js +2 -2
- package/upload/dragAndDropArea/DragAndDropArea.js +2 -2
- package/upload/file-upload/FileToUpload.js +1 -1
- package/upload/files-upload/FilesToUpload.js +1 -1
- package/upload/transaction/Transaction.js +2 -2
- package/upload/transactions/Transactions.js +1 -1
- package/useTheme.d.ts +2 -0
- package/useTheme.js +1 -1
- package/wizard/Wizard.d.ts +4 -0
- package/wizard/Wizard.js +69 -59
- package/wizard/Wizard.stories.tsx +224 -0
- package/wizard/types.d.ts +60 -0
- package/wizard/types.js +5 -0
- package/chip/index.d.ts +0 -22
- package/file-input/index.d.ts +0 -81
- package/heading/index.d.ts +0 -17
- package/resultsetTable/index.d.ts +0 -19
- package/select/index.d.ts +0 -131
- package/text-input/index.d.ts +0 -135
- package/textarea/index.d.ts +0 -117
- package/toggle-group/index.d.ts +0 -21
- package/wizard/Icons.js +0 -65
- package/wizard/index.d.ts +0 -18
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports["default"] = void 0;
|
|
11
|
+
|
|
12
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
13
|
+
|
|
14
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
15
|
+
|
|
16
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
|
+
|
|
18
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
19
|
+
|
|
20
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
21
|
+
|
|
22
|
+
var _uuid = require("uuid");
|
|
23
|
+
|
|
24
|
+
var _useTheme = _interopRequireDefault(require("../useTheme"));
|
|
25
|
+
|
|
26
|
+
var _Radio = _interopRequireDefault(require("./Radio"));
|
|
27
|
+
|
|
28
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
|
|
29
|
+
|
|
30
|
+
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); }
|
|
31
|
+
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(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; }
|
|
33
|
+
|
|
34
|
+
var getInitialFocusIndex = function getInitialFocusIndex(innerOptions, value) {
|
|
35
|
+
var initialSelectedOptionIndex = innerOptions.findIndex(function (option) {
|
|
36
|
+
return option.value === value;
|
|
37
|
+
});
|
|
38
|
+
return initialSelectedOptionIndex !== -1 ? initialSelectedOptionIndex : 0;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var DxcRadioGroup = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
42
|
+
var label = _ref.label,
|
|
43
|
+
name = _ref.name,
|
|
44
|
+
helperText = _ref.helperText,
|
|
45
|
+
options = _ref.options,
|
|
46
|
+
_ref$disabled = _ref.disabled,
|
|
47
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
48
|
+
_ref$optional = _ref.optional,
|
|
49
|
+
optional = _ref$optional === void 0 ? false : _ref$optional,
|
|
50
|
+
_ref$optionalItemLabe = _ref.optionalItemLabel,
|
|
51
|
+
optionalItemLabel = _ref$optionalItemLabe === void 0 ? "N/A" : _ref$optionalItemLabe,
|
|
52
|
+
_ref$readonly = _ref.readonly,
|
|
53
|
+
readonly = _ref$readonly === void 0 ? false : _ref$readonly,
|
|
54
|
+
_ref$stacking = _ref.stacking,
|
|
55
|
+
stacking = _ref$stacking === void 0 ? "column" : _ref$stacking,
|
|
56
|
+
defaultValue = _ref.defaultValue,
|
|
57
|
+
value = _ref.value,
|
|
58
|
+
onChange = _ref.onChange,
|
|
59
|
+
onBlur = _ref.onBlur,
|
|
60
|
+
error = _ref.error;
|
|
61
|
+
|
|
62
|
+
var _useState = (0, _react.useState)("radio-group-".concat((0, _uuid.v4)())),
|
|
63
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 1),
|
|
64
|
+
radioGroupId = _useState2[0];
|
|
65
|
+
|
|
66
|
+
var radioGroupLabelId = "label-".concat(radioGroupId);
|
|
67
|
+
var errorId = "error-".concat(radioGroupId);
|
|
68
|
+
|
|
69
|
+
var _useState3 = (0, _react.useState)(defaultValue),
|
|
70
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
71
|
+
innerValue = _useState4[0],
|
|
72
|
+
setInnerValue = _useState4[1];
|
|
73
|
+
|
|
74
|
+
var _useState5 = (0, _react.useState)(true),
|
|
75
|
+
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
76
|
+
firstTimeFocus = _useState6[0],
|
|
77
|
+
setFirstTimeFocus = _useState6[1];
|
|
78
|
+
|
|
79
|
+
var optionalItem = {
|
|
80
|
+
label: optionalItemLabel,
|
|
81
|
+
value: "",
|
|
82
|
+
disabled: disabled
|
|
83
|
+
};
|
|
84
|
+
var innerOptions = (0, _react.useMemo)(function () {
|
|
85
|
+
return optional ? [].concat((0, _toConsumableArray2["default"])(options), [optionalItem]) : options;
|
|
86
|
+
}, [optional, options]);
|
|
87
|
+
|
|
88
|
+
var _useState7 = (0, _react.useState)(getInitialFocusIndex(innerOptions, value !== null && value !== void 0 ? value : innerValue)),
|
|
89
|
+
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
|
90
|
+
currentFocusIndex = _useState8[0],
|
|
91
|
+
setCurrentFocusIndex = _useState8[1];
|
|
92
|
+
|
|
93
|
+
var colorsTheme = (0, _useTheme["default"])();
|
|
94
|
+
var handleOnChange = (0, _react.useCallback)(function (newValue) {
|
|
95
|
+
var currentValue = value !== null && value !== void 0 ? value : innerValue;
|
|
96
|
+
|
|
97
|
+
if (newValue !== currentValue && !readonly) {
|
|
98
|
+
value !== null && value !== void 0 ? value : setInnerValue(newValue);
|
|
99
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
100
|
+
}
|
|
101
|
+
}, [value, innerValue, setInnerValue, onChange]);
|
|
102
|
+
|
|
103
|
+
var handleOnBlur = function handleOnBlur(e) {
|
|
104
|
+
// If the radio group loses the focus to an element not contained inside it...
|
|
105
|
+
!e.currentTarget.contains(e.relatedTarget) && setFirstTimeFocus(true);
|
|
106
|
+
var currentValue = value !== null && value !== void 0 ? value : innerValue;
|
|
107
|
+
!optional && !Boolean(currentValue) ? onBlur === null || onBlur === void 0 ? void 0 : onBlur({
|
|
108
|
+
value: currentValue,
|
|
109
|
+
error: "This field is required. Please, choose an option."
|
|
110
|
+
}) : onBlur === null || onBlur === void 0 ? void 0 : onBlur({
|
|
111
|
+
value: currentValue
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
var setPreviousRadioChecked = function setPreviousRadioChecked() {
|
|
116
|
+
if (!disabled) {
|
|
117
|
+
setCurrentFocusIndex(function (currentFocusIndex) {
|
|
118
|
+
var index = currentFocusIndex === 0 ? innerOptions.length - 1 : currentFocusIndex - 1;
|
|
119
|
+
|
|
120
|
+
while (innerOptions[index].disabled) {
|
|
121
|
+
index = index === 0 ? innerOptions.length - 1 : index - 1;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return index;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
var setNextRadioChecked = function setNextRadioChecked() {
|
|
130
|
+
if (!disabled) {
|
|
131
|
+
setCurrentFocusIndex(function (currentFocusIndex) {
|
|
132
|
+
var index = currentFocusIndex === innerOptions.length - 1 ? 0 : currentFocusIndex + 1;
|
|
133
|
+
|
|
134
|
+
while (innerOptions[index].disabled) {
|
|
135
|
+
index = index === innerOptions.length - 1 ? 0 : index + 1;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return index;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
var handleOnKeyDown = function handleOnKeyDown(event) {
|
|
144
|
+
switch (event.keyCode) {
|
|
145
|
+
case 37: // arrow left
|
|
146
|
+
|
|
147
|
+
case 38:
|
|
148
|
+
// arrow up
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
setPreviousRadioChecked();
|
|
151
|
+
break;
|
|
152
|
+
|
|
153
|
+
case 39: // arrow right
|
|
154
|
+
|
|
155
|
+
case 40:
|
|
156
|
+
// arrow down
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
setNextRadioChecked();
|
|
159
|
+
break;
|
|
160
|
+
|
|
161
|
+
case 13: // enter
|
|
162
|
+
|
|
163
|
+
case 32:
|
|
164
|
+
// space
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
handleOnChange(innerOptions[currentFocusIndex].value);
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return /*#__PURE__*/_react["default"].createElement(_styledComponents.ThemeProvider, {
|
|
172
|
+
theme: colorsTheme.radioGroup
|
|
173
|
+
}, /*#__PURE__*/_react["default"].createElement(RadioGroupContainer, {
|
|
174
|
+
ref: ref
|
|
175
|
+
}, label && /*#__PURE__*/_react["default"].createElement(Label, {
|
|
176
|
+
id: radioGroupLabelId,
|
|
177
|
+
helperText: helperText,
|
|
178
|
+
disabled: disabled
|
|
179
|
+
}, label, " ", optional && /*#__PURE__*/_react["default"].createElement(OptionalLabel, null, "(Optional)")), helperText && /*#__PURE__*/_react["default"].createElement(HelperText, {
|
|
180
|
+
disabled: disabled
|
|
181
|
+
}, helperText), /*#__PURE__*/_react["default"].createElement(RadioGroup, {
|
|
182
|
+
onBlur: handleOnBlur,
|
|
183
|
+
onKeyDown: handleOnKeyDown,
|
|
184
|
+
stacking: stacking,
|
|
185
|
+
role: "radiogroup",
|
|
186
|
+
"aria-disabled": disabled,
|
|
187
|
+
"aria-labelledby": radioGroupLabelId,
|
|
188
|
+
"aria-invalid": error ? "true" : "false",
|
|
189
|
+
"aria-errormessage": error ? errorId : undefined,
|
|
190
|
+
"aria-required": !optional
|
|
191
|
+
}, /*#__PURE__*/_react["default"].createElement(ValueInput, {
|
|
192
|
+
name: name,
|
|
193
|
+
value: value !== null && value !== void 0 ? value : innerValue,
|
|
194
|
+
readOnly: true,
|
|
195
|
+
"aria-hidden": "true"
|
|
196
|
+
}), innerOptions.map(function (option, index) {
|
|
197
|
+
return /*#__PURE__*/_react["default"].createElement(_Radio["default"], {
|
|
198
|
+
option: option,
|
|
199
|
+
currentValue: value !== null && value !== void 0 ? value : innerValue,
|
|
200
|
+
onClick: function onClick() {
|
|
201
|
+
handleOnChange(option.value);
|
|
202
|
+
setCurrentFocusIndex(index);
|
|
203
|
+
},
|
|
204
|
+
onFocus: function onFocus() {
|
|
205
|
+
!firstTimeFocus ? handleOnChange(option.value) : setFirstTimeFocus(false);
|
|
206
|
+
},
|
|
207
|
+
error: error,
|
|
208
|
+
disabled: option.disabled || disabled,
|
|
209
|
+
focused: currentFocusIndex === index,
|
|
210
|
+
readonly: readonly
|
|
211
|
+
});
|
|
212
|
+
})), !disabled && typeof error === "string" && /*#__PURE__*/_react["default"].createElement(Error, {
|
|
213
|
+
id: errorId,
|
|
214
|
+
"aria-live": error ? "assertive" : "off"
|
|
215
|
+
}, error)));
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
var RadioGroupContainer = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n display: inline-flex;\n flex-direction: column;\n box-sizing: border-box;\n"])));
|
|
219
|
+
|
|
220
|
+
var Label = _styledComponents["default"].span(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n ", "\n"])), function (props) {
|
|
221
|
+
return props.disabled ? props.theme.disabledLabelFontColor : props.theme.labelFontColor;
|
|
222
|
+
}, function (props) {
|
|
223
|
+
return props.theme.fontFamily;
|
|
224
|
+
}, function (props) {
|
|
225
|
+
return props.theme.labelFontSize;
|
|
226
|
+
}, function (props) {
|
|
227
|
+
return props.theme.labelFontStyle;
|
|
228
|
+
}, function (props) {
|
|
229
|
+
return props.theme.labelFontWeight;
|
|
230
|
+
}, function (props) {
|
|
231
|
+
return props.theme.labelLineHeight;
|
|
232
|
+
}, function (props) {
|
|
233
|
+
return !props.helperText && "margin-bottom: ".concat(props.theme.groupLabelMargin);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
var OptionalLabel = _styledComponents["default"].span(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["\n font-weight: ", ";\n"])), function (props) {
|
|
237
|
+
return props.theme.optionalLabelFontWeight;
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
var HelperText = _styledComponents["default"].span(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n margin-bottom: ", ";\n"])), function (props) {
|
|
241
|
+
return props.disabled ? props.theme.disabledHelperTextFontColor : props.theme.helperTextFontColor;
|
|
242
|
+
}, function (props) {
|
|
243
|
+
return props.theme.fontFamily;
|
|
244
|
+
}, function (props) {
|
|
245
|
+
return props.theme.helperTextFontSize;
|
|
246
|
+
}, function (props) {
|
|
247
|
+
return props.theme.helperTextFontStyle;
|
|
248
|
+
}, function (props) {
|
|
249
|
+
return props.theme.helperTextFontWeight;
|
|
250
|
+
}, function (props) {
|
|
251
|
+
return props.theme.helperTextLineHeight;
|
|
252
|
+
}, function (props) {
|
|
253
|
+
return props.theme.groupLabelMargin;
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
var RadioGroup = _styledComponents["default"].div(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-wrap: wrap;\n flex-direction: ", ";\n\n row-gap: ", ";\n column-gap: ", ";\n"])), function (props) {
|
|
257
|
+
return props.stacking;
|
|
258
|
+
}, function (props) {
|
|
259
|
+
return props.theme.groupVerticalGutter;
|
|
260
|
+
}, function (props) {
|
|
261
|
+
return props.theme.groupHorizontalGutter;
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
var ValueInput = _styledComponents["default"].input(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2["default"])(["\n display: none;\n"])));
|
|
265
|
+
|
|
266
|
+
var Error = _styledComponents["default"].span(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2["default"])(["\n min-height: 1.5em;\n color: ", ";\n font-family: ", ";\n font-size: 0.75rem;\n font-weight: 400;\n line-height: 1.5em;\n margin-top: 0.5rem;\n"])), function (props) {
|
|
267
|
+
return props.theme.errorMessageColor;
|
|
268
|
+
}, function (props) {
|
|
269
|
+
return props.theme.fontFamily;
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
var _default = DxcRadioGroup;
|
|
273
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import ExampleContainer from "../../.storybook/components/ExampleContainer";
|
|
2
|
+
import Title from "../../.storybook/components/Title";
|
|
3
|
+
import DxcRadioGroup from "./RadioGroup";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: "Radio Group",
|
|
7
|
+
component: DxcRadioGroup,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const options = [
|
|
11
|
+
{ label: "Option 1", value: "1" },
|
|
12
|
+
{ label: "Option 2", value: "2" },
|
|
13
|
+
{ label: "Option 3", value: "3" },
|
|
14
|
+
{ label: "Option 4", value: "4" },
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const single_disabled_options = [
|
|
18
|
+
{ label: "Option 1", value: "1" },
|
|
19
|
+
{ label: "Option 2", value: "2", disabled: true },
|
|
20
|
+
{ label: "Option 3", value: "3" },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
export const Chromatic = () => (
|
|
24
|
+
<>
|
|
25
|
+
<ExampleContainer>
|
|
26
|
+
<Title title="Label only" theme="light" level={4} />
|
|
27
|
+
<DxcRadioGroup label="Example of a label only" options={options} />
|
|
28
|
+
</ExampleContainer>
|
|
29
|
+
<ExampleContainer>
|
|
30
|
+
<Title title="Column" theme="light" level={4} />
|
|
31
|
+
<DxcRadioGroup label="Example" helperText="Helper text" options={options} defaultValue="3" />
|
|
32
|
+
</ExampleContainer>
|
|
33
|
+
<ExampleContainer>
|
|
34
|
+
<Title title="Row" theme="light" level={4} />
|
|
35
|
+
<DxcRadioGroup label="Example" helperText="Helper text" options={options} stacking="row" />
|
|
36
|
+
</ExampleContainer>
|
|
37
|
+
<ExampleContainer>
|
|
38
|
+
<Title title="Disabled" theme="light" level={4} />
|
|
39
|
+
<DxcRadioGroup
|
|
40
|
+
label="Disabled"
|
|
41
|
+
error="Error message"
|
|
42
|
+
helperText="Helper text"
|
|
43
|
+
options={options}
|
|
44
|
+
disabled
|
|
45
|
+
optional
|
|
46
|
+
defaultValue="2"
|
|
47
|
+
/>
|
|
48
|
+
</ExampleContainer>
|
|
49
|
+
<ExampleContainer>
|
|
50
|
+
<Title title="Single disabled" theme="light" level={4} />
|
|
51
|
+
<DxcRadioGroup label="Disabled" helperText="Helper text" options={single_disabled_options} defaultValue="3" />
|
|
52
|
+
</ExampleContainer>
|
|
53
|
+
<ExampleContainer>
|
|
54
|
+
<Title title="Optional" theme="light" level={4} />
|
|
55
|
+
<DxcRadioGroup
|
|
56
|
+
label="Example"
|
|
57
|
+
optionalItemLabel="No selection"
|
|
58
|
+
optional
|
|
59
|
+
helperText="Helper text"
|
|
60
|
+
options={options}
|
|
61
|
+
stacking="row"
|
|
62
|
+
/>
|
|
63
|
+
</ExampleContainer>
|
|
64
|
+
<ExampleContainer>
|
|
65
|
+
<Title title="Error" theme="light" level={4} />
|
|
66
|
+
<DxcRadioGroup
|
|
67
|
+
label="Example"
|
|
68
|
+
error="Error message"
|
|
69
|
+
helperText="Helper text"
|
|
70
|
+
options={options}
|
|
71
|
+
defaultValue="2"
|
|
72
|
+
/>
|
|
73
|
+
</ExampleContainer>
|
|
74
|
+
<ExampleContainer>
|
|
75
|
+
<Title title="Readonly" theme="light" level={4} />
|
|
76
|
+
<DxcRadioGroup label="Example" readonly helperText="Helper text" options={options} defaultValue="2" />
|
|
77
|
+
</ExampleContainer>
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _react = _interopRequireDefault(require("react"));
|
|
6
|
+
|
|
7
|
+
var _RadioGroup = _interopRequireDefault(require("./RadioGroup"));
|
|
8
|
+
|
|
9
|
+
var _react2 = require("@testing-library/react");
|
|
10
|
+
|
|
11
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
12
|
+
|
|
13
|
+
var single_options = [{
|
|
14
|
+
label: "Option 01",
|
|
15
|
+
value: "1"
|
|
16
|
+
}, {
|
|
17
|
+
label: "Option 02",
|
|
18
|
+
value: "2"
|
|
19
|
+
}, {
|
|
20
|
+
label: "Option 03",
|
|
21
|
+
value: "3"
|
|
22
|
+
}, {
|
|
23
|
+
label: "Option 04",
|
|
24
|
+
value: "4"
|
|
25
|
+
}, {
|
|
26
|
+
label: "Option 05",
|
|
27
|
+
value: "5"
|
|
28
|
+
}, {
|
|
29
|
+
label: "Option 06",
|
|
30
|
+
value: "6"
|
|
31
|
+
}, {
|
|
32
|
+
label: "Option 07",
|
|
33
|
+
value: "7"
|
|
34
|
+
}, {
|
|
35
|
+
label: "Option 08",
|
|
36
|
+
value: "8"
|
|
37
|
+
}, {
|
|
38
|
+
label: "Option 09",
|
|
39
|
+
value: "9"
|
|
40
|
+
}, {
|
|
41
|
+
label: "Option 10",
|
|
42
|
+
value: "10"
|
|
43
|
+
}];
|
|
44
|
+
describe("Radio Group component tests", function () {
|
|
45
|
+
test("Controlled - Not optional constraint - undefined", function () {
|
|
46
|
+
var onChange = jest.fn();
|
|
47
|
+
var onBlur = jest.fn();
|
|
48
|
+
|
|
49
|
+
var _render = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_RadioGroup["default"], {
|
|
50
|
+
label: "test-select-label",
|
|
51
|
+
options: single_options,
|
|
52
|
+
onChange: onChange,
|
|
53
|
+
onBlur: onBlur
|
|
54
|
+
})),
|
|
55
|
+
getByRole = _render.getByRole,
|
|
56
|
+
getAllByRole = _render.getAllByRole;
|
|
57
|
+
|
|
58
|
+
var radioGroup = getByRole("radiogroup");
|
|
59
|
+
expect(radioGroup.getAttribute("aria-required")).toBe("true");
|
|
60
|
+
|
|
61
|
+
_react2.fireEvent.focus(radioGroup);
|
|
62
|
+
|
|
63
|
+
_react2.fireEvent.blur(radioGroup);
|
|
64
|
+
|
|
65
|
+
expect(onBlur).toHaveBeenCalled();
|
|
66
|
+
expect(onBlur).toHaveBeenCalledWith({
|
|
67
|
+
error: "This field is required. Please, choose an option."
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
_userEvent["default"].click(radioGroup);
|
|
71
|
+
|
|
72
|
+
_userEvent["default"].click(getAllByRole("radio")[0]);
|
|
73
|
+
|
|
74
|
+
expect(onChange).toHaveBeenCalled();
|
|
75
|
+
expect(onChange).toHaveBeenCalledWith("1");
|
|
76
|
+
|
|
77
|
+
_react2.fireEvent.focus(radioGroup);
|
|
78
|
+
|
|
79
|
+
_react2.fireEvent.blur(radioGroup);
|
|
80
|
+
|
|
81
|
+
expect(onBlur).toHaveBeenCalled();
|
|
82
|
+
expect(onBlur).toHaveBeenCalledWith({
|
|
83
|
+
value: "1"
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
test("Controlled - Not optional constraint - empty string", function () {
|
|
87
|
+
var onChange = jest.fn();
|
|
88
|
+
var onBlur = jest.fn();
|
|
89
|
+
|
|
90
|
+
var _render2 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_RadioGroup["default"], {
|
|
91
|
+
label: "test-select-label",
|
|
92
|
+
value: "",
|
|
93
|
+
options: single_options,
|
|
94
|
+
onChange: onChange,
|
|
95
|
+
onBlur: onBlur
|
|
96
|
+
})),
|
|
97
|
+
getByRole = _render2.getByRole,
|
|
98
|
+
getAllByRole = _render2.getAllByRole;
|
|
99
|
+
|
|
100
|
+
var radioGroup = getByRole("radiogroup");
|
|
101
|
+
expect(radioGroup.getAttribute("aria-required")).toBe("true");
|
|
102
|
+
|
|
103
|
+
_react2.fireEvent.focus(radioGroup);
|
|
104
|
+
|
|
105
|
+
_react2.fireEvent.blur(radioGroup);
|
|
106
|
+
|
|
107
|
+
expect(onBlur).toHaveBeenCalled();
|
|
108
|
+
expect(onBlur).toHaveBeenCalledWith({
|
|
109
|
+
value: "",
|
|
110
|
+
error: "This field is required. Please, choose an option."
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
_userEvent["default"].click(getAllByRole("radio")[0]);
|
|
114
|
+
|
|
115
|
+
expect(onChange).toHaveBeenCalled();
|
|
116
|
+
expect(onChange).toHaveBeenCalledWith("1");
|
|
117
|
+
});
|
|
118
|
+
test("Controlled - Optional constraint", function () {
|
|
119
|
+
var onChange = jest.fn();
|
|
120
|
+
var onBlur = jest.fn();
|
|
121
|
+
|
|
122
|
+
var _render3 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_RadioGroup["default"], {
|
|
123
|
+
label: "test-radio-group-label",
|
|
124
|
+
helperText: "test-radio-group-helper-text",
|
|
125
|
+
options: single_options,
|
|
126
|
+
onChange: onChange,
|
|
127
|
+
onBlur: onBlur,
|
|
128
|
+
optional: true
|
|
129
|
+
})),
|
|
130
|
+
getByRole = _render3.getByRole;
|
|
131
|
+
|
|
132
|
+
var radioGroup = getByRole("radiogroup");
|
|
133
|
+
expect(radioGroup.getAttribute("aria-required")).toBe("false");
|
|
134
|
+
|
|
135
|
+
_react2.fireEvent.focus(radioGroup);
|
|
136
|
+
|
|
137
|
+
_react2.fireEvent.blur(radioGroup);
|
|
138
|
+
|
|
139
|
+
expect(onBlur).toHaveBeenCalled();
|
|
140
|
+
expect(onBlur).toHaveBeenCalledWith({});
|
|
141
|
+
expect(radioGroup.getAttribute("aria-invalid")).toBe("false");
|
|
142
|
+
});
|
|
143
|
+
test("Select an option - Click on radio input label", function () {
|
|
144
|
+
var onChange = jest.fn();
|
|
145
|
+
|
|
146
|
+
var _render4 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_RadioGroup["default"], {
|
|
147
|
+
label: "test-radio-group-label",
|
|
148
|
+
helperText: "test-radio-group-helper-text",
|
|
149
|
+
options: single_options,
|
|
150
|
+
onChange: onChange
|
|
151
|
+
})),
|
|
152
|
+
getByText = _render4.getByText,
|
|
153
|
+
getAllByRole = _render4.getAllByRole;
|
|
154
|
+
|
|
155
|
+
var radio = getByText("Option 10");
|
|
156
|
+
|
|
157
|
+
_userEvent["default"].click(radio);
|
|
158
|
+
|
|
159
|
+
expect(onChange).toHaveBeenCalled();
|
|
160
|
+
expect(onChange).toHaveBeenCalledWith("10");
|
|
161
|
+
expect(getAllByRole("radio")[9].getAttribute("aria-checked")).toBe("true");
|
|
162
|
+
});
|
|
163
|
+
test("Select an option - Click on radio input", function () {
|
|
164
|
+
var onChange = jest.fn();
|
|
165
|
+
|
|
166
|
+
var _render5 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_RadioGroup["default"], {
|
|
167
|
+
label: "test-radio-group-label",
|
|
168
|
+
helperText: "test-radio-group-helper-text",
|
|
169
|
+
options: single_options,
|
|
170
|
+
onChange: onChange
|
|
171
|
+
})),
|
|
172
|
+
getAllByRole = _render5.getAllByRole;
|
|
173
|
+
|
|
174
|
+
var radio = getAllByRole("radio")[6];
|
|
175
|
+
|
|
176
|
+
_userEvent["default"].click(radio);
|
|
177
|
+
|
|
178
|
+
expect(onChange).toHaveBeenCalled();
|
|
179
|
+
expect(onChange).toHaveBeenCalledWith("7");
|
|
180
|
+
expect(radio.getAttribute("aria-checked")).toBe("true");
|
|
181
|
+
});
|
|
182
|
+
test("Select an option - Tab and Enter key", function () {
|
|
183
|
+
var onChange = jest.fn();
|
|
184
|
+
|
|
185
|
+
var _render6 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_RadioGroup["default"], {
|
|
186
|
+
label: "test-radio-group-label",
|
|
187
|
+
helperText: "test-radio-group-helper-text",
|
|
188
|
+
options: single_options,
|
|
189
|
+
onChange: onChange
|
|
190
|
+
})),
|
|
191
|
+
getByRole = _render6.getByRole,
|
|
192
|
+
getAllByRole = _render6.getAllByRole;
|
|
193
|
+
|
|
194
|
+
var radioGroup = getByRole("radiogroup");
|
|
195
|
+
var radio = getAllByRole("radio")[0];
|
|
196
|
+
|
|
197
|
+
_react2.fireEvent.keyDown(radioGroup, {
|
|
198
|
+
key: "Tab",
|
|
199
|
+
code: "Tab",
|
|
200
|
+
keyCode: 9,
|
|
201
|
+
charCode: 9
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
_react2.fireEvent.keyDown(radioGroup, {
|
|
205
|
+
key: "Enter",
|
|
206
|
+
code: "Enter",
|
|
207
|
+
keyCode: 13,
|
|
208
|
+
charCode: 13
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
expect(onChange).toHaveBeenCalled();
|
|
212
|
+
expect(onChange).toHaveBeenCalledWith("1");
|
|
213
|
+
expect(radio.getAttribute("aria-checked")).toBe("true");
|
|
214
|
+
});
|
|
215
|
+
test("Select an option - Tab and Space key", function () {
|
|
216
|
+
var onChange = jest.fn();
|
|
217
|
+
|
|
218
|
+
var _render7 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_RadioGroup["default"], {
|
|
219
|
+
label: "test-radio-group-label",
|
|
220
|
+
helperText: "test-radio-group-helper-text",
|
|
221
|
+
options: single_options,
|
|
222
|
+
onChange: onChange
|
|
223
|
+
})),
|
|
224
|
+
getByRole = _render7.getByRole,
|
|
225
|
+
getAllByRole = _render7.getAllByRole;
|
|
226
|
+
|
|
227
|
+
var radioGroup = getByRole("radiogroup");
|
|
228
|
+
var radio = getAllByRole("radio")[0];
|
|
229
|
+
|
|
230
|
+
_react2.fireEvent.keyDown(radioGroup, {
|
|
231
|
+
key: "Tab",
|
|
232
|
+
code: "Tab",
|
|
233
|
+
keyCode: 9,
|
|
234
|
+
charCode: 9
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
_react2.fireEvent.keyDown(radioGroup, {
|
|
238
|
+
key: "Space",
|
|
239
|
+
code: "Space",
|
|
240
|
+
keyCode: 32,
|
|
241
|
+
charCode: 32
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
expect(onChange).toHaveBeenCalled();
|
|
245
|
+
expect(onChange).toHaveBeenCalledWith("1");
|
|
246
|
+
expect(radio.getAttribute("aria-checked")).toBe("true");
|
|
247
|
+
});
|
|
248
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare type Option = {
|
|
2
|
+
value: string;
|
|
3
|
+
label: string;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
};
|
|
6
|
+
declare type RadioGroupProps = {
|
|
7
|
+
label: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
helperText?: string;
|
|
10
|
+
options: Option[];
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
optional?: boolean;
|
|
13
|
+
optionalItemLabel?: string;
|
|
14
|
+
readonly?: boolean;
|
|
15
|
+
stacking?: "row" | "column";
|
|
16
|
+
defaultValue?: string;
|
|
17
|
+
value?: string;
|
|
18
|
+
onChange?: (value?: string) => void;
|
|
19
|
+
onBlur?: (val: {
|
|
20
|
+
value?: string;
|
|
21
|
+
error?: string;
|
|
22
|
+
}) => void;
|
|
23
|
+
error?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare type RefType = HTMLDivElement;
|
|
26
|
+
export declare type RadioProps = {
|
|
27
|
+
option: Option;
|
|
28
|
+
currentValue?: string;
|
|
29
|
+
onClick: () => void;
|
|
30
|
+
onFocus: () => void;
|
|
31
|
+
error?: string;
|
|
32
|
+
disabled: boolean;
|
|
33
|
+
focused: boolean;
|
|
34
|
+
readonly: boolean;
|
|
35
|
+
};
|
|
36
|
+
export default RadioGroupProps;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import ResultsetTablePropsType from "./types";
|
|
3
|
+
declare const DxcResultsetTable: ({ columns, rows, showGoToPage, itemsPerPage, itemsPerPageOptions, itemsPerPageFunction, margin, tabIndex, }: ResultsetTablePropsType) => JSX.Element;
|
|
4
|
+
export default DxcResultsetTable;
|