iguazio.dashboard-react-controls 0.0.7 → 0.0.10

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.
@@ -25,7 +25,7 @@ require("./Button.scss");
25
25
 
26
26
  var _jsxRuntime = require("react/jsx-runtime");
27
27
 
28
- var _excluded = ["className", "icon", "label", "tooltip", "variant"];
28
+ var _excluded = ["className", "density", "icon", "label", "tooltip", "variant"];
29
29
 
30
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
31
 
@@ -45,13 +45,14 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
45
45
 
46
46
  var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
47
47
  var className = _ref.className,
48
+ density = _ref.density,
48
49
  icon = _ref.icon,
49
50
  label = _ref.label,
50
51
  tooltip = _ref.tooltip,
51
52
  variant = _ref.variant,
52
53
  restProps = _objectWithoutProperties(_ref, _excluded);
53
54
 
54
- var buttonClassName = (0, _classnames.default)('btn', "btn-".concat(variant), className);
55
+ var buttonClassName = (0, _classnames.default)('btn', "btn-".concat(variant), "btn-".concat(density), className);
55
56
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
56
57
  template: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextTooltipTemplate.default, {
57
58
  text: tooltip
@@ -68,12 +69,14 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
68
69
  });
69
70
  Button.defaultProps = {
70
71
  className: '',
72
+ density: 'normal',
71
73
  label: 'Button',
72
74
  tooltip: '',
73
75
  variant: _constants.TERTIARY_BUTTON
74
76
  };
75
77
  Button.propTypes = {
76
78
  className: _propTypes.default.string,
79
+ density: _propTypes.default.oneOf(['dense', 'normal', 'medium', 'chunky']),
77
80
  icon: _propTypes.default.element,
78
81
  label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.element]),
79
82
  tooltip: _propTypes.default.string,
@@ -7,16 +7,31 @@
7
7
  align-items: center;
8
8
  justify-content: center;
9
9
  min-width: 90px;
10
- height: 36px;
10
+ height: $fieldNormal;
11
11
  padding: 0 16px;
12
12
  color: $white;
13
13
  font-weight: 500;
14
14
  font-size: 0.875rem;
15
15
  font-style: normal;
16
- line-height: 16px;
17
16
  border: $transparentBorder;
18
17
  border-radius: $mainBorderRadius;
19
18
 
