iguazio.dashboard-react-controls 0.0.11 → 0.0.14
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/FormCheckBox/FormCheckBox.js +41 -23
- package/dist/components/FormCheckBox/formCheckBox.scss +35 -17
- package/dist/components/FormCombobox/FormCombobox.js +517 -0
- package/dist/components/FormCombobox/formCombobox.scss +102 -0
- package/dist/components/FormInput/FormInput.js +38 -15
- package/dist/components/FormInput/InputNumberButtons/InputNumberButtons.js +97 -0
- package/dist/components/FormInput/InputNumberButtons/InputNumberButtons.scss +123 -0
- package/dist/components/FormInput/formInput.scss +12 -2
- package/dist/components/FormRadio/FormRadio.js +72 -0
- package/dist/components/FormRadio/FormRadio.scss +36 -0
- package/dist/components/FormSelect/FormSelect.js +33 -21
- package/dist/components/FormSelect/formSelect.scss +10 -10
- package/dist/components/FormTextarea/FormTextarea.js +1 -1
- package/dist/components/FormTextarea/formTextarea.scss +2 -2
- package/dist/components/Wizard/Wizard.js +4 -2
- package/dist/components/Wizard/WizardSteps/WizardSteps.scss +2 -2
- package/dist/components/index.js +16 -0
- package/dist/elements/SelectOption/SelectOption.js +30 -25
- package/dist/elements/SelectOption/selectOption.scss +31 -14
- package/dist/scss/mixins.scss +64 -1
- package/dist/types.js +26 -2
- package/dist/utils/validation.util.js +2 -1
- package/package.json +1 -1
|
@@ -9,47 +9,65 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _reactFinalForm = require("react-final-form");
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
15
|
|
|
16
16
|
require("./formCheckBox.scss");
|
|
17
17
|
|
|
18
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
19
|
|
|
20
|
+
var _excluded = ["children", "className", "name", "label"];
|
|
21
|
+
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
23
|
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
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; }
|
|
29
|
+
|
|
30
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
31
|
+
|
|
32
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
33
|
+
|
|
22
34
|
var FormCheckBox = function FormCheckBox(_ref) {
|
|
23
|
-
var
|
|
35
|
+
var _children = _ref.children,
|
|
24
36
|
className = _ref.className,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
name = _ref.name,
|
|
38
|
+
label = _ref.label,
|
|
39
|
+
inputProps = _objectWithoutProperties(_ref, _excluded);
|
|
40
|
+
|
|
41
|
+
var formFieldClassNames = (0, _classnames.default)('form-field-checkbox', className);
|
|
42
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
43
|
+
name: name,
|
|
44
|
+
value: inputProps.value,
|
|
45
|
+
type: "checkbox",
|
|
46
|
+
children: function children(_ref2) {
|
|
47
|
+
var _inputProps$value, _inputProps$value2;
|
|
48
|
+
|
|
49
|
+
var input = _ref2.input;
|
|
50
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
51
|
+
className: formFieldClassNames,
|
|
52
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, input), inputProps)), {}, {
|
|
53
|
+
id: (_inputProps$value = inputProps.value) !== null && _inputProps$value !== void 0 ? _inputProps$value : name
|
|
54
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
55
|
+
htmlFor: (_inputProps$value2 = inputProps.value) !== null && _inputProps$value2 !== void 0 ? _inputProps$value2 : name,
|
|
56
|
+
children: [label ? label : '', _children]
|
|
57
|
+
})]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
38
60
|
});
|
|
39
61
|
};
|
|
40
62
|
|
|
41
63
|
FormCheckBox.defaultProps = {
|
|
42
64
|
className: '',
|
|
43
|
-
|
|
65
|
+
label: ''
|
|
44
66
|
};
|
|
45
67
|
FormCheckBox.propTypes = {
|
|
46
68
|
className: _propTypes.default.string,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
label: _propTypes.default.string
|
|
50
|
-
}).isRequired,
|
|
51
|
-
onChange: _propTypes.default.func.isRequired,
|
|
52
|
-
selectedId: _propTypes.default.string
|
|
69
|
+
name: _propTypes.default.string.isRequired,
|
|
70
|
+
label: _propTypes.default.string
|
|
53
71
|
};
|
|
54
72
|
|
|
55
73
|
var _default = /*#__PURE__*/_react.default.memo(FormCheckBox);
|
|
@@ -1,32 +1,50 @@
|
|
|
1
1
|
@import '../../scss/colors';
|
|
2
|
+
@import '../../scss/mixins';
|
|
2
3
|
|
|
3
|
-
.checkbox {
|
|
4
|
-
display: flex;
|
|
4
|
+
.form-field-checkbox {
|
|
5
|
+
display: inline-flex;
|
|
5
6
|
align-items: center;
|
|
7
|
+
justify-content: flex-start;
|
|
6
8
|
color: $primary;
|
|
7
|
-
cursor: pointer;
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
font-size: 14px;
|
|
10
|
+
input[type='checkbox'] {
|
|
11
|
+
@include radioCheckField;
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
flex: 0 0 18px;
|
|
14
|
+
width: 18px;
|
|
15
|
+
height: 18px;
|
|
16
|
+
border-radius: 4px;
|
|
17
|
+
transition: background 0.2s ease-in-out;
|
|
18
|
+
|
|
19
|
+
&::before {
|
|
20
|
+
content: '';
|
|
21
|
+
display: block;
|
|
22
|
+
position: absolute;
|
|
23
|
+
top: 1px;
|
|
24
|
+
left: 5px;
|
|
25
|
+
width: 6px;
|
|
26
|
+
height: 11px;
|
|
27
|
+
border-style: solid;
|
|
28
|
+
border-color: $white;
|
|
29
|
+
border-width: 0 2px 2px 0;
|
|
30
|
+
transform: rotate(45deg);
|
|
15
31
|
}
|
|
16
|
-
}
|
|
17
32
|
|
|
18
|
-
|
|
19
|
-
|
|
33
|
+
&:checked {
|
|
34
|
+
background: currentColor;
|
|
35
|
+
|
|
36
|
+
&:hover {
|
|
37
|
+
background: currentColor;
|
|
20
38
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
39
|
+
&:disabled {
|
|
40
|
+
background: currentColor;
|
|
41
|
+
}
|
|
24
42
|
}
|
|
25
43
|
}
|
|
26
44
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
&:disabled {
|
|
46
|
+
&:hover {
|
|
47
|
+
background: $white;
|
|
30
48
|
}
|
|
31
49
|
}
|
|
32
50
|
}
|
|
@@ -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;
|