iguazio.dashboard-react-controls 0.0.6 → 0.0.7
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 +57 -0
- package/dist/components/FormCheckBox/formCheckBox.scss +33 -0
- package/dist/components/FormInput/FormInput.js +418 -0
- package/dist/components/FormInput/formInput.scss +169 -0
- package/dist/components/FormSelect/FormSelect.js +306 -0
- package/dist/components/FormSelect/FormSelect.test.js +158 -0
- package/dist/components/FormSelect/formSelect.scss +303 -0
- package/dist/components/Modal/Modal.js +9 -12
- package/dist/components/Tip/Tip.js +132 -0
- package/dist/components/Tip/Tip.test.js +96 -0
- package/dist/components/Tip/tip.scss +89 -0
- package/dist/components/Wizard/Wizard.js +4 -2
- package/dist/components/index.js +32 -0
- package/dist/constants.js +20 -2
- package/dist/elements/OptionsMenu/OptionsMenu.js +64 -0
- package/dist/elements/OptionsMenu/optionsMenu.scss +49 -0
- package/dist/elements/SelectOption/SelectOption.js +95 -0
- package/dist/elements/SelectOption/SelectOption.test.js +99 -0
- package/dist/elements/SelectOption/selectOption.scss +61 -0
- package/dist/elements/ValidationTemplate/ValidationTemplate.js +48 -0
- package/dist/elements/ValidationTemplate/ValidationTemplate.scss +36 -0
- package/dist/hooks/useDetectOutsideClick.js +34 -0
- package/dist/index.js +5 -1
- package/dist/scss/mixins.scss +6 -23
- package/dist/types.js +34 -2
- package/dist/utils/validationService.js +269 -0
- package/package.json +6 -6
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _checkboxUnchecked = require("../../images/checkbox-unchecked.svg");
|
|
13
|
+
|
|
14
|
+
var _checkboxChecked = require("../../images/checkbox-checked.svg");
|
|
15
|
+
|
|
16
|
+
require("./formCheckBox.scss");
|
|
17
|
+
|
|
18
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
var FormCheckBox = function FormCheckBox(_ref) {
|
|
23
|
+
var children = _ref.children,
|
|
24
|
+
className = _ref.className,
|
|
25
|
+
item = _ref.item,
|
|
26
|
+
onChange = _ref.onChange,
|
|
27
|
+
selectedId = _ref.selectedId;
|
|
28
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
29
|
+
className: "checkbox ".concat(className),
|
|
30
|
+
onClick: function onClick() {
|
|
31
|
+
onChange(item.id);
|
|
32
|
+
},
|
|
33
|
+
children: [item.id === selectedId ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_checkboxChecked.ReactComponent, {
|
|
34
|
+
className: "checked"
|
|
35
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_checkboxUnchecked.ReactComponent, {
|
|
36
|
+
className: "unchecked"
|
|
37
|
+
}), children || item.label]
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
FormCheckBox.defaultProps = {
|
|
42
|
+
className: '',
|
|
43
|
+
selectedId: ''
|
|
44
|
+
};
|
|
45
|
+
FormCheckBox.propTypes = {
|
|
46
|
+
className: _propTypes.default.string,
|
|
47
|
+
item: _propTypes.default.shape({
|
|
48
|
+
id: _propTypes.default.string.isRequired,
|
|
49
|
+
label: _propTypes.default.string
|
|
50
|
+
}).isRequired,
|
|
51
|
+
onChange: _propTypes.default.func.isRequired,
|
|
52
|
+
selectedId: _propTypes.default.string
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
var _default = /*#__PURE__*/_react.default.memo(FormCheckBox);
|
|
56
|
+
|
|
57
|
+
exports.default = _default;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
@import '../../scss/colors';
|
|
2
|
+
|
|
3
|
+
.checkbox {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
color: $primary;
|
|
7
|
+
cursor: pointer;
|
|
8
|
+
|
|
9
|
+
&__label {
|
|
10
|
+
flex: 1;
|
|
11
|
+
font-size: 14px;
|
|
12
|
+
|
|
13
|
+
&-tip {
|
|
14
|
+
margin-left: 5px;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
svg {
|
|
19
|
+
margin-right: 5px;
|
|
20
|
+
|
|
21
|
+
&.checked {
|
|
22
|
+
path {
|
|
23
|
+
fill: $malibu;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&.unchecked {
|
|
28
|
+
path {
|
|
29
|
+
fill: $spunPearl;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,418 @@
|
|
|
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 _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
+
|
|
14
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
|
+
|
|
16
|
+
var _lodash = require("lodash");
|
|
17
|
+
|
|
18
|
+
var _reactFinalForm = require("react-final-form");
|
|
19
|
+
|
|
20
|
+
var _OptionsMenu = _interopRequireDefault(require("../../elements/OptionsMenu/OptionsMenu"));
|
|
21
|
+
|
|
22
|
+
var _TextTooltipTemplate = _interopRequireDefault(require("../TooltipTemplate/TextTooltipTemplate"));
|
|
23
|
+
|
|
24
|
+
var _Tip = _interopRequireDefault(require("../Tip/Tip"));
|
|
25
|
+
|
|
26
|
+
var _Tooltip = _interopRequireDefault(require("../Tooltip/Tooltip"));
|
|
27
|
+
|
|
28
|
+
var _ValidationTemplate = _interopRequireDefault(require("../../elements/ValidationTemplate/ValidationTemplate"));
|
|
29
|
+
|
|
30
|
+
var _validationService = require("../../utils/validationService");
|
|
31
|
+
|
|
32
|
+
var _useDetectOutsideClick = require("../../hooks/useDetectOutsideClick");
|
|
33
|
+
|
|
34
|
+
var _types = require("../../types");
|
|
35
|
+
|
|
36
|
+
var _invalid = require("../../images/invalid.svg");
|
|
37
|
+
|
|
38
|
+
var _popout = require("../../images/popout.svg");
|
|
39
|
+
|
|
40
|
+
var _warning = require("../../images/warning.svg");
|
|
41
|
+
|
|
42
|
+
require("./formInput.scss");
|
|
43
|
+
|
|
44
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
45
|
+
|
|
46
|
+
var _excluded = ["className", "density", "disabled", "focused", "iconClass", "inputIcon", "invalidText", "label", "link", "name", "onBlur", "onChange", "pattern", "required", "suggestionList", "tip", "validationRules", "validator", "withoutBorder"];
|
|
47
|
+
|
|
48
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
|
+
|
|
50
|
+
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); }
|
|
51
|
+
|
|
52
|
+
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; }
|
|
53
|
+
|
|
54
|
+
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; }
|
|
55
|
+
|
|
56
|
+
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; }
|
|
57
|
+
|
|
58
|
+
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; }
|
|
59
|
+
|
|
60
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
61
|
+
|
|
62
|
+
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."); }
|
|
63
|
+
|
|
64
|
+
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); }
|
|
65
|
+
|
|
66
|
+
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; }
|
|
67
|
+
|
|
68
|
+
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; }
|
|
69
|
+
|
|
70
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
71
|
+
|
|
72
|
+
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; }
|
|
73
|
+
|
|
74
|
+
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; }
|
|
75
|
+
|
|
76
|
+
var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
77
|
+
var _ref2;
|
|
78
|
+
|
|
79
|
+
var className = _ref.className,
|
|
80
|
+
density = _ref.density,
|
|
81
|
+
disabled = _ref.disabled,
|
|
82
|
+
focused = _ref.focused,
|
|
83
|
+
iconClass = _ref.iconClass,
|
|
84
|
+
inputIcon = _ref.inputIcon,
|
|
85
|
+
invalidText = _ref.invalidText,
|
|
86
|
+
label = _ref.label,
|
|
87
|
+
link = _ref.link,
|
|
88
|
+
name = _ref.name,
|
|
89
|
+
onBlur = _ref.onBlur,
|
|
90
|
+
onChange = _ref.onChange,
|
|
91
|
+
pattern = _ref.pattern,
|
|
92
|
+
required = _ref.required,
|
|
93
|
+
suggestionList = _ref.suggestionList,
|
|
94
|
+
tip = _ref.tip,
|
|
95
|
+
validationRules = _ref.validationRules,
|
|
96
|
+
validator = _ref.validator,
|
|
97
|
+
withoutBorder = _ref.withoutBorder,
|
|
98
|
+
inputProps = _objectWithoutProperties(_ref, _excluded);
|
|
99
|
+
|
|
100
|
+
var _useField = (0, _reactFinalForm.useField)(name),
|
|
101
|
+
input = _useField.input,
|
|
102
|
+
meta = _useField.meta;
|
|
103
|
+
|
|
104
|
+
var _useState = (0, _react.useState)(false),
|
|
105
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
106
|
+
isInvalid = _useState2[0],
|
|
107
|
+
setIsInvalid = _useState2[1];
|
|
108
|
+
|
|
109
|
+
var _useState3 = (0, _react.useState)(false),
|
|
110
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
111
|
+
isFocused = _useState4[0],
|
|
112
|
+
setIsFocused = _useState4[1];
|
|
113
|
+
|
|
114
|
+
var _useState5 = (0, _react.useState)(''),
|
|
115
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
116
|
+
typedValue = _useState6[0],
|
|
117
|
+
setTypedValue = _useState6[1];
|
|
118
|
+
|
|
119
|
+
var _useState7 = (0, _react.useState)(RegExp(pattern)),
|
|
120
|
+
_useState8 = _slicedToArray(_useState7, 1),
|
|
121
|
+
validationPattern = _useState8[0];
|
|
122
|
+
|
|
123
|
+
var _useState9 = (0, _react.useState)(false),
|
|
124
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
125
|
+
showValidationRules = _useState10[0],
|
|
126
|
+
setShowValidationRules = _useState10[1];
|
|
127
|
+
|
|
128
|
+
var wrapperRef = (0, _react.useRef)();
|
|
129
|
+
(_ref2 = ref) !== null && _ref2 !== void 0 ? _ref2 : ref = wrapperRef;
|
|
130
|
+
var inputRef = (0, _react.useRef)();
|
|
131
|
+
(0, _useDetectOutsideClick.useDetectOutsideClick)(ref, function () {
|
|
132
|
+
return setShowValidationRules(false);
|
|
133
|
+
});
|
|
134
|
+
var inputClassNames = (0, _classnames.default)('form-field__input', className, "form-field__input-".concat(density), isInvalid && 'form-field__input-invalid', // isInvalid && 'input_rules-invalid',
|
|
135
|
+
withoutBorder && 'without-border');
|
|
136
|
+
var labelClassNames = (0, _classnames.default)('form-field__label', disabled && 'form-field__label-disabled');
|
|
137
|
+
(0, _react.useEffect)(function () {
|
|
138
|
+
setTypedValue(String(input.value)); // convert from number to string
|
|
139
|
+
}, [input.value]);
|
|
140
|
+
(0, _react.useEffect)(function () {
|
|
141
|
+
setIsInvalid(meta.invalid && (meta.validating || meta.modified || meta.submitFailed && meta.touched));
|
|
142
|
+
}, [meta.invalid, meta.modified, meta.submitFailed, meta.touched, meta.validating]);
|
|
143
|
+
(0, _react.useEffect)(function () {
|
|
144
|
+
if (showValidationRules) {
|
|
145
|
+
window.addEventListener('scroll', handleScroll, true);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return function () {
|
|
149
|
+
window.removeEventListener('scroll', handleScroll, true);
|
|
150
|
+
};
|
|
151
|
+
}, [showValidationRules]);
|
|
152
|
+
(0, _react.useEffect)(function () {
|
|
153
|
+
if (focused) {
|
|
154
|
+
inputRef.current.focus();
|
|
155
|
+
}
|
|
156
|
+
}, [focused]);
|
|
157
|
+
|
|
158
|
+
var getValidationRules = function getValidationRules(rules) {
|
|
159
|
+
return rules.map(function (_ref3) {
|
|
160
|
+
var _ref3$isValid = _ref3.isValid,
|
|
161
|
+
isValid = _ref3$isValid === void 0 ? false : _ref3$isValid,
|
|
162
|
+
label = _ref3.label,
|
|
163
|
+
name = _ref3.name;
|
|
164
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ValidationTemplate.default, {
|
|
165
|
+
valid: isValid,
|
|
166
|
+
validationMessage: label
|
|
167
|
+
}, name);
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
var handleInputBlur = function handleInputBlur(event) {
|
|
172
|
+
var _event$relatedTarget;
|
|
173
|
+
|
|
174
|
+
input.onBlur(event);
|
|
175
|
+
|
|
176
|
+
if (!event.relatedTarget || !((_event$relatedTarget = event.relatedTarget) !== null && _event$relatedTarget !== void 0 && _event$relatedTarget.closest('.suggestion-list'))) {
|
|
177
|
+
setIsFocused(false);
|
|
178
|
+
onBlur && onBlur(event);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
var handleInputChange = function handleInputChange(event) {
|
|
183
|
+
input.onChange(event);
|
|
184
|
+
onChange && onChange(event.target.value);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
var handleInputFocus = function handleInputFocus(event) {
|
|
188
|
+
input.onFocus(event);
|
|
189
|
+
setIsFocused(true);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
var handleScroll = function handleScroll(event) {
|
|
193
|
+
if (!event.target.closest('.options-menu') && !event.target.classList.contains('form-field')) {
|
|
194
|
+
setShowValidationRules(false);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
var handleSuggestionClick = function handleSuggestionClick(item) {
|
|
199
|
+
input.onChange && input.onChange(item);
|
|
200
|
+
setIsFocused(false);
|
|
201
|
+
onBlur();
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
var toggleValidationRulesMenu = function toggleValidationRulesMenu() {
|
|
205
|
+
inputRef.current.focus();
|
|
206
|
+
setShowValidationRules(!showValidationRules);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
var validateField = function validateField(value) {
|
|
210
|
+
var valueToValidate = value !== null && value !== void 0 ? value : '';
|
|
211
|
+
var validationError = null;
|
|
212
|
+
|
|
213
|
+
if (!(0, _lodash.isEmpty)(validationRules)) {
|
|
214
|
+
var _checkPatternsValidit = (0, _validationService.checkPatternsValidity)(validationRules, valueToValidate),
|
|
215
|
+
_checkPatternsValidit2 = _slicedToArray(_checkPatternsValidit, 2),
|
|
216
|
+
newRules = _checkPatternsValidit2[0],
|
|
217
|
+
isValidField = _checkPatternsValidit2[1];
|
|
218
|
+
|
|
219
|
+
if (!isValidField) {
|
|
220
|
+
validationError = newRules;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (isValidField && showValidationRules || required && valueToValidate === '') {
|
|
224
|
+
setShowValidationRules(false);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!validationError) {
|
|
229
|
+
if (pattern && !validationPattern.test(valueToValidate)) {
|
|
230
|
+
validationError = {
|
|
231
|
+
name: 'pattern',
|
|
232
|
+
label: invalidText
|
|
233
|
+
};
|
|
234
|
+
} else if (valueToValidate.startsWith(' ')) {
|
|
235
|
+
validationError = {
|
|
236
|
+
name: 'empty',
|
|
237
|
+
label: invalidText
|
|
238
|
+
};
|
|
239
|
+
} else if (required && valueToValidate.trim().length === 0) {
|
|
240
|
+
validationError = {
|
|
241
|
+
name: 'required',
|
|
242
|
+
label: 'This field is required'
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (!validationError && validator) {
|
|
248
|
+
validationError = validator(value);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return validationError;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
|
|
255
|
+
validate: validateField,
|
|
256
|
+
name: name,
|
|
257
|
+
children: function children(_ref4) {
|
|
258
|
+
var _inputProps$autocompl, _meta$error$label, _meta$error;
|
|
259
|
+
|
|
260
|
+
var input = _ref4.input,
|
|
261
|
+
meta = _ref4.meta;
|
|
262
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
263
|
+
ref: ref,
|
|
264
|
+
className: "form-field",
|
|
265
|
+
children: [label && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
266
|
+
className: labelClassNames,
|
|
267
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
268
|
+
"data-testid": "label",
|
|
269
|
+
htmlFor: input.name,
|
|
270
|
+
children: [label, (required || validationRules.find(function (rule) {
|
|
271
|
+
return rule.name === 'required';
|
|
272
|
+
})) && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
273
|
+
className: "form-field__label-mandatory",
|
|
274
|
+
children: " *"
|
|
275
|
+
})]
|
|
276
|
+
}), link && link.show && typedValue.trim() && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
277
|
+
className: "form-field__label-icon",
|
|
278
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
279
|
+
template: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextTooltipTemplate.default, {
|
|
280
|
+
text: link.url || typedValue
|
|
281
|
+
}),
|
|
282
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
|
|
283
|
+
href: link.url || typedValue,
|
|
284
|
+
onClick: function onClick(event) {
|
|
285
|
+
return event.stopPropagation();
|
|
286
|
+
},
|
|
287
|
+
target: "_blank",
|
|
288
|
+
rel: "noreferrer",
|
|
289
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_popout.ReactComponent, {})
|
|
290
|
+
})
|
|
291
|
+
})
|
|
292
|
+
})]
|
|
293
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
294
|
+
className: "form-field__wrapper",
|
|
295
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({
|
|
296
|
+
"data-testid": "input",
|
|
297
|
+
id: input.name,
|
|
298
|
+
className: inputClassNames,
|
|
299
|
+
ref: inputRef,
|
|
300
|
+
required: isInvalid
|
|
301
|
+
}, _objectSpread(_objectSpread({
|
|
302
|
+
disabled: disabled,
|
|
303
|
+
pattern: pattern
|
|
304
|
+
}, inputProps), input)), {}, {
|
|
305
|
+
autoComplete: (_inputProps$autocompl = inputProps.autocomplete) !== null && _inputProps$autocompl !== void 0 ? _inputProps$autocompl : 'off',
|
|
306
|
+
onChange: handleInputChange,
|
|
307
|
+
onBlur: handleInputBlur,
|
|
308
|
+
onFocus: handleInputFocus
|
|
309
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
310
|
+
className: "form-field__icons",
|
|
311
|
+
children: [isInvalid && !Array.isArray(meta.error) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
312
|
+
className: "form-field__warning",
|
|
313
|
+
template: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextTooltipTemplate.default, {
|
|
314
|
+
text: (_meta$error$label = (_meta$error = meta.error) === null || _meta$error === void 0 ? void 0 : _meta$error.label) !== null && _meta$error$label !== void 0 ? _meta$error$label : invalidText,
|
|
315
|
+
warning: true
|
|
316
|
+
}),
|
|
317
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_invalid.ReactComponent, {})
|
|
318
|
+
}), isInvalid && Array.isArray(meta.error) && !(0, _lodash.isEmpty)(meta.error) && /*#__PURE__*/(0, _jsxRuntime.jsx)("i", {
|
|
319
|
+
className: "form-field__warning",
|
|
320
|
+
onClick: toggleValidationRulesMenu,
|
|
321
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_warning.ReactComponent, {})
|
|
322
|
+
}), tip && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tip.default, {
|
|
323
|
+
text: tip,
|
|
324
|
+
className: "form-field__tip"
|
|
325
|
+
}), inputIcon && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
326
|
+
"data-testid": "input-icon",
|
|
327
|
+
className: iconClass,
|
|
328
|
+
children: inputIcon
|
|
329
|
+
})]
|
|
330
|
+
})]
|
|
331
|
+
}), (suggestionList === null || suggestionList === void 0 ? void 0 : suggestionList.length) > 0 && isFocused && /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
|
|
332
|
+
className: "suggestion-list",
|
|
333
|
+
children: suggestionList.map(function (item, index) {
|
|
334
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
335
|
+
className: "suggestion-item",
|
|
336
|
+
onClick: function onClick() {
|
|
337
|
+
handleSuggestionClick(item);
|
|
338
|
+
},
|
|
339
|
+
tabIndex: index,
|
|
340
|
+
dangerouslySetInnerHTML: {
|
|
341
|
+
__html: item.replace(new RegExp(typedValue, 'gi'), function (match) {
|
|
342
|
+
return match ? "<b>".concat(match, "</b>") : match;
|
|
343
|
+
})
|
|
344
|
+
}
|
|
345
|
+
}, "".concat(item).concat(index));
|
|
346
|
+
})
|
|
347
|
+
}), isInvalid && Array.isArray(meta.error) && !(0, _lodash.isEmpty)(meta.error) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_OptionsMenu.default, {
|
|
348
|
+
show: showValidationRules,
|
|
349
|
+
parentElement: ref,
|
|
350
|
+
children: getValidationRules(meta.error)
|
|
351
|
+
})]
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
FormInput.defaultProps = {
|
|
358
|
+
className: '',
|
|
359
|
+
density: 'normal',
|
|
360
|
+
disabled: false,
|
|
361
|
+
focused: false,
|
|
362
|
+
iconClass: '',
|
|
363
|
+
inputIcon: null,
|
|
364
|
+
invalidText: 'This field is invalid',
|
|
365
|
+
label: '',
|
|
366
|
+
link: {
|
|
367
|
+
show: '',
|
|
368
|
+
value: ''
|
|
369
|
+
},
|
|
370
|
+
maxLength: null,
|
|
371
|
+
min: null,
|
|
372
|
+
onBlur: function onBlur() {},
|
|
373
|
+
onChange: function onChange() {},
|
|
374
|
+
onKeyDown: function onKeyDown() {},
|
|
375
|
+
pattern: null,
|
|
376
|
+
placeholder: '',
|
|
377
|
+
required: false,
|
|
378
|
+
step: '',
|
|
379
|
+
suggestionList: [],
|
|
380
|
+
tip: '',
|
|
381
|
+
type: 'text',
|
|
382
|
+
validationRules: [],
|
|
383
|
+
validator: function validator() {},
|
|
384
|
+
value: '',
|
|
385
|
+
withoutBorder: false
|
|
386
|
+
};
|
|
387
|
+
FormInput.propTypes = {
|
|
388
|
+
className: _propTypes.default.string,
|
|
389
|
+
density: _propTypes.default.oneOf(['dense', 'normal', 'medium', 'chunky']),
|
|
390
|
+
disabled: _propTypes.default.bool,
|
|
391
|
+
focused: _propTypes.default.bool,
|
|
392
|
+
iconClass: _propTypes.default.string,
|
|
393
|
+
inputIcon: _propTypes.default.element,
|
|
394
|
+
invalidText: _propTypes.default.string,
|
|
395
|
+
label: _propTypes.default.string,
|
|
396
|
+
link: _types.INPUT_LINK,
|
|
397
|
+
maxLength: _propTypes.default.number,
|
|
398
|
+
min: _propTypes.default.number,
|
|
399
|
+
name: _propTypes.default.string.isRequired,
|
|
400
|
+
onBlur: _propTypes.default.func,
|
|
401
|
+
onChange: _propTypes.default.func,
|
|
402
|
+
onKeyDown: _propTypes.default.func,
|
|
403
|
+
pattern: _propTypes.default.string,
|
|
404
|
+
placeholder: _propTypes.default.string,
|
|
405
|
+
required: _propTypes.default.bool,
|
|
406
|
+
step: _propTypes.default.string,
|
|
407
|
+
suggestionList: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
408
|
+
tip: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.element]),
|
|
409
|
+
type: _propTypes.default.string,
|
|
410
|
+
validationRules: _types.INPUT_VALIDATION_RULES,
|
|
411
|
+
validator: _propTypes.default.func,
|
|
412
|
+
value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
413
|
+
withoutBorder: _propTypes.default.bool
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
var _default = /*#__PURE__*/_react.default.memo(FormInput);
|
|
417
|
+
|
|
418
|
+
exports.default = _default;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
@import '../../scss/colors';
|
|
2
|
+
@import '../../scss/borders';
|
|
3
|
+
@import '../../scss/shadows';
|
|
4
|
+
@import '../../scss/mixins';
|
|
5
|
+
|
|
6
|
+
.form-field {
|
|
7
|
+
position: relative;
|
|
8
|
+
display: block;
|
|
9
|
+
width: 100%;
|
|
10
|
+
|
|
11
|
+
&__label {
|
|
12
|
+
margin-bottom: 5px;
|
|
13
|
+
color: $topaz;
|
|
14
|
+
font-size: 12px;
|
|
15
|
+
text-transform: capitalize;
|
|
16
|
+
background-color: transparent;
|
|
17
|
+
|
|
18
|
+
&-mandatory {
|
|
19
|
+
color: $amaranth;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&-disabled {
|
|
23
|
+
color: $spunPearl;
|
|
24
|
+
|
|
25
|
+
.form-field__label-mandatory {
|
|
26
|
+
color: $spunPearl;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&-icon {
|
|
31
|
+
display: inline-flex;
|
|
32
|
+
margin-left: 3px;
|
|
33
|
+
|
|
34
|
+
& > *,
|
|
35
|
+
a {
|
|
36
|
+
display: inline-flex;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
a {
|
|
40
|
+
transform: translateY(-1px);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
svg {
|
|
44
|
+
width: 12px;
|
|
45
|
+
height: 12px;
|
|
46
|
+
|
|
47
|
+
path {
|
|
48
|
+
fill: $cornflowerBlue;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&__input {
|
|
55
|
+
padding-left: 16px;
|
|
56
|
+
padding-right: 30px;
|
|
57
|
+
|
|
58
|
+
@include fieldWrapper;
|
|
59
|
+
|
|
60
|
+
&::placeholder {
|
|
61
|
+
color: $spunPearl;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
&::-webkit-input-placeholder {
|
|
65
|
+
/* Chrome/Opera/Safari */
|
|
66
|
+
color: $spunPearl;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&::-moz-placeholder {
|
|
70
|
+
/* Firefox 19+ */
|
|
71
|
+
color: $spunPearl;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&:-ms-input-placeholder {
|
|
75
|
+
/* IE 10+ */
|
|
76
|
+
color: $spunPearl;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&:-moz-placeholder {
|
|
80
|
+
/* Firefox 18- */
|
|
81
|
+
color: $spunPearl;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
&-invalid {
|
|
85
|
+
border: $errorBorder;
|
|
86
|
+
padding-right: 50px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
&.without-border {
|
|
90
|
+
border-color: transparent;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
&:read-only:not(:disabled) {
|
|
94
|
+
border-color: transparent;
|
|
95
|
+
padding: 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
&:disabled {
|
|
99
|
+
color: $spunPearl;
|
|
100
|
+
cursor: not-allowed;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
&-dense {
|
|
104
|
+
padding-top: 12px;
|
|
105
|
+
padding-bottom: 12px;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
&-normal {
|
|
109
|
+
padding-top: 14px;
|
|
110
|
+
padding-bottom: 14px;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
&-medium {
|
|
114
|
+
padding-top: 16px;
|
|
115
|
+
padding-bottom: 16px;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
&-chunky {
|
|
119
|
+
padding-top: 18px;
|
|
120
|
+
padding-bottom: 18px;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
&__icons {
|
|
125
|
+
display: flex;
|
|
126
|
+
align-items: center;
|
|
127
|
+
position: absolute;
|
|
128
|
+
top: 50%;
|
|
129
|
+
right: 10px;
|
|
130
|
+
transform: translateY(-50%);
|
|
131
|
+
|
|
132
|
+
& > * {
|
|
133
|
+
display: flex;
|
|
134
|
+
align-items: center;
|
|
135
|
+
cursor: pointer;
|
|
136
|
+
|
|
137
|
+
&:not(:first-child) {
|
|
138
|
+
margin-left: 8px;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.suggestion-list {
|
|
144
|
+
position: absolute;
|
|
145
|
+
top: 100%;
|
|
146
|
+
left: 0;
|
|
147
|
+
z-index: 5;
|
|
148
|
+
margin: 0;
|
|
149
|
+
padding: 7px 0;
|
|
150
|
+
background-color: $white;
|
|
151
|
+
border-radius: 4px;
|
|
152
|
+
box-shadow: $previewBoxShadow;
|
|
153
|
+
|
|
154
|
+
.suggestion-item {
|
|
155
|
+
padding: 7px 15px;
|
|
156
|
+
color: $mulledWine;
|
|
157
|
+
list-style-type: none;
|
|
158
|
+
|
|
159
|
+
&:hover {
|
|
160
|
+
background-color: $alabaster;
|
|
161
|
+
cursor: pointer;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
&__wrapper {
|
|
167
|
+
position: relative;
|
|
168
|
+
}
|
|
169
|
+
}
|