19
+ &-dense {
20
+ height: $fieldDense;
21
+ }
22
+
23
+ &-normal {
24
+ height: $fieldNormal;
25
+ }
26
+
27
+ &-medium {
28
+ height: $fieldMedium;
29
+ }
30
+
31
+ &-chunky {
32
+ height: $fieldChunky;
33
+ }
34
+
20
35
  svg {
21
36
  & > * {
22
37
  fill: currentColor;
@@ -27,7 +27,7 @@ var _Tooltip = _interopRequireDefault(require("../Tooltip/Tooltip"));
27
27
 
28
28
  var _ValidationTemplate = _interopRequireDefault(require("../../elements/ValidationTemplate/ValidationTemplate"));
29
29
 
30
- var _validationService = require("../../utils/validationService");
30
+ var _validation = require("../../utils/validation.util");
31
31
 
32
32
  var _useDetectOutsideClick = require("../../hooks/useDetectOutsideClick");
33
33
 
@@ -92,7 +92,7 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
92
92
  required = _ref.required,
93
93
  suggestionList = _ref.suggestionList,
94
94
  tip = _ref.tip,
95
- validationRules = _ref.validationRules,
95
+ rules = _ref.validationRules,
96
96
  validator = _ref.validator,
97
97
  withoutBorder = _ref.withoutBorder,
98
98
  inputProps = _objectWithoutProperties(_ref, _excluded);
@@ -120,10 +120,15 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
120
120
  _useState8 = _slicedToArray(_useState7, 1),
121
121
  validationPattern = _useState8[0];
122
122
 
123
- var _useState9 = (0, _react.useState)(false),
123
+ var _useState9 = (0, _react.useState)(rules),
124
124
  _useState10 = _slicedToArray(_useState9, 2),
125
- showValidationRules = _useState10[0],
126
- setShowValidationRules = _useState10[1];
125
+ validationRules = _useState10[0],
126
+ setValidationRules = _useState10[1];
127
+
128
+ var _useState11 = (0, _react.useState)(false),
129
+ _useState12 = _slicedToArray(_useState11, 2),
130
+ showValidationRules = _useState12[0],
131
+ setShowValidationRules = _useState12[1];
127
132
 
128
133
  var wrapperRef = (0, _react.useRef)();
129
134
  (_ref2 = ref) !== null && _ref2 !== void 0 ? _ref2 : ref = wrapperRef;
@@ -131,8 +136,8 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
131
136
  (0, _useDetectOutsideClick.useDetectOutsideClick)(ref, function () {
132
137
  return setShowValidationRules(false);
133
138
  });
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');
139
+ var formFieldClassNames = (0, _classnames.default)('form-field form-field-input', className);
140
+ var inputWrapperClassNames = (0, _classnames.default)('form-field__wrapper', "form-field__wrapper-".concat(density), disabled && 'form-field__wrapper-disabled', isInvalid && 'form-field__wrapper-invalid', withoutBorder && 'without-border');
136
141
  var labelClassNames = (0, _classnames.default)('form-field__label', disabled && 'form-field__label-disabled');
137
142
  (0, _react.useEffect)(function () {
138
143
  setTypedValue(String(input.value)); // convert from number to string
@@ -140,6 +145,11 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
140
145
  (0, _react.useEffect)(function () {
141
146
  setIsInvalid(meta.invalid && (meta.validating || meta.modified || meta.submitFailed && meta.touched));
142
147
  }, [meta.invalid, meta.modified, meta.submitFailed, meta.touched, meta.validating]);
148
+ (0, _react.useEffect)(function () {
149
+ if (meta.valid && showValidationRules) {
150
+ setShowValidationRules(false);
151
+ }
152
+ }, [meta.valid, showValidationRules]);
143
153
  (0, _react.useEffect)(function () {
144
154
  if (showValidationRules) {
145
155
  window.addEventListener('scroll', handleScroll, true);
@@ -155,8 +165,8 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
155
165
  }
156
166
  }, [focused]);
157
167
 
158
- var getValidationRules = function getValidationRules(rules) {
159
- return rules.map(function (_ref3) {
168
+ var getValidationRules = function getValidationRules() {
169
+ return validationRules.map(function (_ref3) {
160
170
  var _ref3$isValid = _ref3.isValid,
161
171
  isValid = _ref3$isValid === void 0 ? false : _ref3$isValid,
162
172
  label = _ref3.label,
@@ -173,7 +183,7 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
173
183
 
174
184
  input.onBlur(event);
175
185
 
176
- if (!event.relatedTarget || !((_event$relatedTarget = event.relatedTarget) !== null && _event$relatedTarget !== void 0 && _event$relatedTarget.closest('.suggestion-list'))) {
186
+ if (!event.relatedTarget || !((_event$relatedTarget = event.relatedTarget) !== null && _event$relatedTarget !== void 0 && _event$relatedTarget.closest('.form-field__suggestion-list'))) {
177
187
  setIsFocused(false);
178
188
  onBlur && onBlur(event);
179
189
  }
@@ -190,6 +200,8 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
190
200
  };
191
201
 
192
202
  var handleScroll = function handleScroll(event) {
203
+ if (inputRef.current.contains(event.target)) return;
204
+
193
205
  if (!event.target.closest('.options-menu') && !event.target.classList.contains('form-field')) {
194
206
  setShowValidationRules(false);
195
207
  }
@@ -206,26 +218,43 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
206
218
  setShowValidationRules(!showValidationRules);
207
219
  };
208
220
 
221
+ (0, _react.useEffect)(function () {
222
+ setValidationRules(function (prevState) {
223
+ return prevState.map(function (rule) {
224
+ return _objectSpread(_objectSpread({}, rule), {}, {
225
+ isValid: !meta.error || !Array.isArray(meta.error) ? true : !meta.error.some(function (err) {
226
+ return err.name === rule.name;
227
+ })
228
+ });
229
+ });
230
+ });
231
+ }, [meta.error]);
232
+
209
233
  var validateField = function validateField(value) {
210
234
  var valueToValidate = value !== null && value !== void 0 ? value : '';
211
235
  var validationError = null;
212
236
 
213
237
  if (!(0, _lodash.isEmpty)(validationRules)) {
214
- var _checkPatternsValidit = (0, _validationService.checkPatternsValidity)(validationRules, valueToValidate),
238
+ var _checkPatternsValidit = (0, _validation.checkPatternsValidity)(rules, valueToValidate),
215
239
  _checkPatternsValidit2 = _slicedToArray(_checkPatternsValidit, 2),
216
240
  newRules = _checkPatternsValidit2[0],
217
241
  isValidField = _checkPatternsValidit2[1];
218
242
 
219
- if (!isValidField) {
220
- validationError = newRules;
221
- }
243
+ var invalidRules = newRules.filter(function (rule) {
244
+ return !rule.isValid;
245
+ });
222
246
 
223
- if (isValidField && showValidationRules || required && valueToValidate === '') {
224
- setShowValidationRules(false);
247
+ if (!isValidField) {
248
+ validationError = invalidRules.map(function (rule) {
249
+ return {
250
+ name: rule.name,
251
+ label: rule.label
252
+ };
253
+ });
225
254
  }
226
255
  }
227
256
 
228
- if (!validationError) {
257
+ if ((0, _lodash.isEmpty)(validationError)) {
229
258
  if (pattern && !validationPattern.test(valueToValidate)) {
230
259
  validationError = {
231
260
  name: 'pattern',
@@ -261,7 +290,7 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
261
290
  meta = _ref4.meta;
262
291
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
263
292
  ref: ref,
264
- className: "form-field",
293
+ className: formFieldClassNames,
265
294
  children: [label && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
266
295
  className: labelClassNames,
267
296
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
@@ -291,22 +320,24 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
291
320
  })
292
321
  })]
293
322
  }), /*#__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", {
323
+ className: inputWrapperClassNames,
324
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
325
+ className: "form-field__control",
326
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({
327
+ "data-testid": "input",
328
+ id: input.name,
329
+ ref: inputRef,
330
+ required: isInvalid || required
331
+ }, _objectSpread(_objectSpread({
332
+ disabled: disabled,
333
+ pattern: pattern
334
+ }, inputProps), input)), {}, {
335
+ autoComplete: (_inputProps$autocompl = inputProps.autocomplete) !== null && _inputProps$autocompl !== void 0 ? _inputProps$autocompl : 'off',
336
+ onChange: handleInputChange,
337
+ onBlur: handleInputBlur,
338
+ onFocus: handleInputFocus
339
+ }))
340
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
310
341
  className: "form-field__icons",
311
342
  children: [isInvalid && !Array.isArray(meta.error) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
312
343
  className: "form-field__warning",
@@ -315,7 +346,7 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
315
346
  warning: true
316
347
  }),
317
348
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_invalid.ReactComponent, {})
318
- }), isInvalid && Array.isArray(meta.error) && !(0, _lodash.isEmpty)(meta.error) && /*#__PURE__*/(0, _jsxRuntime.jsx)("i", {
349
+ }), isInvalid && Array.isArray(meta.error) && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
319
350
  className: "form-field__warning",
320
351
  onClick: toggleValidationRulesMenu,
321
352
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_warning.ReactComponent, {})
@@ -329,7 +360,7 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
329
360
  })]
330
361
  })]
331
362
  }), (suggestionList === null || suggestionList === void 0 ? void 0 : suggestionList.length) > 0 && isFocused && /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
332
- className: "suggestion-list",
363
+ className: "form-field__suggestion-list",
333
364
  children: suggestionList.map(function (item, index) {
334
365
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
335
366
  className: "suggestion-item",
@@ -344,10 +375,10 @@ var FormInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
344
375
  }
345
376
  }, "".concat(item).concat(index));
