@dxc-technology/halstack-react 0.0.0-ba36a4a → 0.0.0-beebecd
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/dist/ThemeContext.js +69 -61
- package/dist/alert/Alert.js +5 -5
- package/dist/alert/index.d.ts +51 -0
- package/dist/common/variables.js +298 -90
- package/dist/date/Date.js +4 -6
- package/dist/{new-date/NewDate.js → date-input/DateInput.js} +69 -72
- package/dist/date-input/index.d.ts +95 -0
- package/dist/file-input/FileInput.js +644 -0
- package/dist/file-input/FileItem.js +280 -0
- package/dist/file-input/index.d.ts +81 -0
- package/dist/input-text/InputText.js +3 -3
- package/dist/layout/ApplicationLayout.js +1 -1
- package/dist/link/Link.js +4 -8
- package/dist/main.d.ts +8 -0
- package/dist/main.js +29 -13
- package/dist/new-select/NewSelect.js +836 -0
- package/dist/new-select/index.d.ts +53 -0
- package/dist/new-textarea/NewTextarea.js +62 -39
- package/dist/new-textarea/index.d.ts +117 -0
- package/dist/{number/Number.js → number-input/NumberInput.js} +9 -11
- package/dist/{number/NumberContext.js → number-input/NumberInputContext.js} +2 -2
- package/dist/number-input/index.d.ts +113 -0
- package/dist/{password/Password.js → password-input/PasswordInput.js} +11 -13
- package/dist/password-input/index.d.ts +94 -0
- package/dist/progress-bar/ProgressBar.js +1 -1
- package/dist/select/Select.js +122 -158
- package/dist/sidenav/Sidenav.js +6 -4
- package/dist/slider/Slider.js +89 -14
- package/dist/tag/Tag.js +26 -32
- package/dist/{new-input-text/NewInputText.js → text-input/TextInput.js} +180 -170
- package/dist/text-input/index.d.ts +135 -0
- package/dist/toggle-group/ToggleGroup.js +132 -28
- package/package.json +2 -1
- package/test/{NewDate.test.js → DateInput.test.js} +66 -27
- package/test/FileInput.test.js +201 -0
- package/test/InputText.test.js +24 -16
- package/test/NewTextarea.test.js +95 -101
- package/test/{Number.test.js → NumberInput.test.js} +84 -66
- package/test/Paginator.test.js +1 -1
- package/test/PasswordInput.test.js +83 -0
- package/test/ResultsetTable.test.js +1 -2
- package/test/Select.test.js +40 -17
- package/test/{NewInputText.test.js → TextInput.test.js} +146 -231
- package/test/ToggleGroup.test.js +5 -1
- package/dist/footer/Footer.stories.js +0 -94
- package/dist/input-text/InputText.stories.js +0 -209
- package/dist/password/styles.css +0 -3
- package/dist/select/Select.stories.js +0 -235
- package/dist/select/readme.md +0 -72
- package/dist/slider/Slider.stories.js +0 -241
- package/test/Password.test.js +0 -76
|
@@ -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;
|
|
@@ -21,14 +21,56 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
21
21
|
|
|
22
22
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
23
23
|
|
|
24
|
+
var _uuid = require("uuid");
|
|
25
|
+
|
|
24
26
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
25
27
|
|
|
26
28
|
var _variables = require("../common/variables.js");
|
|
27
29
|
|
|
28
30
|
var _useTheme = _interopRequireDefault(require("../useTheme.js"));
|
|
29
31
|
|
|
32
|
+
function _templateObject9() {
|
|
33
|
+
var data = (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"]);
|
|
34
|
+
|
|
35
|
+
_templateObject9 = function _templateObject9() {
|
|
36
|
+
return data;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function _templateObject8() {
|
|
43
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n height: 24px;\n width: 24px;\n margin-right: ", ";\n"]);
|
|
44
|
+
|
|
45
|
+
_templateObject8 = function _templateObject8() {
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function _templateObject7() {
|
|
53
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: row;\n"]);
|
|
54
|
+
|
|
55
|
+
_templateObject7 = function _templateObject7() {
|
|
56
|
+
return data;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _templateObject6() {
|
|
63
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n"]);
|
|
64
|
+
|
|
65
|
+
_templateObject6 = function _templateObject6() {
|
|
66
|
+
return data;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
|
|
30
72
|
function _templateObject5() {
|
|
31
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n
|
|
73
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: column;\n justify-content: center;\n margin-right: ", ";\n\n ", "\n"]);
|
|
32
74
|
|
|
33
75
|
_templateObject5 = function _templateObject5() {
|
|
34
76
|
return data;
|
|
@@ -38,7 +80,7 @@ function _templateObject5() {
|
|
|
38
80
|
}
|
|
39
81
|
|
|
40
82
|
function _templateObject4() {
|
|
41
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n height: ", ";\n
|
|
83
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n display: flex;\n flex-direction: row;\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"]);
|
|
42
84
|
|
|
43
85
|
_templateObject4 = function _templateObject4() {
|
|
44
86
|
return data;
|
|
@@ -48,7 +90,7 @@ function _templateObject4() {
|
|
|
48
90
|
}
|
|
49
91
|
|
|
50
92
|
function _templateObject3() {
|
|
51
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n
|
|
93
|
+
var data = (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"]);
|
|
52
94
|
|
|
53
95
|
_templateObject3 = function _templateObject3() {
|
|
54
96
|
return data;
|
|
@@ -58,7 +100,7 @@ function _templateObject3() {
|
|
|
58
100
|
}
|
|
59
101
|
|
|
60
102
|
function _templateObject2() {
|
|
61
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n
|
|
103
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n"]);
|
|
62
104
|
|
|
63
105
|
_templateObject2 = function _templateObject2() {
|
|
64
106
|
return data;
|
|
@@ -68,7 +110,7 @@ function _templateObject2() {
|
|
|
68
110
|
}
|
|
69
111
|
|
|
70
112
|
function _templateObject() {
|
|
71
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n
|
|
113
|
+
var data = (0, _taggedTemplateLiteral2["default"])(["\n color: ", ";\n font-family: ", ";\n font-size: ", ";\n font-style: ", ";\n font-weight: ", ";\n line-height: ", ";\n"]);
|
|
72
114
|
|
|
73
115
|
_templateObject = function _templateObject() {
|
|
74
116
|
return data;
|
|
@@ -78,7 +120,9 @@ function _templateObject() {
|
|
|
78
120
|
}
|
|
79
121
|
|
|
80
122
|
var DxcToggleGroup = function DxcToggleGroup(_ref) {
|
|
81
|
-
var
|
|
123
|
+
var label = _ref.label,
|
|
124
|
+
helperText = _ref.helperText,
|
|
125
|
+
value = _ref.value,
|
|
82
126
|
onChange = _ref.onChange,
|
|
83
127
|
_ref$disabled = _ref.disabled,
|
|
84
128
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
@@ -96,6 +140,10 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
|
|
|
96
140
|
selectedValue = _useState2[0],
|
|
97
141
|
setSelectedValue = _useState2[1];
|
|
98
142
|
|
|
143
|
+
var _useState3 = (0, _react.useState)("toggle-group-".concat((0, _uuid.v4)())),
|
|
144
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 1),
|
|
145
|
+
toggleGroupId = _useState4[0];
|
|
146
|
+
|
|
99
147
|
var handleToggleChange = function handleToggleChange(selectedOption) {
|
|
100
148
|
var newSelectedOptions;
|
|
101
149
|
|
|
@@ -139,9 +187,19 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
|
|
|
139
187
|
}, _react["default"].createElement(ToggleGroup, {
|
|
140
188
|
margin: margin,
|
|
141
189
|
disabled: disabled
|
|
190
|
+
}, _react["default"].createElement(Label, {
|
|
191
|
+
htmlFor: toggleGroupId,
|
|
192
|
+
disabled: disabled
|
|
193
|
+
}, label), _react["default"].createElement(HelperText, {
|
|
194
|
+
disabled: disabled
|
|
195
|
+
}, helperText), _react["default"].createElement(OptionsContainer, {
|
|
196
|
+
id: toggleGroupId,
|
|
197
|
+
role: multiple ? "group" : "radiogroup"
|
|
142
198
|
}, options.map(function (option, i) {
|
|
143
199
|
return _react["default"].createElement(ToggleContainer, {
|
|
144
200
|
selected: multiple ? value ? value.includes(option.value) : selectedValue.includes(option.value) : value ? option.value === value : option.value === selectedValue,
|
|
201
|
+
role: multiple ? "switch" : "radio",
|
|
202
|
+
"aria-checked": multiple ? value ? value.includes(option.value) : selectedValue.includes(option.value) : value ? option.value === value : option.value === selectedValue,
|
|
145
203
|
tabIndex: !disabled ? tabIndex : -1,
|
|
146
204
|
onClick: function onClick() {
|
|
147
205
|
return !disabled && handleToggleChange(option.value);
|
|
@@ -149,20 +207,50 @@ var DxcToggleGroup = function DxcToggleGroup(_ref) {
|
|
|
149
207
|
isFirst: i === 0,
|
|
150
208
|
isLast: i === options.length - 1,
|
|
151
209
|
isIcon: option.iconSrc || option.icon,
|
|
210
|
+
optionLabel: option.label,
|
|
152
211
|
disabled: disabled,
|
|
153
212
|
onKeyPress: function onKeyPress(event) {
|
|
154
213
|
handleKeyPress(event, option.value);
|
|
155
214
|
},
|
|
156
215
|
key: "toggle-".concat(i, "-").concat(option.label)
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
}) : _react["default"].createElement(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
216
|
+
}, _react["default"].createElement(OptionContent, null, option.icon && _react["default"].createElement(IconContainer, {
|
|
217
|
+
optionLabel: option.label
|
|
218
|
+
}, (0, _typeof2["default"])(option.icon) === "object" ? option.icon : _react["default"].createElement(option.icon)), option.iconSrc && _react["default"].createElement(Icon, {
|
|
219
|
+
src: option.iconSrc,
|
|
220
|
+
optionLabel: option.label
|
|
221
|
+
}), option.label && _react["default"].createElement(LabelContainer, null, option.label)));
|
|
222
|
+
}))));
|
|
163
223
|
};
|
|
164
224
|
|
|
165
|
-
var
|
|
225
|
+
var Label = _styledComponents["default"].label(_templateObject(), function (props) {
|
|
226
|
+
return props.disabled ? props.theme.disabledLabelFontColor : props.theme.labelFontColor;
|
|
227
|
+
}, function (props) {
|
|
228
|
+
return props.theme.labelFontFamily;
|
|
229
|
+
}, function (props) {
|
|
230
|
+
return props.theme.labelFontSize;
|
|
231
|
+
}, function (props) {
|
|
232
|
+
return props.theme.labelFontStyle;
|
|
233
|
+
}, function (props) {
|
|
234
|
+
return props.theme.labelFontWeight;
|
|
235
|
+
}, function (props) {
|
|
236
|
+
return props.theme.labelLineHeight;
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
var HelperText = _styledComponents["default"].span(_templateObject2(), function (props) {
|
|
240
|
+
return props.disabled ? props.theme.disabledHelperTextFontcolor : props.theme.helperTextFontColor;
|
|
241
|
+
}, function (props) {
|
|
242
|
+
return props.theme.helperTextFontFamily;
|
|
243
|
+
}, function (props) {
|
|
244
|
+
return props.theme.helperTextFontSize;
|
|
245
|
+
}, function (props) {
|
|
246
|
+
return props.theme.helperTextFontStyle;
|
|
247
|
+
}, function (props) {
|
|
248
|
+
return props.theme.helperTextFontWeight;
|
|
249
|
+
}, function (props) {
|
|
250
|
+
return props.theme.helperTextLineHeight;
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
var ToggleGroup = _styledComponents["default"].div(_templateObject3(), function (props) {
|
|
166
254
|
return props.margin && (0, _typeof2["default"])(props.margin) !== "object" ? _variables.spaces[props.margin] : "0px";
|
|
167
255
|
}, function (props) {
|
|
168
256
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.top ? _variables.spaces[props.margin.top] : "";
|
|
@@ -174,33 +262,49 @@ var ToggleGroup = _styledComponents["default"].div(_templateObject(), function (
|
|
|
174
262
|
return props.margin && (0, _typeof2["default"])(props.margin) === "object" && props.margin.left ? _variables.spaces[props.margin.left] : "";
|
|
175
263
|
});
|
|
176
264
|
|
|
177
|
-
var
|
|
178
|
-
return
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return props.theme.
|
|
265
|
+
var OptionsContainer = _styledComponents["default"].div(_templateObject4(), function (props) {
|
|
266
|
+
return props.theme.containerBorderThickness;
|
|
267
|
+
}, function (props) {
|
|
268
|
+
return props.theme.containerBorderStyle;
|
|
269
|
+
}, function (props) {
|
|
270
|
+
return props.theme.containerBorderRadius;
|
|
183
271
|
}, function (props) {
|
|
184
|
-
return props.theme.
|
|
272
|
+
return props.theme.containerBorderColor;
|
|
185
273
|
}, function (props) {
|
|
186
|
-
return props.theme.
|
|
274
|
+
return props.theme.containerBackgroundColor;
|
|
187
275
|
}, function (props) {
|
|
188
|
-
return props.theme.
|
|
276
|
+
return props.theme.containerMarginTop;
|
|
189
277
|
});
|
|
190
278
|
|
|
191
|
-
var
|
|
192
|
-
return props.
|
|
279
|
+
var ToggleContainer = _styledComponents["default"].div(_templateObject5(), function (props) {
|
|
280
|
+
return !props.isLast && "4px";
|
|
193
281
|
}, function (props) {
|
|
194
|
-
return props.theme.
|
|
282
|
+
return "\n background-color: ".concat(props.selected ? props.disabled ? props.theme.selectedDisabledBackgroundColor : props.theme.selectedBackgroundColor : props.disabled ? props.theme.unselectedDisabledBackgroundColor : props.theme.unselectedBackgroundColor, ";\n border-width: ").concat(props.theme.optionBorderThickness, ";\n border-style: ").concat(props.theme.optionBorderStyle, ";\n border-radius: ").concat(props.theme.optionBorderRadius, ";\n padding-left: ").concat(props.optionLabel && props.isIcon || props.optionLabel && !props.isIcon ? props.theme.labelPaddingLeft : props.theme.iconPaddingLeft, ";\n padding-right: ").concat(props.optionLabel && props.isIcon || props.optionLabel && !props.isIcon ? props.theme.labelPaddingRight : props.theme.iconPaddingRight, ";\n ").concat(!props.disabled ? ":hover {\n background-color: ".concat(props.selected ? props.theme.selectedHoverBackgroundColor : props.theme.unselectedHoverBackgroundColor, ";\n }\n :active {\n background-color: ").concat(props.selected ? props.theme.selectedActiveBackgroundColor : props.theme.unselectedActiveBackgroundColor, ";\n color: #ffffff;\n } \n :focus {\n border-color: transparent;\n box-shadow: 0 0 0 ").concat(props.theme.optionFocusBorderThickness, " ").concat(props.backgroundType === "dark" ? props.theme.focusColorOnDark : props.theme.focusColor, ";\n }\n &:focus-visible {\n outline: none;\n }\n cursor: pointer;\n color: ").concat(props.selected ? props.theme.selectedFontColor : props.theme.unselectedFontColor, ";\n") : "color: ".concat(props.selected ? props.theme.selectedDisabledFontColor : props.theme.unselectedDisabledFontColor, ";\n cursor: not-allowed;"), "\n ");
|
|
195
283
|
});
|
|
196
284
|
|
|
197
|
-
var
|
|
198
|
-
return props.theme.
|
|
285
|
+
var LabelContainer = _styledComponents["default"].span(_templateObject6(), function (props) {
|
|
286
|
+
return props.theme.optionLabelFontFamily;
|
|
199
287
|
}, function (props) {
|
|
200
|
-
return props.theme.
|
|
288
|
+
return props.theme.optionLabelFontSize;
|
|
289
|
+
}, function (props) {
|
|
290
|
+
return props.theme.optionLabelFontStyle;
|
|
291
|
+
}, function (props) {
|
|
292
|
+
return props.theme.optionLabelFontWeight;
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
var OptionContent = _styledComponents["default"].div(_templateObject7());
|
|
296
|
+
|
|
297
|
+
var Icon = _styledComponents["default"].img(_templateObject8(), function (props) {
|
|
298
|
+
return props.optionLabel && props.theme.iconMarginRight;
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
var IconContainer = _styledComponents["default"].div(_templateObject9(), function (props) {
|
|
302
|
+
return props.optionLabel && props.theme.iconMarginRight;
|
|
201
303
|
});
|
|
202
304
|
|
|
203
305
|
DxcToggleGroup.propTypes = {
|
|
306
|
+
label: _propTypes["default"].string,
|
|
307
|
+
helperText: _propTypes["default"].string,
|
|
204
308
|
value: _propTypes["default"].any,
|
|
205
309
|
onChange: _propTypes["default"].func,
|
|
206
310
|
disabled: _propTypes["default"].bool,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxc-technology/halstack-react",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-beebecd",
|
|
4
4
|
"description": "DXC Halstack React components library",
|
|
5
5
|
"repository": "dxc-technology/halstack-react",
|
|
6
6
|
"homepage": "http://developer.dxc.com/tools/react",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"url": "https://dxc.com"
|
|
12
12
|
},
|
|
13
13
|
"main": "./dist/main.js",
|
|
14
|
+
"types": "./dist/main.d.ts",
|
|
14
15
|
"peerDependencies": {
|
|
15
16
|
"react": "^16.8.6",
|
|
16
17
|
"react-dom": "^16.8.6",
|
|
@@ -2,41 +2,55 @@ import React from "react";
|
|
|
2
2
|
import { render, fireEvent } from "@testing-library/react";
|
|
3
3
|
import userEvent from "@testing-library/user-event";
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import DxcDateInput from "../src/date-input/DateInput";
|
|
6
6
|
|
|
7
|
-
describe("
|
|
7
|
+
describe("DateInput component tests", () => {
|
|
8
8
|
test("Renders with correct label, helper text, optional, placeholder and clearable action", () => {
|
|
9
9
|
const { getByText, getByRole, getAllByRole } = render(
|
|
10
|
-
<
|
|
10
|
+
<DxcDateInput label="Example label" helperText="Example of helper text" placeholder optional clearable />
|
|
11
11
|
);
|
|
12
12
|
const input = getByRole("textbox");
|
|
13
13
|
expect(getByText("Example label")).toBeTruthy();
|
|
14
14
|
expect(getByText("Example of helper text")).toBeTruthy();
|
|
15
15
|
expect(getByText("(Optional)")).toBeTruthy();
|
|
16
16
|
expect(input.getAttribute("placeholder")).toBe("DD-MM-YYYY");
|
|
17
|
-
userEvent.type(input, "10/
|
|
17
|
+
userEvent.type(input, "10/10/2010");
|
|
18
18
|
const closeAction = getAllByRole("button")[0];
|
|
19
19
|
userEvent.click(closeAction);
|
|
20
20
|
expect(input.value).toBe("");
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
test("Renders with personalized error", () => {
|
|
24
|
-
const { getByText } = render(<
|
|
25
|
-
|
|
24
|
+
const { getByText } = render(<DxcDateInput error="Personalized error." />);
|
|
26
25
|
expect(getByText("Personalized error.")).toBeTruthy();
|
|
27
26
|
});
|
|
28
27
|
|
|
29
|
-
test("Renders with correct format: user typed date but it's invalid", () => {
|
|
30
|
-
const
|
|
28
|
+
test("Renders with correct format: user typed date but it's invalid, onBlur error", () => {
|
|
29
|
+
const onBlur = jest.fn(({ value, error }) => {
|
|
30
|
+
expect(value).toBe("10/90/2010");
|
|
31
|
+
expect(error).toBe("Invalid date.");
|
|
32
|
+
});
|
|
33
|
+
const { getByRole } = render(<DxcDateInput label="With format MM/dd/yyyy" format="MM/dd/yyyy" onBlur={onBlur} />);
|
|
31
34
|
const input = getByRole("textbox");
|
|
32
35
|
|
|
33
36
|
userEvent.type(input, "10/90/2010");
|
|
34
37
|
fireEvent.blur(input);
|
|
35
|
-
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("Renders with correct format: user typed date but it's invalid, onChange error", () => {
|
|
41
|
+
const onChange = jest.fn();
|
|
42
|
+
const { getByRole } = render(
|
|
43
|
+
<DxcDateInput label="With format MM/dd/yyyy" format="MM/dd/yyyy" onChange={onChange} />
|
|
44
|
+
);
|
|
45
|
+
const input = getByRole("textbox");
|
|
46
|
+
|
|
47
|
+
userEvent.type(input, "10/90/2010");
|
|
48
|
+
expect(onChange).toHaveBeenCalledTimes(10);
|
|
49
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10/90/2010", error: "Invalid date.", date: null });
|
|
36
50
|
});
|
|
37
51
|
|
|
38
52
|
test("Calendar renders with correct date: today's date", () => {
|
|
39
|
-
const { getByText, getByRole } = render(<
|
|
53
|
+
const { getByText, getByRole } = render(<DxcDateInput />);
|
|
40
54
|
const calendarAction = getByRole("button");
|
|
41
55
|
const d = new Date();
|
|
42
56
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -46,7 +60,7 @@ describe("NewDate component tests", () => {
|
|
|
46
60
|
});
|
|
47
61
|
|
|
48
62
|
test("Calendar renders with correct date: value prop", () => {
|
|
49
|
-
const { getByText, getByRole } = render(<
|
|
63
|
+
const { getByText, getByRole } = render(<DxcDateInput value="20-10-2019" />);
|
|
50
64
|
const calendarAction = getByRole("button");
|
|
51
65
|
const d = new Date(2019, 9, 20);
|
|
52
66
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -56,7 +70,7 @@ describe("NewDate component tests", () => {
|
|
|
56
70
|
});
|
|
57
71
|
|
|
58
72
|
test("Calendar renders with correct date: user typed value", () => {
|
|
59
|
-
const { getByText, getByRole } = render(<
|
|
73
|
+
const { getByText, getByRole } = render(<DxcDateInput />);
|
|
60
74
|
const calendarAction = getByRole("button");
|
|
61
75
|
const d = new Date(2010, 0, 1);
|
|
62
76
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -68,7 +82,8 @@ describe("NewDate component tests", () => {
|
|
|
68
82
|
});
|
|
69
83
|
|
|
70
84
|
test("Calendar renders with correct date: invalid date, renders with today's date", () => {
|
|
71
|
-
const
|
|
85
|
+
const onBlur = jest.fn();
|
|
86
|
+
const { getByText, getByRole } = render(<DxcDateInput onBlur={onBlur} />);
|
|
72
87
|
const calendarAction = getByRole("button");
|
|
73
88
|
const d = new Date();
|
|
74
89
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -76,17 +91,18 @@ describe("NewDate component tests", () => {
|
|
|
76
91
|
|
|
77
92
|
userEvent.type(input, "01-01-xxxx");
|
|
78
93
|
fireEvent.blur(input);
|
|
79
|
-
expect(
|
|
94
|
+
expect(onBlur).toHaveBeenCalled();
|
|
95
|
+
expect(onBlur).toHaveBeenCalledWith({ value: "01-01-xxxx", error: "Invalid date.", date: null });
|
|
80
96
|
userEvent.click(calendarAction);
|
|
81
97
|
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
82
98
|
});
|
|
83
99
|
|
|
84
100
|
test("Selecting a date from the calendar with an specific format", () => {
|
|
85
|
-
const { getByText, getByRole } = render(<
|
|
101
|
+
const { getByText, getByRole } = render(<DxcDateInput label="With format M-dd-yyyy" format="M-dd-yyyy" />);
|
|
86
102
|
const input = getByRole("textbox");
|
|
87
103
|
const calendarAction = getByRole("button");
|
|
88
104
|
userEvent.click(calendarAction);
|
|
89
|
-
const dayButton =
|
|
105
|
+
const dayButton = getByText("10").closest("button");
|
|
90
106
|
fireEvent.click(dayButton);
|
|
91
107
|
const d = new Date();
|
|
92
108
|
d.setDate(10);
|
|
@@ -97,7 +113,7 @@ describe("NewDate component tests", () => {
|
|
|
97
113
|
});
|
|
98
114
|
|
|
99
115
|
test("Selecting a date from the calendar (using keyboard presses)", () => {
|
|
100
|
-
const { getByRole } = render(<
|
|
116
|
+
const { getByRole } = render(<DxcDateInput />);
|
|
101
117
|
const calendarAction = getByRole("button");
|
|
102
118
|
const input = getByRole("textbox");
|
|
103
119
|
|
|
@@ -114,14 +130,14 @@ describe("NewDate component tests", () => {
|
|
|
114
130
|
test("onChange & onBlur functions are called correctly", () => {
|
|
115
131
|
const onBlur = jest.fn();
|
|
116
132
|
const onChange = jest.fn();
|
|
117
|
-
const { getByRole } = render(<
|
|
133
|
+
const { getByRole } = render(<DxcDateInput onChange={onChange} onBlur={onBlur} />);
|
|
118
134
|
const input = getByRole("textbox");
|
|
119
135
|
const d = new Date(2011, 9, 10);
|
|
120
136
|
|
|
121
137
|
userEvent.type(input, "10-10-2011");
|
|
122
138
|
expect(input.value).toBe("10-10-2011");
|
|
123
139
|
expect(onChange).toHaveBeenCalledTimes(10);
|
|
124
|
-
expect(onChange).toHaveBeenCalledWith({ value: "10-10-2011", date: d });
|
|
140
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
125
141
|
fireEvent.blur(input);
|
|
126
142
|
expect(onBlur).toHaveBeenCalled();
|
|
127
143
|
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
@@ -130,14 +146,13 @@ describe("NewDate component tests", () => {
|
|
|
130
146
|
test("onChange & onBlur functions are called correctly, also with errors", () => {
|
|
131
147
|
const onBlur = jest.fn();
|
|
132
148
|
const onChange = jest.fn();
|
|
133
|
-
const { getByRole } = render(<
|
|
149
|
+
const { getByRole } = render(<DxcDateInput onChange={onChange} onBlur={onBlur} />);
|
|
134
150
|
const input = getByRole("textbox");
|
|
135
|
-
const d = new Date(2011, 9, 10);
|
|
136
151
|
|
|
137
152
|
userEvent.type(input, "10-10-");
|
|
138
153
|
expect(input.value).toBe("10-10-");
|
|
139
154
|
expect(onChange).toHaveBeenCalledTimes(6);
|
|
140
|
-
expect(onChange).toHaveBeenCalledWith({ value: "10-10-", date: null });
|
|
155
|
+
expect(onChange).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
141
156
|
fireEvent.blur(input);
|
|
142
157
|
expect(onBlur).toHaveBeenCalled();
|
|
143
158
|
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
@@ -145,7 +160,7 @@ describe("NewDate component tests", () => {
|
|
|
145
160
|
|
|
146
161
|
test("onBlur function removes the error when it is fixed", () => {
|
|
147
162
|
const onBlur = jest.fn();
|
|
148
|
-
const { getByRole } = render(<
|
|
163
|
+
const { getByRole } = render(<DxcDateInput onBlur={onBlur} />);
|
|
149
164
|
const input = getByRole("textbox");
|
|
150
165
|
const d = new Date(2002, 1, 20);
|
|
151
166
|
|
|
@@ -164,7 +179,7 @@ describe("NewDate component tests", () => {
|
|
|
164
179
|
|
|
165
180
|
test("onBlur function removes the error when the input is empty", () => {
|
|
166
181
|
const onBlur = jest.fn();
|
|
167
|
-
const { getByRole } = render(<
|
|
182
|
+
const { getByRole } = render(<DxcDateInput onBlur={onBlur} optional />);
|
|
168
183
|
const input = getByRole("textbox");
|
|
169
184
|
|
|
170
185
|
userEvent.type(input, "test");
|
|
@@ -178,8 +193,32 @@ describe("NewDate component tests", () => {
|
|
|
178
193
|
expect(onBlur).toHaveBeenCalledWith({ value: "", error: null, date: null });
|
|
179
194
|
});
|
|
180
195
|
|
|
181
|
-
test("
|
|
182
|
-
const
|
|
196
|
+
test("onBlur & onChange functions error: required field (not optional)", () => {
|
|
197
|
+
const onBlur = jest.fn();
|
|
198
|
+
const onChange = jest.fn();
|
|
199
|
+
const { getByRole } = render(<DxcDateInput onBlur={onBlur} onChange={onChange} />);
|
|
200
|
+
const date = getByRole("textbox");
|
|
201
|
+
|
|
202
|
+
userEvent.type(date, "t");
|
|
203
|
+
expect(date.value).toBe("t");
|
|
204
|
+
userEvent.clear(date);
|
|
205
|
+
fireEvent.blur(date);
|
|
206
|
+
expect(onBlur).toHaveBeenCalled();
|
|
207
|
+
expect(onBlur).toHaveBeenCalledWith({
|
|
208
|
+
value: "",
|
|
209
|
+
error: "This field is required. Please, enter a value.",
|
|
210
|
+
date: null,
|
|
211
|
+
});
|
|
212
|
+
expect(onChange).toHaveBeenCalled();
|
|
213
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
214
|
+
value: "",
|
|
215
|
+
error: "This field is required. Please, enter a value.",
|
|
216
|
+
date: null,
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test("Disabled date input (calendar action must be shown but not clickable)", () => {
|
|
221
|
+
const { getByRole, queryByText } = render(<DxcDateInput disabled />);
|
|
183
222
|
const calendarAction = getByRole("button");
|
|
184
223
|
const d = new Date();
|
|
185
224
|
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
@@ -190,7 +229,7 @@ describe("NewDate component tests", () => {
|
|
|
190
229
|
});
|
|
191
230
|
|
|
192
231
|
test("Input has correct accesibility attributes", () => {
|
|
193
|
-
const { getByRole } = render(<
|
|
232
|
+
const { getByRole } = render(<DxcDateInput label="Date input label" />);
|
|
194
233
|
const input = getByRole("textbox");
|
|
195
234
|
expect(input.getAttribute("aria-autocomplete")).toBeNull();
|
|
196
235
|
expect(input.getAttribute("aria-controls")).toBeNull();
|