iguazio.dashboard-react-controls 0.0.12 → 0.0.15

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.
@@ -0,0 +1,517 @@
1
+ "use strict";
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
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _reactFinalForm = require("react-final-form");
13
+
14
+ var _lodash = require("lodash");
15
+
16
+ var _propTypes = _interopRequireDefault(require("prop-types"));
17
+
18
+ var _classnames = _interopRequireDefault(require("classnames"));
19
+
20
+ var _elements = require("../../elements");
21
+
22
+ var _validation = require("../../utils/validation.util");
23
+
24
+ var _hooks = require("../../hooks");
25
+
26
+ var _types = require("../../types");
27
+
28
+ var _arrow = require("../../images/arrow.svg");
29
+
30
+ var _search = require("../../images/search.svg");
31
+
32
+ var _warning = require("../../images/warning.svg");
33
+
34
+ require("./formCombobox.scss");
35
+
36
+ var _jsxRuntime = require("react/jsx-runtime");
37
+
38
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
+
40
+ 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); }
41
+
42
+ 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; }
43
+
44
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
45
+
46
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
47
+
48
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
49
+
50
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
51
+
52
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
53
+
54
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
55
+
56
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
57
+
58
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
59
+
60
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
61
+
62
+ var FormCombobox = function FormCombobox(_ref) {
63
+ var comboboxClassName = _ref.comboboxClassName,
64
+ density = _ref.density,
65
+ disabled = _ref.disabled,
66
+ hideSearchInput = _ref.hideSearchInput,
67
+ inputDefaultValue = _ref.inputDefaultValue,
68
+ inputPlaceholder = _ref.inputPlaceholder,
69
+ invalidText = _ref.invalidText,
70
+ maxSuggestedMatches = _ref.maxSuggestedMatches,
71
+ name = _ref.name,
72
+ onBlur = _ref.onBlur,
73
+ onChange = _ref.onChange,
74
+ onFocus = _ref.onFocus,
75
+ required = _ref.required,
76
+ rules = _ref.rules,
77
+ selectDefaultValue = _ref.selectDefaultValue,
78
+ selectOptions = _ref.selectOptions,
79
+ selectPlaceholder = _ref.selectPlaceholder,
80
+ suggestionList = _ref.suggestionList,
81
+ validator = _ref.validator,
82
+ withoutBorder = _ref.withoutBorder;
83
+
84
+ var _useField = (0, _reactFinalForm.useField)(name),
85
+ input = _useField.input,
86
+ meta = _useField.meta;
87
+
88
+ var _useState = (0, _react.useState)(''),
89
+ _useState2 = _slicedToArray(_useState, 2),
90
+ inputValue = _useState2[0],
91
+ setInputValue = _useState2[1];
92
+
93
+ var _useState3 = (0, _react.useState)({
94
+ label: '',
95
+ id: '',
96
+ className: ''
97
+ }),
98
+ _useState4 = _slicedToArray(_useState3, 2),
99
+ selectValue = _useState4[0],
100
+ setSelectValue = _useState4[1];
101
+
102
+ var _useState5 = (0, _react.useState)({
103
+ left: '0',
104
+ paddingTop: '10px'
105
+ }),
106
+ _useState6 = _slicedToArray(_useState5, 2),
107
+ dropdownStyle = _useState6[0],
108
+ setDropdownStyle = _useState6[1];
109
+
110
+ var _useState7 = (0, _react.useState)(false),
111
+ _useState8 = _slicedToArray(_useState7, 2),
112
+ showSelectDropdown = _useState8[0],
113
+ setShowSelectDropdown = _useState8[1];
114
+
115
+ var _useState9 = (0, _react.useState)(false),
116
+ _useState10 = _slicedToArray(_useState9, 2),
117
+ showSuggestionList = _useState10[0],
118
+ setShowSuggestionList = _useState10[1];
119
+
120
+ var _useState11 = (0, _react.useState)(suggestionList),
121
+ _useState12 = _slicedToArray(_useState11, 2),
122
+ dropdownList = _useState12[0],
123
+ setDropdownList = _useState12[1];
124
+
125
+ var _useState13 = (0, _react.useState)(false),
126
+ _useState14 = _slicedToArray(_useState13, 2),
127
+ searchIsFocused = _useState14[0],
128
+ setSearchIsFocused = _useState14[1];
129
+
130
+ var _useState15 = (0, _react.useState)(false),
131
+ _useState16 = _slicedToArray(_useState15, 2),
132
+ isInvalid = _useState16[0],
133
+ setIsInvalid = _useState16[1];
134
+
135
+ var _useState17 = (0, _react.useState)(rules),
136
+ _useState18 = _slicedToArray(_useState17, 2),
137
+ validationRules = _useState18[0],
138
+ setValidationRules = _useState18[1];
139
+
140
+ var _useState19 = (0, _react.useState)(false),
141
+ _useState20 = _slicedToArray(_useState19, 2),
142
+ showValidationRules = _useState20[0],
143
+ setShowValidationRules = _useState20[1];
144
+
145
+ var comboboxRef = (0, _react.useRef)();
146
+ var selectRef = (0, _react.useRef)();
147
+ var inputRef = (0, _react.useRef)();
148
+ (0, _hooks.useDetectOutsideClick)(comboboxRef, function () {
149
+ return setShowValidationRules(false);
150
+ });
151
+ (0, _react.useEffect)(function () {
152
+ if ((selectDefaultValue === null || selectDefaultValue === void 0 ? void 0 : selectDefaultValue.label.length) > 0 && selectValue.label.length === 0) {
153
+ setSelectValue(selectDefaultValue);
154
+ input.onChange(selectDefaultValue.id);
155
+ onChange && onChange(selectDefaultValue);
156
+ }
157
+ }, [input, onChange, selectDefaultValue, selectValue.label.length]);
158
+ (0, _react.useEffect)(function () {
159
+ if (inputDefaultValue.length > 0 && selectValue.id.length > 0 && inputValue.length === 0) {
160
+ setInputValue(inputDefaultValue);
161
+ onChange && onChange(selectValue.id, inputDefaultValue);
162
+ input.onChange("".concat(selectValue.id).concat(inputDefaultValue));
163
+ }
164
+ }, [input, inputDefaultValue, inputValue.length, onChange, selectValue]);
165
+ (0, _react.useEffect)(function () {
166
+ setValidationRules(function (prevState) {
167
+ return prevState.map(function (rule) {
168
+ return _objectSpread(_objectSpread({}, rule), {}, {
169
+ isValid: !meta.error || !Array.isArray(meta.error) ? true : !meta.error.some(function (err) {
170
+ return err.name === rule.name;
171
+ })
172
+ });
173
+ });
174
+ });
175
+ }, [meta.error]);
176
+ (0, _react.useEffect)(function () {
177
+ if (!searchIsFocused) {
178
+ if (JSON.stringify(dropdownList) !== JSON.stringify(suggestionList)) {
179
+ setDropdownList(suggestionList);
180
+ }
181
+ }
182
+ }, [dropdownList, suggestionList, searchIsFocused]);
183
+ (0, _react.useEffect)(function () {
184
+ setIsInvalid(meta.invalid && (meta.validating || meta.modified || meta.submitFailed && meta.touched));
185
+ }, [meta.invalid, meta.modified, meta.submitFailed, meta.touched, meta.validating]);
186
+ var handleOutsideClick = (0, _react.useCallback)(function (event) {
187
+ if (comboboxRef.current && !comboboxRef.current.contains(event.target)) {
188
+ setSearchIsFocused(false);
189
+ setShowSelectDropdown(false);
190
+ setShowSuggestionList(false);
191
+ input.onBlur(new Event('blur'));
192
+ onBlur && onBlur(input.value);
193
+ }
194
+ }, [input, onBlur]);
195
+ (0, _react.useEffect)(function () {
196
+ window.addEventListener('click', handleOutsideClick);
197
+ return function () {
198
+ window.removeEventListener('click', handleOutsideClick);
199
+ };
200
+ }, [handleOutsideClick]);
201
+
202
+ var getValidationRules = function getValidationRules() {
203
+ return validationRules.map(function (_ref2) {
204
+ var _ref2$isValid = _ref2.isValid,
205
+ isValid = _ref2$isValid === void 0 ? false : _ref2$isValid,
206
+ label = _ref2.label,
207
+ name = _ref2.name;
208
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_elements.ValidationTemplate, {
209
+ valid: isValid,
210
+ validationMessage: label
211
+ }, name);
212
+ });
213
+ };
214
+
215
+ var handleInputChange = function handleInputChange(event) {
216
+ var target = event.target;
217
+ setDropdownStyle({
218
+ left: "".concat(target.selectionStart < 30 ? target.selectionStart : 30, "ch"),
219
+ paddingTop: '10px'
220
+ });
221
+
222
+ if (searchIsFocused) {
223
+ setSearchIsFocused(false);
224
+ }
225
+
226
+ setInputValue(target.value);
227
+ input.onChange("".concat(selectValue.id).concat(target.value));
228
+ onChange && onChange(selectValue.id, target.value);
229
+
230
+ if (dropdownList.length > 0) {
231
+ setShowSuggestionList(true);
232
+ }
233
+ };
234
+
235
+ var handleSelectOptionClick = function handleSelectOptionClick(selectedOption, option) {
236
+ if (selectedOption.id !== selectValue.id) {
237
+ setSelectValue(selectedOption);
238
+ input.onChange(selectedOption.id);
239
+ setInputValue('');
240
+ onChange && onChange(selectedOption.id);
241
+ setShowSelectDropdown(false);
242
+ inputRef.current.disabled = false;
243
+ inputRef.current.focus();
244
+ }
245
+ };
246
+
247
+ var handleSuggestionListOptionClick = function handleSuggestionListOptionClick(option) {
248
+ var inputValueItems = inputValue.split('/');
249
+ var valueIndex = inputValueItems.length - 1;
250
+ var formattedValue = option.customDelimiter ? inputValueItems[valueIndex].replace(new RegExp("".concat(option.customDelimiter, ".*")), '') + option.id : option.id;
251
+ if (inputValueItems.length <= maxSuggestedMatches - 1) formattedValue += '/';
252
+ inputValueItems[valueIndex] = formattedValue;
253
+
254
+ if (searchIsFocused) {
255
+ setSearchIsFocused(false);
256
+ }
257
+
258
+ if (inputValueItems.join('/') !== inputValue) {
259
+ setInputValue(inputValueItems.join('/'));
260
+ input.onChange("".concat(selectValue.id).concat(inputValueItems.join('/')));
261
+ onChange && onChange(selectValue.id, inputValueItems.join('/'));
262
+ }
263
+
264
+ setShowSuggestionList(false);
265
+ inputRef.current.focus();
266
+ setDropdownStyle({
267
+ left: "".concat(inputRef.current.selectionStart < 30 ? inputRef.current.selectionStart : 30, "ch"),
268
+ paddingTop: '10px'
269
+ });
270
+ };
271
+
272
+ var inputOnFocus = function inputOnFocus() {
273
+ onFocus && onFocus();
274
+ input.onFocus(new Event('focus'));
275
+
276
+ if (showSelectDropdown) {
277
+ setShowSelectDropdown(false);
278
+ }
279
+
280
+ setShowSuggestionList(true);
281
+ };
282
+
283
+ var suggestionListSearchChange = function suggestionListSearchChange(event) {
284
+ event.persist();
285
+ setDropdownList(function () {
286
+ return suggestionList.filter(function (option) {
287
+ return option.id.startsWith(event.target.value);
288
+ });
289
+ });
290
+ };
291
+
292
+ var toggleSelect = (0, _react.useCallback)(function () {
293
+ if (showSelectDropdown) {
294
+ setShowSelectDropdown(false);
295
+ input.onBlur(new Event('blur'));
296
+ onBlur && onBlur(input.value);
297
+ } else {
298
+ setShowSuggestionList(false);
299
+ setShowValidationRules(false);
300
+ setDropdownStyle({
301
+ left: '0',
302
+ paddingTop: '10px'
303
+ });
304
+ setShowSelectDropdown(true);
305
+ input.onFocus(new Event('focus'));
306
+ onFocus && onFocus(input.value);
307
+ }
308
+ }, [input, onBlur, onFocus, showSelectDropdown]);
309
+
310
+ var validateField = function validateField(value) {
311
+ var valueToValidate = value !== null && value !== void 0 ? value : '';
312
+ var validationError = null;
313
+
314
+ if (!(0, _lodash.isEmpty)(validationRules)) {
315
+ var _checkPatternsValidit = (0, _validation.checkPatternsValidity)(rules, valueToValidate),
316
+ _checkPatternsValidit2 = _slicedToArray(_checkPatternsValidit, 2),
317
+ newRules = _checkPatternsValidit2[0],
318
+ isValidField = _checkPatternsValidit2[1];
319
+
320
+ var invalidRules = newRules.filter(function (rule) {
321
+ return !rule.isValid;
322
+ });
323
+
324
+ if (!isValidField) {
325
+ validationError = invalidRules.map(function (rule) {
326
+ return {
327
+ name: rule.name,
328
+ label: rule.label
329
+ };
330
+ });
331
+ }
332
+ }
333
+
334
+ if ((0, _lodash.isEmpty)(validationError)) {
335
+ if (valueToValidate.startsWith(' ')) {
336
+ validationError = {
337
+ name: 'empty',
338
+ label: invalidText
339
+ };
340
+ } else if (required && valueToValidate.trim().length === 0) {
341
+ validationError = {
342
+ name: 'required',
343
+ label: 'This field is required'
344
+ };
345
+ }
346
+ }
347
+
348
+ if (!validationError && validator) {
349
+ validationError = validator(value);
350
+ }
351
+
352
+ return validationError;
353
+ };
354
+
355
+ var warningIconClick = function warningIconClick() {
356
+ setShowValidationRules(function (state) {
357
+ return !state;
358
+ });
359
+ setShowSelectDropdown(false);
360
+ };
361
+
362
+ var comboboxClassNames = (0, _classnames.default)(comboboxClassName, 'form-field-combobox', 'form-field', isInvalid && 'form-field-combobox_invalid');
363
+ var iconClassNames = (0, _classnames.default)(showSelectDropdown && 'form-field-combobox__icon_open', 'form-field-combobox__icon');
364
+ var selectClassNames = (0, _classnames.default)('form-field-combobox__select', 'form-field__control', showSelectDropdown && 'form-field-combobox__select_open', selectValue.id.length <= 5 && selectValue.id.length !== 0 && 'form-field-combobox__select_short');
365
+ var selectValueClassNames = (0, _classnames.default)(selectValue.className);
366
+ var dropdownClassNames = (0, _classnames.default)('form-field-combobox__dropdown', 'form-field-combobox__input-dropdown', showSuggestionList && dropdownList.length > 0 && 'form-field-combobox__input-dropdown_visible');
367
+ var wrapperClassNames = (0, _classnames.default)('form-field__wrapper', "form-field__wrapper-".concat(density), disabled && 'form-field__wrapper-disabled', isInvalid && 'form-field__wrapper-invalid', withoutBorder && 'without-border');
368
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
369
+ name: name,
370
+ validate: validateField,
371
+ children: function children(_ref3) {
372
+ var input = _ref3.input,
373
+ meta = _ref3.meta;
374
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
375
+ className: comboboxClassNames,
376
+ ref: comboboxRef,
377
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
378
+ className: wrapperClassNames,
379
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
380
+ className: "form-field__icons",
381
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_arrow.ReactComponent, {
382
+ className: iconClassNames,
383
+ onClick: toggleSelect
384
+ })
385
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
386
+ className: selectClassNames,
387
+ ref: selectRef,
388
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
389
+ className: "form-field-combobox__select-header",
390
+ onClick: toggleSelect,
391
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
392
+ className: selectValueClassNames,
393
+ children: selectValue.id
394
+ }), selectValue.id.length === 0 && selectPlaceholder && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
395
+ className: "form-field__label",
396
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
397
+ children: [selectPlaceholder, (meta.error || required) && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
398
+ className: "form-field__label-mandatory",
399
+ children: " *"
400
+ })]
401
+ })
402
+ })]
403
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
404
+ className: "form-field-combobox__select-body form-field-combobox__dropdown",
405
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
406
+ className: "form-field-combobox__list",
407
+ children: selectOptions.map(function (option) {
408
+ var selectOptionClassNames = (0, _classnames.default)('form-field-combobox__list-option', option.className);
409
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
410
+ className: selectOptionClassNames,
411
+ onClick: function onClick() {
412
+ return handleSelectOptionClick(option);
413
+ },
414
+ children: option.label
415
+ }, option.id);
416
+ })
417
+ })
418
+ })]
419
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
420
+ className: "form-field-combobox__input form-field__control",
421
+ disabled: selectValue.id.length === 0,
422
+ onChange: handleInputChange,
423
+ onFocus: inputOnFocus,
424
+ placeholder: inputPlaceholder,
425
+ ref: inputRef,
426
+ type: "text",
427
+ value: inputValue
428
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
429
+ className: dropdownClassNames,
430
+ style: _objectSpread({}, dropdownStyle),
431
+ children: [!hideSearchInput && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
432
+ className: "form-field-combobox__search-wrapper",
433
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
434
+ className: "form-field-combobox__search form-field__control",
435
+ onChange: suggestionListSearchChange,
436
+ onFocus: function onFocus() {
437
+ return setSearchIsFocused(true);
438
+ },
439
+ placeholder: "Type to search",
440
+ type: "text"
441
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_search.ReactComponent, {})]
442
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
443
+ className: "form-field-combobox__list",
444
+ children: searchIsFocused && dropdownList.length === 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
445
+ className: "form-field-combobox__list-option",
446
+ children: "No data"
447
+ }, "no data") : dropdownList.map(function (value) {
448
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
449
+ className: "form-field-combobox__list-option",
450
+ onClick: function onClick() {
451
+ return handleSuggestionListOptionClick(value);
452
+ },
453
+ children: value.label
454
+ }, value.id);
455
+ })
456
+ })]
457
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
458
+ className: "form-field__icons",
459
+ children: isInvalid && Array.isArray(meta.error) && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
460
+ className: "form-field__warning",
461
+ onClick: warningIconClick,
462
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_warning.ReactComponent, {})
463
+ })
464
+ }), !(0, _lodash.isEmpty)(validationRules) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_elements.OptionsMenu, {
465
+ show: showValidationRules,
466
+ ref: comboboxRef,
467
+ children: getValidationRules()
468
+ })]
469
+ })
470
+ });
471
+ }
472
+ });
473
+ };
474
+
475
+ FormCombobox.defaultProps = {
476
+ comboboxClassName: '',
477
+ density: 'normal',
478
+ disabled: false,
479
+ hideSearchInput: false,
480
+ inputDefaultValue: '',
481
+ inputPlaceholder: '',
482
+ maxSuggestedMatches: 1,
483
+ onBlur: null,
484
+ onFocus: null,
485
+ onChange: null,
486
+ required: false,
487
+ rules: [],
488
+ selectDefaultValue: null,
489
+ selectPlaceholder: '',
490
+ suggestionList: [],
491
+ validator: null,
492
+ withoutBorder: false
493
+ };
494
+ FormCombobox.propTypes = {
495
+ comboboxClassName: _propTypes.default.string,
496
+ density: _propTypes.default.oneOf(['dense', 'normal', 'medium', 'chunky']),
497
+ disabled: _propTypes.default.bool,
498
+ hideSearchInput: _propTypes.default.bool,
499
+ inputDefaultValue: _propTypes.default.string,
500
+ inputPlaceholder: _propTypes.default.string,
501
+ invalidText: _propTypes.default.string,
502
+ maxSuggestedMatches: _propTypes.default.number,
503
+ name: _propTypes.default.string.isRequired,
504
+ onBlur: _propTypes.default.func,
505
+ onChange: _propTypes.default.func,
506
+ onFocus: _propTypes.default.func,
507
+ required: _propTypes.default.bool,
508
+ rules: _propTypes.default.array,
509
+ selectDefaultValue: _propTypes.default.string,
510
+ selectOptions: _types.COMBOBOX_SELECT_OPTIONS.isRequired,
511
+ selectPlaceholder: _propTypes.default.string,
512
+ suggestionList: _types.COMBOBOX_SUGGESTION_LIST,
513
+ validator: _propTypes.default.func,
514
+ withoutBorder: _propTypes.default.bool
515
+ };
516
+ var _default = FormCombobox;
517
+ exports.default = _default;
@@ -0,0 +1,102 @@
1
+ @import '../../scss/colors';
2
+ @import '../../scss/borders';
3
+ @import '../../scss/shadows';
4
+ @import '../../scss/mixins';
5
+
6
+ .form-field.form-field-combobox {
7
+ width: 100%;
8
+
9
+ .form-field {
10
+ @include inputSelectField;
11
+
12
+ &__icons {
13
+ .form-field-combobox__icon {
14
+ cursor: pointer;
15
+ padding: 0;
16
+
17
+ &_open {
18
+ transform: rotate(90deg);
19
+ transform-origin: center center;
20
+ transition: transform 200ms linear;
21
+ }
22
+ }
23
+ }
24
+
25
+ &__label {
26
+ margin-bottom: 0;
27
+ font-size: 15px;
28
+ }
29
+
30
+ &-combobox {
31
+ &__select {
32
+ flex: unset;
33
+ padding: 0;
34
+ max-width: 110px;
35
+ overflow: visible;
36
+
37
+ &-header {
38
+ display: flex;
39
+ align-items: center;
40
+ }
41
+
42
+ &-body {
43
+ top: 35px;
44
+ max-width: 220px;
45
+ }
46
+
47
+ &_open {
48
+ .form-field-combobox__select-body {
49
+ display: block;
50
+ }
51
+ }
52
+ }
53
+
54
+ &__dropdown {
55
+ position: absolute;
56
+ z-index: 5;
57
+ display: none;
58
+ padding: 0;
59
+ background-color: $white;
60
+ box-shadow: $previewBoxShadow;
61
+ }
62
+
63
+ &__list {
64
+ margin: 0;
65
+ padding: 0;
66
+ min-width: 140px;
67
+ list-style-type: none;
68
+
69
+ &-option {
70
+ padding: 8px 15px;
71
+ word-break: break-all;
72
+ cursor: pointer;
73
+
74
+ &:hover {
75
+ background-color: $alabaster;
76
+ }
77
+ }
78
+ }
79
+
80
+ &__input {
81
+ padding: 0;
82
+
83
+ &-dropdown {
84
+ top: 40px;
85
+ max-width: 350px;
86
+
87
+ &_visible {
88
+ display: block;
89
+ }
90
+ }
91
+ }
92
+ &__search {
93
+ padding-left: 8px;
94
+
95
+ &-wrapper {
96
+ display: flex;
97
+ padding: 5px;
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
@@ -212,7 +212,9 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
212
212
 
213
213
  var toggleValidationRulesMenu = function toggleValidationRulesMenu() {
214
214
  inputRef.current.focus();
215
- setShowValidationRules(!showValidationRules);
215
+ setShowValidationRules(function (state) {
216
+ return !state;
217
+ });
216
218
  };
217
219
 
218
220
  (0, _react.useEffect)(function () {
@@ -229,7 +231,7 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
229
231
 
230
232
  var validateField = function validateField(value) {
231
233
  var valueToValidate = (0, _lodash.isNil)(value) ? '' : String(value);
232
- if (!valueToValidate && !required) return;
234
+ if (!valueToValidate && !required || disabled) return;
233
235
  var validationError = null;
234
236
 
235
237
  if (!(0, _lodash.isEmpty)(validationRules)) {
@@ -57,16 +57,16 @@ var Modal = function Modal(_ref) {
57
57
  show = _ref.show,
58
58
  title = _ref.title;
59
59
 
60
- var _useState = (0, _react.useState)(location),
60
+ var _useState = (0, _react.useState)(location.pathname),
61
61
  _useState2 = _slicedToArray(_useState, 2),
62
62
  currentLocation = _useState2[0],
63
63
  setCurrentLocation = _useState2[1];
64
64
 
65
65
  var modalClassNames = (0, _classnames.default)('modal', className, size && "modal-".concat(size));
66
66
  (0, _react.useEffect)(function () {
67
- setCurrentLocation(location);
67
+ setCurrentLocation(location.pathname);
68
68
  return function () {
69
- if (location !== currentLocation) {
69
+ if (location.pathname !== currentLocation) {
70
70
  onClose();
71
71
  }
72
72
  };
@@ -128,7 +128,7 @@ Modal.defaultProps = {
128
128
  Modal.propTypes = {
129
129
  actions: _propTypes.default.array,
130
130
  children: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.object, _propTypes.default.node, _propTypes.default.string]).isRequired,
131
- location: _propTypes.default.string.isRequired,
131
+ location: _propTypes.default.object.isRequired,
132
132
  onClose: _propTypes.default.func.isRequired,
133
133
  show: _propTypes.default.bool.isRequired,
134
134
  size: _types.MODAL_SIZES,
@@ -98,13 +98,13 @@
98
98
  &-enter {
99
99
  opacity: 0;
100
100
  transform: translate(-50%, calc(100vh));
101
- transition: all 0.3s ease-in-out;
102
101
  }
103
102
 
104
103
  &-enter-active,
105
104
  &-enter-done {
106
105
  opacity: 1;
107
106
  transform: translate(-50%, -50%);
107
+ transition: all 0.3s ease-in-out;
108
108
  }
109
109
 
110
110
  &-exit {
@@ -15,8 +15,6 @@ var _classnames = _interopRequireDefault(require("classnames"));
15
15
 
16
16
  var _Button = _interopRequireDefault(require("../Button/Button"));
17
17
 
18
- var _ConfirmDialog = _interopRequireDefault(require("../ConfirmDialog/ConfirmDialog"));
19
-
20
18
  var _Modal = _interopRequireDefault(require("../Modal/Modal"));
21
19
 
22
20
  var _WizardSteps = _interopRequireDefault(require("./WizardSteps/WizardSteps"));
@@ -25,8 +23,6 @@ var _constants = require("../../constants");
25
23
 
26
24
  var _types = require("../../types");
27
25
 
28
- var _common = require("../../utils/common.util");
29
-
30
26
  require("./Wizard.scss");
31
27
 
32
28
  var _jsxRuntime = require("react/jsx-runtime");
@@ -108,26 +104,6 @@ var Wizard = function Wizard(_ref) {
108
104
  return setActiveStepNumber(idx);
109
105
  };
110
106
 
111
- var handleOnClose = function handleOnClose() {
112
- if (formState && formState.dirty) {
113
- (0, _common.openPopUp)(_ConfirmDialog.default, {
114
- cancelButton: {
115
- label: 'Cancel',
116
- variant: _constants.TERTIARY_BUTTON
117
- },
118
- confirmButton: {
119
- handler: onWizardResolve,
120
- label: 'OK',
121
- variant: _constants.SECONDARY_BUTTON
122
- },
123
- header: 'Are you sure?',
124
- message: 'All changes will be lost'
125
- });
126
- } else {
127
- onWizardResolve();
128
- }
129
- };
130
-
131
107
  var handleSubmit = function handleSubmit() {
132
108
  formState.handleSubmit();
133
109
 
@@ -163,7 +139,7 @@ var Wizard = function Wizard(_ref) {
163
139
  formState: formState,
164
140
  goToNextStep: goToNextStep,
165
141
  goToPreviousStep: goToPreviousStep,
166
- handleOnClose: handleOnClose,
142
+ onWizardResolve: onWizardResolve,
167
143
  handleSubmit: handleSubmit
168
144
  }).map(function (action) {
169
145
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, _objectSpread({}, action));
@@ -176,7 +152,7 @@ var Wizard = function Wizard(_ref) {
176
152
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Modal.default, {
177
153
  actions: renderModalActions(),
178
154
  className: wizardClasses,
179
- onClose: handleOnClose,
155
+ onClose: onWizardResolve,
180
156
  location: location,
181
157
  show: isWizardOpen,
182
158
  size: size,
@@ -11,5 +11,6 @@
11
11
  height: 100%;
12
12
  width: 100%;
13
13
  padding-right: 2rem;
14
+ padding-left: 1rem;
14
15
  }
15
16
  }
@@ -5,7 +5,7 @@
5
5
  .wizard-steps {
6
6
  background-color: $white;
7
7
  min-width: 260px;
8
- margin-right: 2rem;
8
+ margin-right: 1rem;
9
9
 
10
10
  &__indicator {
11
11
  display: inline-flex;
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "FormCheckBox", {
21
21
  return _FormCheckBox.default;
22
22
  }
23
23
  });
24
+ Object.defineProperty(exports, "FormCombobox", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _FormCombobox.default;
28
+ }
29
+ });
24
30
  Object.defineProperty(exports, "FormInput", {
25
31
  enumerable: true,
26
32
  get: function get() {
@@ -124,4 +130,6 @@ var _Tooltip = _interopRequireDefault(require("./Tooltip/Tooltip"));
124
130
 
125
131
  var _Wizard = _interopRequireDefault(require("./Wizard/Wizard"));
126
132
 
133
+ var _FormCombobox = _interopRequireDefault(require("./FormCombobox/FormCombobox"));
134
+
127
135
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -1041,27 +1041,19 @@
1041
1041
  }
1042
1042
 
1043
1043
  &-dense {
1044
- .form-field__control > *:first-child {
1045
- height: $fieldDense;
1046
- }
1044
+ height: $fieldDense;
1047
1045
  }
1048
1046
 
1049
1047
  &-normal {
1050
- .form-field__control > *:first-child {
1051
- height: $fieldNormal;
1052
- }
1048
+ height: $fieldNormal;
1053
1049
  }
1054
1050
 
1055
1051
  &-medium {
1056
- .form-field__control > *:first-child {
1057
- height: $fieldMedium;
1058
- }
1052
+ height: $fieldMedium;
1059
1053
  }
1060
1054
 
1061
1055
  &-chunky {
1062
- .form-field__control > *:first-child {
1063
- height: $fieldChunky;
1064
- }
1056
+ height: $fieldChunky;
1065
1057
  }
1066
1058
  }
1067
1059
 
@@ -1131,8 +1123,16 @@
1131
1123
 
1132
1124
  &:focus:not(:disabled),
1133
1125
  &:active:not(:disabled) {
1134
- outline: 1px solid #b1bcf3;
1135
- outline-offset: 2px;
1126
+ animation: pulse-animation 0.5s ease-out;
1127
+ }
1128
+
1129
+ @keyframes pulse-animation {
1130
+ 20% {
1131
+ box-shadow: 0 0 0 0 rgba($cornflowerBlue, 0.5);
1132
+ }
1133
+ 100% {
1134
+ box-shadow: 0 0 0 6px rgba($cornflowerBlue, 0);
1135
+ }
1136
1136
  }
1137
1137
 
1138
1138
  &:hover {
package/dist/types.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.WIZARD_STEPS_CONFIG = exports.SELECT_OPTIONS = exports.SELECT_OPTION = exports.POP_UP_CUSTOM_POSITION = exports.MODAL_SIZES = exports.INPUT_VALIDATION_RULES = exports.INPUT_LINK = exports.CONFIRM_DIALOG_SUBMIT_BUTTON = exports.CONFIRM_DIALOG_CANCEL_BUTTON = exports.BUTTON_VARIANTS = void 0;
6
+ exports.WIZARD_STEPS_CONFIG = exports.SELECT_OPTIONS = exports.SELECT_OPTION = exports.POP_UP_CUSTOM_POSITION = exports.MODAL_SIZES = exports.INPUT_VALIDATION_RULES = exports.INPUT_LINK = exports.CONFIRM_DIALOG_SUBMIT_BUTTON = exports.CONFIRM_DIALOG_CANCEL_BUTTON = exports.COMBOBOX_VALIDATION_RULES = exports.COMBOBOX_SUGGESTION_LIST = exports.COMBOBOX_SELECT_OPTIONS = exports.BUTTON_VARIANTS = void 0;
7
7
 
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
 
@@ -80,4 +80,28 @@ var INPUT_VALIDATION_RULES = _propTypes.default.arrayOf(_propTypes.default.shape
80
80
  isValid: _propTypes.default.bool
81
81
  }));
82
82
 
83
- exports.INPUT_VALIDATION_RULES = INPUT_VALIDATION_RULES;
83
+ exports.INPUT_VALIDATION_RULES = INPUT_VALIDATION_RULES;
84
+
85
+ var COMBOBOX_SUGGESTION_LIST = _propTypes.default.arrayOf(_propTypes.default.shape({
86
+ customDelimiter: _propTypes.default.string,
87
+ id: _propTypes.default.string.isRequired,
88
+ label: _propTypes.default.string.isRequired
89
+ }));
90
+
91
+ exports.COMBOBOX_SUGGESTION_LIST = COMBOBOX_SUGGESTION_LIST;
92
+
93
+ var COMBOBOX_VALIDATION_RULES = _propTypes.default.arrayOf(_propTypes.default.shape({
94
+ name: _propTypes.default.string.isRequired,
95
+ label: _propTypes.default.string.isRequired,
96
+ isValid: _propTypes.default.bool
97
+ }));
98
+
99
+ exports.COMBOBOX_VALIDATION_RULES = COMBOBOX_VALIDATION_RULES;
100
+
101
+ var COMBOBOX_SELECT_OPTIONS = _propTypes.default.arrayOf(_propTypes.default.shape({
102
+ className: _propTypes.default.string,
103
+ id: _propTypes.default.string.isRequired,
104
+ label: _propTypes.default.string.isRequired
105
+ }));
106
+
107
+ exports.COMBOBOX_SELECT_OPTIONS = COMBOBOX_SELECT_OPTIONS;
@@ -246,7 +246,8 @@ var validationRules = {
246
246
  }), generateRule.required()],
247
247
  tag: [generateRule.validCharacters('a-z A-Z 0-9 - _ .'), generateRule.beginEndWith('a-z A-Z 0-9'), generateRule.length({
248
248
  max: 56
249
- })]
249
+ })],
250
+ combobox: [generateRule.required()]
250
251
  },
251
252
  project: {
252
253
  name: [generateRule.validCharacters('a-z 0-9 -'), generateRule.beginWith('a-z'), generateRule.endWith('a-z 0-9'), generateRule.length({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iguazio.dashboard-react-controls",
3
- "version": "0.0.12",
3
+ "version": "0.0.15",
4
4
  "description": "Collection of resources (such as CSS styles, fonts and images) and ReactJS 17.x components to share among different Iguazio React repos.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",