346
377
  })
347
- }), isInvalid && Array.isArray(meta.error) && !(0, _lodash.isEmpty)(meta.error) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_OptionsMenu.default, {
378
+ }), !(0, _lodash.isEmpty)(validationRules) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_OptionsMenu.default, {
348
379
  show: showValidationRules,
349
- parentElement: ref,
350
- children: getValidationRules(meta.error)
380
+ ref: ref,
381
+ children: getValidationRules()
351
382
  })]
352
383
  });
353
384
  }
@@ -3,167 +3,58 @@
3
3
  @import '../../scss/shadows';
4
4
  @import '../../scss/mixins';
5
5
 
6
- .form-field {
7
- position: relative;
8
- display: block;
6
+ .form-field.form-field-input {
9
7
  width: 100%;
10
8
 
11
- &__label {
12
- margin-bottom: 5px;
13
- color: $topaz;
14
- font-size: 12px;
15
- text-transform: capitalize;
16
- background-color: transparent;
9
+ .form-field {
10
+ @include formField;
17
11
 
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 {
12
+ &__label {
13
+ &-icon {
36
14
  display: inline-flex;
37
- }
38
-
39
- a {
40
- transform: translateY(-1px);
41
- }
15
+ margin-left: 3px;
42
16
 
43
- svg {
44
- width: 12px;
45
- height: 12px;
46
-
47
- path {
48
- fill: $cornflowerBlue;
17
+ & > *,
18
+ a {
19
+ display: inline-flex;
49
20
  }
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
21
 
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%);
22
+ a {
23
+ transform: translateY(-1px);
24
+ }
131
25
 
132
- & > * {
133
- display: flex;
134
- align-items: center;
135
- cursor: pointer;
26
+ svg {
27
+ width: 12px;
28
+ height: 12px;
136
29
 
137
- &:not(:first-child) {
138
- margin-left: 8px;
30
+ path {
31
+ fill: $cornflowerBlue;
32
+ }
33
+ }
139
34
  }
140
35
  }
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
36
 
159
- &:hover {
160
- background-color: $alabaster;
161
- cursor: pointer;
37
+ &__suggestion-list {
38
+ position: absolute;
39
+ top: 100%;
40
+ left: 0;
41
+ z-index: 5;
42
+ margin: 0;
43
+ padding: 7px 0;
44
+ background-color: $white;
45
+ border-radius: 4px;
46
+ box-shadow: $previewBoxShadow;
47
+
48
+ .suggestion-item {
49
+ padding: 7px 15px;
50
+ color: $mulledWine;
51
+ list-style-type: none;
52
+
53
+ &:hover {
54
+ background-color: $alabaster;
55
+ cursor: pointer;
56
+ }
162
57
  }
163
58
  }
164
59
  }
165
-
166
- &__wrapper {
167
- position: relative;
168
- }
169
60
  }