iguazio.dashboard-react-controls 1.9.2 → 2.0.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/dist/components/Backdrop/Backdrop.js +7 -7
- package/dist/components/Button/Button.js +20 -26
- package/dist/components/ConfirmDialog/ConfirmDialog.js +18 -17
- package/dist/components/FormCheckBox/FormCheckBox.js +28 -32
- package/dist/components/FormChipCell/FormChip/FormChip.js +46 -50
- package/dist/components/FormChipCell/FormChipCell.js +122 -142
- package/dist/components/FormChipCell/FormChipCellView.js +44 -47
- package/dist/components/FormChipCell/HiddenChipsBlock/HiddenChipsBlock.js +23 -20
- package/dist/components/FormChipCell/NewChipForm/NewChipForm.js +129 -152
- package/dist/components/FormChipCell/NewChipInput/NewChipInput.js +24 -27
- package/dist/components/FormChipCell/formChipCell.util.js +6 -16
- package/dist/components/FormCombobox/FormCombobox.js +134 -195
- package/dist/components/FormInput/FormInput.js +134 -212
- package/dist/components/FormInput/InputNumberButtons/InputNumberButtons.js +15 -14
- package/dist/components/FormKeyValueTable/FormKeyValueTable.js +72 -72
- package/dist/components/FormRadio/FormRadio.js +21 -25
- package/dist/components/FormSelect/FormSelect.js +98 -126
- package/dist/components/FormSelect/FormSelect.test.js +56 -60
- package/dist/components/FormTextarea/FormTextarea.js +55 -71
- package/dist/components/FormToggle/FormToggle.js +25 -29
- package/dist/components/Modal/Modal.js +17 -18
- package/dist/components/PopUpDialog/PopUpDialog.js +53 -63
- package/dist/components/RoundedIcon/RoundedIcon.js +14 -13
- package/dist/components/Tip/Tip.js +58 -64
- package/dist/components/Tip/Tip.test.js +41 -64
- package/dist/components/Tooltip/Tooltip.js +75 -89
- package/dist/components/TooltipTemplate/ProducerTooltipTemplate.js +6 -5
- package/dist/components/TooltipTemplate/TextTooltipTemplate.js +10 -10
- package/dist/components/Wizard/Wizard.js +73 -107
- package/dist/components/Wizard/WizardSteps/WizardSteps.js +19 -20
- package/dist/components/index.js +18 -18
- package/dist/constants.js +26 -44
- package/dist/elements/FormActionButton/FormActionButton.js +12 -13
- package/dist/elements/FormRowActions/FormRowActions.js +19 -22
- package/dist/elements/OptionsMenu/OptionsMenu.js +10 -8
- package/dist/elements/SelectOption/SelectOption.js +14 -13
- package/dist/elements/SelectOption/SelectOption.test.js +39 -47
- package/dist/elements/ValidationTemplate/ValidationTemplate.js +7 -6
- package/dist/elements/index.js +5 -5
- package/dist/hooks/index.js +5 -5
- package/dist/hooks/useChipCell.hook.js +66 -85
- package/dist/hooks/useDebounce.hook.js +22 -24
- package/dist/hooks/useDetectOutsideClick.hook.js +4 -4
- package/dist/hooks/useFormTable.hook.js +99 -112
- package/dist/hooks/useHiddenChipsBlock.hook.js +40 -55
- package/dist/index.js +2 -3
- package/dist/scss/borders.scss +6 -0
- package/dist/scss/mixins.scss +32 -0
- package/dist/types.js +43 -67
- package/dist/utils/common.util.js +19 -23
- package/dist/utils/form.util.js +33 -39
- package/dist/utils/generateChipsList.util.js +7 -7
- package/dist/utils/getFirstScrollableParent.util.js +4 -10
- package/dist/utils/math.util.js +3 -3
- package/dist/utils/validation.util.js +74 -131
- package/package.json +34 -34
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -20,183 +19,156 @@ var _dropdown = require("../../images/dropdown.svg");
|
|
|
20
19
|
require("./formSelect.scss");
|
|
21
20
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
function _getRequireWildcardCache(
|
|
24
|
-
function _interopRequireWildcard(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
file except in compliance with the License. You may obtain a copy of
|
|
44
|
-
the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
45
|
-
Unless required by applicable law or agreed to in writing, software
|
|
46
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
47
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
48
|
-
implied. See the License for the specific language governing
|
|
49
|
-
permissions and limitations under the License.
|
|
50
|
-
In addition, you may not use the software for any purposes that are
|
|
51
|
-
illegal under applicable law, and the grant of the foregoing license
|
|
52
|
-
under the Apache 2.0 license is conditioned upon your compliance with
|
|
53
|
-
such restriction.
|
|
54
|
-
*/
|
|
55
|
-
var FormSelect = function FormSelect(_ref) {
|
|
22
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
23
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
24
|
+
/*
|
|
25
|
+
Copyright 2022 Iguazio Systems Ltd.
|
|
26
|
+
Licensed under the Apache License, Version 2.0 (the "License") with
|
|
27
|
+
an addition restriction as set forth herein. You may not use this
|
|
28
|
+
file except in compliance with the License. You may obtain a copy of
|
|
29
|
+
the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
30
|
+
Unless required by applicable law or agreed to in writing, software
|
|
31
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
32
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
33
|
+
implied. See the License for the specific language governing
|
|
34
|
+
permissions and limitations under the License.
|
|
35
|
+
In addition, you may not use the software for any purposes that are
|
|
36
|
+
illegal under applicable law, and the grant of the foregoing license
|
|
37
|
+
under the Apache 2.0 license is conditioned upon your compliance with
|
|
38
|
+
such restriction.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
const FormSelect = _ref => {
|
|
56
42
|
var _selectRef$current;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var _ref2 = (selectRef === null || selectRef === void 0 ? void 0 : (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 ? void 0 : _selectRef$current.getBoundingClientRect()) || {},
|
|
97
|
-
selectWidth = _ref2.width;
|
|
98
|
-
var selectWrapperClassNames = (0, _classnames.default)('form-field__wrapper', "form-field__wrapper-".concat(density), disabled && 'form-field__wrapper-disabled', isOpen && 'form-field__wrapper-active', isInvalid && 'form-field__wrapper-invalid', withoutBorder && 'without-border');
|
|
99
|
-
var selectLabelClassName = (0, _classnames.default)('form-field__label', disabled && 'form-field__label-disabled');
|
|
100
|
-
var selectValueClassName = (0, _classnames.default)('form-field__select-value', !input.value && 'form-field__select-placeholder');
|
|
101
|
-
var selectedOption = options.find(function (option) {
|
|
102
|
-
return option.id === input.value;
|
|
103
|
-
});
|
|
104
|
-
var getFilteredOptions = (0, _react.useCallback)(function (options) {
|
|
105
|
-
return options.filter(function (option) {
|
|
43
|
+
let {
|
|
44
|
+
className,
|
|
45
|
+
density,
|
|
46
|
+
disabled,
|
|
47
|
+
hideSelectedOption,
|
|
48
|
+
label,
|
|
49
|
+
multiple,
|
|
50
|
+
name,
|
|
51
|
+
onChange,
|
|
52
|
+
options,
|
|
53
|
+
required,
|
|
54
|
+
search,
|
|
55
|
+
selectedItemAction,
|
|
56
|
+
scrollToView,
|
|
57
|
+
tooltip,
|
|
58
|
+
withoutBorder,
|
|
59
|
+
withSelectedIcon
|
|
60
|
+
} = _ref;
|
|
61
|
+
const {
|
|
62
|
+
input,
|
|
63
|
+
meta
|
|
64
|
+
} = (0, _reactFinalForm.useField)(name);
|
|
65
|
+
const [isInvalid, setIsInvalid] = (0, _react.useState)(false);
|
|
66
|
+
const [isConfirmDialogOpen, setConfirmDialogOpen] = (0, _react.useState)(false);
|
|
67
|
+
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
68
|
+
const [searchValue, setSearchValue] = (0, _react.useState)('');
|
|
69
|
+
const optionsListRef = (0, _react.useRef)();
|
|
70
|
+
const popUpRef = (0, _react.useRef)();
|
|
71
|
+
const selectRef = (0, _react.useRef)();
|
|
72
|
+
const searchRef = (0, _react.useRef)();
|
|
73
|
+
const {
|
|
74
|
+
width: selectWidth
|
|
75
|
+
} = (selectRef === null || selectRef === void 0 || (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 ? void 0 : _selectRef$current.getBoundingClientRect()) || {};
|
|
76
|
+
const selectWrapperClassNames = (0, _classnames.default)('form-field__wrapper', "form-field__wrapper-".concat(density), disabled && 'form-field__wrapper-disabled', isOpen && 'form-field__wrapper-active', isInvalid && 'form-field__wrapper-invalid', withoutBorder && 'without-border');
|
|
77
|
+
const selectLabelClassName = (0, _classnames.default)('form-field__label', disabled && 'form-field__label-disabled');
|
|
78
|
+
const selectValueClassName = (0, _classnames.default)('form-field__select-value', !input.value && 'form-field__select-placeholder');
|
|
79
|
+
const selectedOption = options.find(option => option.id === input.value);
|
|
80
|
+
const getFilteredOptions = (0, _react.useCallback)(options => {
|
|
81
|
+
return options.filter(option => {
|
|
106
82
|
return !search || option.label.toLowerCase().includes(searchValue.toLowerCase());
|
|
107
83
|
});
|
|
108
84
|
}, [search, searchValue]);
|
|
109
|
-
|
|
85
|
+
const sortedOptionsList = (0, _react.useMemo)(() => {
|
|
110
86
|
if (scrollToView) {
|
|
111
87
|
return getFilteredOptions(options);
|
|
112
88
|
}
|
|
113
|
-
|
|
114
|
-
|
|
89
|
+
const optionsList = [...options];
|
|
90
|
+
const selectedOption = optionsList.filter((option, idx, arr) => {
|
|
115
91
|
if (option.id === input.value) {
|
|
116
92
|
arr.splice(idx, 1);
|
|
117
93
|
return true;
|
|
118
94
|
}
|
|
119
95
|
return false;
|
|
120
96
|
});
|
|
121
|
-
return getFilteredOptions([
|
|
97
|
+
return getFilteredOptions([...selectedOption, ...optionsList]);
|
|
122
98
|
}, [input.value, getFilteredOptions, options, scrollToView]);
|
|
123
|
-
|
|
99
|
+
const getSelectValue = () => {
|
|
124
100
|
if (!input.value || !input.value.length) {
|
|
125
101
|
return "Select Option".concat(multiple ? 's' : '');
|
|
126
102
|
}
|
|
127
|
-
return !multiple ? selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label : input.value.length <= 2 ? options.filter(
|
|
128
|
-
return input.value.includes(option.id);
|
|
129
|
-
}).map(function (option) {
|
|
130
|
-
return option.label;
|
|
131
|
-
}).join(', ') : "".concat(input.value.length, " items selected");
|
|
103
|
+
return !multiple ? selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label : input.value.length <= 2 ? options.filter(option => input.value.includes(option.id)).map(option => option.label).join(', ') : "".concat(input.value.length, " items selected");
|
|
132
104
|
};
|
|
133
|
-
(0, _react.useEffect)(
|
|
105
|
+
(0, _react.useEffect)(() => {
|
|
134
106
|
setIsInvalid(meta.invalid && (meta.validating || meta.modified || meta.submitFailed && meta.touched));
|
|
135
107
|
}, [meta.invalid, meta.modified, meta.submitFailed, meta.touched, meta.validating]);
|
|
136
|
-
|
|
108
|
+
const openMenu = (0, _react.useCallback)(() => {
|
|
137
109
|
if (!isOpen) {
|
|
138
110
|
setIsOpen(true);
|
|
139
111
|
input.onFocus(new Event('focus'));
|
|
140
112
|
}
|
|
141
113
|
}, [input, isOpen]);
|
|
142
|
-
|
|
114
|
+
const closeMenu = (0, _react.useCallback)(() => {
|
|
143
115
|
if (isOpen) {
|
|
144
116
|
setIsOpen(false);
|
|
145
117
|
input.onBlur(new Event('blur'));
|
|
146
118
|
}
|
|
147
119
|
}, [input, isOpen]);
|
|
148
|
-
|
|
120
|
+
const clickHandler = (0, _react.useCallback)(event => {
|
|
149
121
|
if (selectRef.current !== event.target.closest('.form-field-select')) {
|
|
150
122
|
closeMenu();
|
|
151
123
|
}
|
|
152
124
|
}, [closeMenu]);
|
|
153
|
-
|
|
125
|
+
const handleScroll = (0, _react.useCallback)(event => {
|
|
154
126
|
if (!event.target.closest('.options-list__body')) {
|
|
155
127
|
closeMenu();
|
|
156
128
|
}
|
|
157
129
|
}, [closeMenu]);
|
|
158
|
-
(0, _react.useEffect)(
|
|
130
|
+
(0, _react.useEffect)(() => {
|
|
159
131
|
if (isOpen) {
|
|
160
132
|
window.addEventListener('scroll', handleScroll, true);
|
|
161
133
|
}
|
|
162
134
|
window.addEventListener('click', clickHandler);
|
|
163
|
-
return
|
|
135
|
+
return () => {
|
|
164
136
|
window.removeEventListener('click', clickHandler);
|
|
165
137
|
window.removeEventListener('scroll', handleScroll, true);
|
|
166
138
|
};
|
|
167
139
|
}, [clickHandler, handleScroll, isOpen]);
|
|
168
|
-
|
|
169
|
-
|
|
140
|
+
const scrollOptionToView = (0, _react.useCallback)(() => {
|
|
141
|
+
const selectedOptionEl = optionsListRef.current.querySelector("[data-custom-id=\"".concat(input.value, "\"]"));
|
|
170
142
|
if (!selectedOptionEl) return;
|
|
171
143
|
searchValue ? optionsListRef.current.scrollTo({
|
|
172
144
|
top: 0,
|
|
173
145
|
left: 0,
|
|
174
146
|
behavior: 'smooth'
|
|
175
|
-
}) : setTimeout(
|
|
147
|
+
}) : setTimeout(() => {
|
|
176
148
|
selectedOptionEl.scrollIntoView({
|
|
177
149
|
behavior: 'smooth',
|
|
178
150
|
block: 'center'
|
|
179
151
|
});
|
|
180
152
|
}, 0);
|
|
181
153
|
}, [input.value, searchValue]);
|
|
182
|
-
(0, _react.useEffect)(
|
|
154
|
+
(0, _react.useEffect)(() => {
|
|
183
155
|
if (isOpen && optionsListRef.current && scrollToView) {
|
|
184
156
|
scrollOptionToView();
|
|
185
157
|
}
|
|
186
158
|
}, [isOpen, scrollOptionToView, scrollToView]);
|
|
187
|
-
(0, _react.useEffect)(
|
|
159
|
+
(0, _react.useEffect)(() => {
|
|
188
160
|
if (isOpen && search && searchRef.current) {
|
|
189
161
|
searchRef.current.focus();
|
|
190
162
|
}
|
|
191
163
|
}, [isOpen, search]);
|
|
192
|
-
|
|
164
|
+
const toggleOpen = () => {
|
|
193
165
|
if (isOpen) {
|
|
194
166
|
closeMenu();
|
|
195
167
|
} else {
|
|
196
168
|
!disabled && openMenu();
|
|
197
169
|
}
|
|
198
170
|
};
|
|
199
|
-
|
|
171
|
+
const handleCloseSelectBody = (0, _react.useCallback)(event => {
|
|
200
172
|
event.stopPropagation();
|
|
201
173
|
if (multiple) return;
|
|
202
174
|
if (!event.target.classList.contains('disabled') && !event.target.closest('.options-list__search')) {
|
|
@@ -204,16 +176,16 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
204
176
|
setSearchValue('');
|
|
205
177
|
}
|
|
206
178
|
}, [closeMenu, multiple]);
|
|
207
|
-
|
|
179
|
+
const handleSelectOptionClick = (selectedOption, option) => {
|
|
208
180
|
if (selectedOption !== input.value) {
|
|
209
181
|
option.handler && option.handler();
|
|
210
182
|
onChange && onChange(selectedOption);
|
|
211
|
-
setTimeout(
|
|
183
|
+
setTimeout(() => {
|
|
212
184
|
input.onChange(selectedOption);
|
|
213
185
|
});
|
|
214
186
|
}
|
|
215
187
|
};
|
|
216
|
-
|
|
188
|
+
const validateField = value => {
|
|
217
189
|
if (required) {
|
|
218
190
|
return value ? undefined : 'Required';
|
|
219
191
|
}
|
|
@@ -221,9 +193,11 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
221
193
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
222
194
|
name: name,
|
|
223
195
|
validate: validateField,
|
|
224
|
-
children:
|
|
225
|
-
|
|
226
|
-
|
|
196
|
+
children: _ref2 => {
|
|
197
|
+
let {
|
|
198
|
+
input,
|
|
199
|
+
meta
|
|
200
|
+
} = _ref2;
|
|
227
201
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
228
202
|
className: "select-tooltip",
|
|
229
203
|
template: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextTooltipTemplate.default, {
|
|
@@ -265,7 +239,7 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
265
239
|
text: selectedItemAction.tooltip
|
|
266
240
|
}),
|
|
267
241
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
268
|
-
onClick:
|
|
242
|
+
onClick: event => {
|
|
269
243
|
if (selectedItemAction.confirm) {
|
|
270
244
|
setConfirmDialogOpen(true);
|
|
271
245
|
} else {
|
|
@@ -286,17 +260,17 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
286
260
|
})]
|
|
287
261
|
}), isConfirmDialogOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfirmDialog.default, {
|
|
288
262
|
cancelButton: {
|
|
289
|
-
handler:
|
|
263
|
+
handler: () => {
|
|
290
264
|
setConfirmDialogOpen(false);
|
|
291
265
|
},
|
|
292
266
|
label: 'Cancel',
|
|
293
267
|
variant: _constants.TERTIARY_BUTTON
|
|
294
268
|
},
|
|
295
|
-
closePopUp:
|
|
269
|
+
closePopUp: () => {
|
|
296
270
|
setConfirmDialogOpen(false);
|
|
297
271
|
},
|
|
298
272
|
confirmButton: {
|
|
299
|
-
handler:
|
|
273
|
+
handler: () => {
|
|
300
274
|
selectedItemAction.handler(input.value);
|
|
301
275
|
setConfirmDialogOpen(false);
|
|
302
276
|
},
|
|
@@ -329,20 +303,18 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
329
303
|
type: "text",
|
|
330
304
|
placeholder: "Search...",
|
|
331
305
|
value: searchValue,
|
|
332
|
-
onChange:
|
|
333
|
-
return setSearchValue(event.target.value);
|
|
334
|
-
},
|
|
306
|
+
onChange: event => setSearchValue(event.target.value),
|
|
335
307
|
ref: searchRef,
|
|
336
308
|
autoFocus: true
|
|
337
309
|
})
|
|
338
310
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
|
|
339
311
|
className: "options-list",
|
|
340
312
|
ref: optionsListRef,
|
|
341
|
-
children: sortedOptionsList.map(
|
|
313
|
+
children: sortedOptionsList.map(option => {
|
|
342
314
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectOption.default, {
|
|
343
315
|
item: option,
|
|
344
316
|
name: name,
|
|
345
|
-
onClick:
|
|
317
|
+
onClick: selectedOption => {
|
|
346
318
|
handleSelectOptionClick(selectedOption, option);
|
|
347
319
|
},
|
|
348
320
|
multiple: multiple,
|
|
@@ -352,9 +324,10 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
352
324
|
})
|
|
353
325
|
})]
|
|
354
326
|
})
|
|
355
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input",
|
|
327
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
328
|
+
...input,
|
|
356
329
|
type: "hidden"
|
|
357
|
-
})
|
|
330
|
+
})]
|
|
358
331
|
})
|
|
359
332
|
});
|
|
360
333
|
}
|
|
@@ -390,5 +363,4 @@ FormSelect.propTypes = {
|
|
|
390
363
|
withoutBorder: _propTypes.default.bool,
|
|
391
364
|
withSelectedIcon: _propTypes.default.bool
|
|
392
365
|
};
|
|
393
|
-
var _default = /*#__PURE__*/_react.default.memo(FormSelect);
|
|
394
|
-
exports.default = _default;
|
|
366
|
+
var _default = exports.default = /*#__PURE__*/_react.default.memo(FormSelect);
|
|
@@ -5,40 +5,34 @@ var _Select = _interopRequireDefault(require("./Select"));
|
|
|
5
5
|
var _react2 = require("@testing-library/react");
|
|
6
6
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
7
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
describe('Select component', function () {
|
|
38
|
-
var wrapper;
|
|
39
|
-
var mockClick = jest.fn();
|
|
40
|
-
beforeEach(function () {
|
|
41
|
-
var props = {
|
|
8
|
+
/*
|
|
9
|
+
Copyright 2022 Iguazio Systems Ltd.
|
|
10
|
+
Licensed under the Apache License, Version 2.0 (the "License") with
|
|
11
|
+
an addition restriction as set forth herein. You may not use this
|
|
12
|
+
file except in compliance with the License. You may obtain a copy of
|
|
13
|
+
the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
14
|
+
Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
17
|
+
implied. See the License for the specific language governing
|
|
18
|
+
permissions and limitations under the License.
|
|
19
|
+
In addition, you may not use the software for any purposes that are
|
|
20
|
+
illegal under applicable law, and the grant of the foregoing license
|
|
21
|
+
under the Apache 2.0 license is conditioned upon your compliance with
|
|
22
|
+
such restriction.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
jest.mock('../../images/dropdown.svg', () => ({
|
|
26
|
+
ReactComponent: 'caret-icon'
|
|
27
|
+
}));
|
|
28
|
+
const renderComponent = props => (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.default, {
|
|
29
|
+
...props
|
|
30
|
+
}));
|
|
31
|
+
describe('Select component', () => {
|
|
32
|
+
let wrapper;
|
|
33
|
+
const mockClick = jest.fn();
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
const props = {
|
|
42
36
|
label: 'Select',
|
|
43
37
|
floatingLabel: true,
|
|
44
38
|
selectedId: 'test1',
|
|
@@ -52,47 +46,49 @@ describe('Select component', function () {
|
|
|
52
46
|
wrapper = renderComponent(props);
|
|
53
47
|
});
|
|
54
48
|
afterEach(_react2.cleanup);
|
|
55
|
-
it('renders without crashing',
|
|
49
|
+
it('renders without crashing', () => {
|
|
56
50
|
expect(wrapper.queryByTestId('select')).not.toBeNull();
|
|
57
51
|
});
|
|
58
|
-
it('should show select body after click by select header',
|
|
59
|
-
|
|
52
|
+
it('should show select body after click by select header', () => {
|
|
53
|
+
const select = wrapper.getByTestId('select');
|
|
60
54
|
_react2.fireEvent.click(select);
|
|
61
55
|
expect(wrapper.queryByTestId('select-body')).not.toBeNull();
|
|
62
56
|
});
|
|
63
|
-
it('should hide the select body when scrolling',
|
|
64
|
-
|
|
57
|
+
it('should hide the select body when scrolling', () => {
|
|
58
|
+
const select = wrapper.getByTestId('select');
|
|
65
59
|
_react2.fireEvent.click(select);
|
|
66
60
|
expect(wrapper.queryByTestId('select-body')).not.toBeNull();
|
|
67
61
|
_react2.fireEvent.scroll(window);
|
|
68
62
|
expect(wrapper.queryByTestId('select-body')).toBeNull();
|
|
69
63
|
});
|
|
70
|
-
it('should call "onClick" callback with "test1"',
|
|
71
|
-
|
|
64
|
+
it('should call "onClick" callback with "test1"', () => {
|
|
65
|
+
const select = wrapper.getByTestId('select');
|
|
72
66
|
_react2.fireEvent.click(select);
|
|
73
|
-
|
|
67
|
+
const selectOption = wrapper.getByTestId('select-option');
|
|
74
68
|
_react2.fireEvent.click(selectOption);
|
|
75
69
|
expect(mockClick).toHaveBeenCalledWith('test1');
|
|
76
70
|
});
|
|
77
|
-
it('should not close "selectBody" if click by disabled option',
|
|
78
|
-
|
|
71
|
+
it('should not close "selectBody" if click by disabled option', () => {
|
|
72
|
+
const props = {
|
|
79
73
|
options: [{
|
|
80
74
|
label: 'Test1',
|
|
81
75
|
id: 'test1'
|
|
82
76
|
}],
|
|
83
77
|
disabledOptions: ['test1']
|
|
84
78
|
};
|
|
85
|
-
wrapper.rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.default,
|
|
86
|
-
|
|
79
|
+
wrapper.rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.default, {
|
|
80
|
+
...props
|
|
81
|
+
}));
|
|
82
|
+
const select = wrapper.getByTestId('select');
|
|
87
83
|
_react2.fireEvent.click(select);
|
|
88
|
-
|
|
84
|
+
const selectOption = wrapper.getByTestId('select-option');
|
|
89
85
|
_react2.fireEvent.click(selectOption);
|
|
90
86
|
expect(wrapper.queryByTestId('select-body')).not.toBeNull();
|
|
91
87
|
});
|
|
92
|
-
it('should display selected option',
|
|
93
|
-
|
|
88
|
+
it('should display selected option', () => {
|
|
89
|
+
const select = wrapper.getByTestId('select');
|
|
94
90
|
_react2.fireEvent.click(select);
|
|
95
|
-
|
|
91
|
+
const selectOption = wrapper.getByTestId('select-option');
|
|
96
92
|
_react2.fireEvent.click(selectOption);
|
|
97
93
|
expect(mockClick).toHaveBeenCalledWith('test1');
|
|
98
94
|
wrapper.rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.default, {
|
|
@@ -102,13 +98,13 @@ describe('Select component', function () {
|
|
|
102
98
|
}],
|
|
103
99
|
selectedId: "test1"
|
|
104
100
|
}));
|
|
105
|
-
|
|
101
|
+
const selectedOption = wrapper.getByTestId('selected-option');
|
|
106
102
|
expect(selectedOption.textContent).toEqual('Test1');
|
|
107
103
|
});
|
|
108
|
-
it('should add className "select__label_floating" to select label if props floatingLabel "true"',
|
|
104
|
+
it('should add className "select__label_floating" to select label if props floatingLabel "true"', () => {
|
|
109
105
|
expect(wrapper.getByTestId('select-label').className).toMatch('select__label_floating');
|
|
110
106
|
});
|
|
111
|
-
it('should not open select body if props disabled set to "true"',
|
|
107
|
+
it('should not open select body if props disabled set to "true"', () => {
|
|
112
108
|
wrapper.rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.default, {
|
|
113
109
|
options: [{
|
|
114
110
|
label: 'Test1',
|
|
@@ -116,16 +112,16 @@ describe('Select component', function () {
|
|
|
116
112
|
}],
|
|
117
113
|
disabled: true
|
|
118
114
|
}));
|
|
119
|
-
|
|
115
|
+
const select = wrapper.getByTestId('select');
|
|
120
116
|
_react2.fireEvent.click(select);
|
|
121
117
|
expect(wrapper.queryByTestId('select-body')).toBeNull();
|
|
122
118
|
});
|
|
123
|
-
it('should display a "subLabel" if it exists in the option',
|
|
124
|
-
|
|
119
|
+
it('should display a "subLabel" if it exists in the option', () => {
|
|
120
|
+
const subLabel = wrapper.queryByTestId('select-subLabel');
|
|
125
121
|
expect(subLabel).not.toBeNull();
|
|
126
122
|
});
|
|
127
|
-
it('should call handler callback if it exists in the option',
|
|
128
|
-
|
|
123
|
+
it('should call handler callback if it exists in the option', () => {
|
|
124
|
+
const mockHandler = jest.fn();
|
|
129
125
|
wrapper.rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.default, {
|
|
130
126
|
options: [{
|
|
131
127
|
label: 'Test1',
|
|
@@ -133,9 +129,9 @@ describe('Select component', function () {
|
|
|
133
129
|
handler: mockHandler
|
|
134
130
|
}]
|
|
135
131
|
}));
|
|
136
|
-
|
|
132
|
+
const select = wrapper.getByTestId('select');
|
|
137
133
|
_react2.fireEvent.click(select);
|
|
138
|
-
|
|
134
|
+
const selectOption = wrapper.getByTestId('select-option');
|
|
139
135
|
_react2.fireEvent.click(selectOption);
|
|
140
136
|
expect(mockHandler).toHaveBeenCalled();
|
|
141
137
|
});
|