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.
@@ -41,6 +41,12 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
41
41
 
42
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
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
+
44
50
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
45
51
 
46
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."); }
@@ -71,33 +77,64 @@ var FormSelect = function FormSelect(_ref) {
71
77
  withSelectedIcon = _ref.withSelectedIcon;
72
78
 
73
79
  var _useField = (0, _reactFinalForm.useField)(name),
74
- input = _useField.input;
75
-
76
- var selectRef = (0, _react.useRef)();
80
+ input = _useField.input,
81
+ meta = _useField.meta;
77
82
 
78
83
  var _useState = (0, _react.useState)(false),
79
84
  _useState2 = _slicedToArray(_useState, 2),
80
- isConfirmDialogOpen = _useState2[0],
81
- setConfirmDialogOpen = _useState2[1];
85
+ isInvalid = _useState2[0],
86
+ setIsInvalid = _useState2[1];
82
87
 
83
88
  var _useState3 = (0, _react.useState)(false),
84
89
  _useState4 = _slicedToArray(_useState3, 2),
85
- isOpen = _useState4[0],
86
- setOpen = _useState4[1];
90
+ isConfirmDialogOpen = _useState4[0],
91
+ setConfirmDialogOpen = _useState4[1];
87
92
 
88
- var _useState5 = (0, _react.useState)(''),
93
+ var _useState5 = (0, _react.useState)(false),
89
94
  _useState6 = _slicedToArray(_useState5, 2),
90
- searchValue = _useState6[0],
91
- setSearchValue = _useState6[1];
95
+ isOpen = _useState6[0],
96
+ setOpen = _useState6[1];
97
+
98
+ var _useState7 = (0, _react.useState)(''),
99
+ _useState8 = _slicedToArray(_useState7, 2),
100
+ searchValue = _useState8[0],
101
+ setSearchValue = _useState8[1];
102
+
103
+ var selectRef = (0, _react.useRef)();
92
104
 
93
105
  var _ref2 = (selectRef === null || selectRef === void 0 ? void 0 : (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 ? void 0 : _selectRef$current.getBoundingClientRect()) || {},
94
106
  dropdownWidth = _ref2.width;
95
107
 
96
- var selectClassName = (0, _classnames.default)('form-field__select', "form-field__select-".concat(density), isOpen && 'form-field__select-active', withoutBorder && 'without-border', disabled && 'form-field__select-disabled');
108
+ var selectWrapperClassNames = (0, _classnames.default)('form-field__wrapper', "form-field__wrapper-".concat(density), disabled && 'form-field__wrapper-disabled', isOpen && 'form-field__wrapper-active', isInvalid && 'form-field__wrapper-invalid', withoutBorder && 'without-border');
97
109
  var selectLabelClassName = (0, _classnames.default)('form-field__label', disabled && 'form-field__label-disabled');
98
110
  var selectedOption = options.find(function (option) {
99
111
  return option.id === input.value;
100
112
  });
113
+ (0, _react.useEffect)(function () {
114
+ setIsInvalid(meta.invalid && (meta.validating || meta.modified || meta.submitFailed && meta.touched));
115
+ }, [meta.invalid, meta.modified, meta.submitFailed, meta.touched, meta.validating]);
116
+ var openMenu = (0, _react.useCallback)(function () {
117
+ if (!isOpen) {
118
+ setOpen(true);
119
+ input.onFocus(new Event('focus'));
120
+ }
121
+ }, [input, isOpen]);
122
+ var closeMenu = (0, _react.useCallback)(function () {
123
+ if (isOpen) {
124
+ setOpen(false);
125
+ input.onBlur(new Event('blur'));
126
+ }
127
+ }, [input, isOpen]);
128
+ var clickHandler = (0, _react.useCallback)(function (event) {
129
+ if (selectRef.current !== event.target.closest('.form-field')) {
130
+ closeMenu();
131
+ }
132
+ }, [closeMenu]);
133
+ var handleScroll = (0, _react.useCallback)(function (event) {
134
+ if (!event.target.closest('.options-list__body')) {
135
+ closeMenu();
136
+ }
137
+ }, [closeMenu]);
101
138
  (0, _react.useEffect)(function () {
102
139
  if (isOpen) {
103
140
  window.addEventListener('scroll', handleScroll, true);
@@ -108,32 +145,24 @@ var FormSelect = function FormSelect(_ref) {
108
145
  window.removeEventListener('click', clickHandler);
109
146
  window.removeEventListener('scroll', handleScroll, true);
110
147
  };
111
- }, [isOpen]);
112
-
113
- var clickHandler = function clickHandler(event) {
114
- if (selectRef.current !== event.target.closest('.form-field')) {
115
- setOpen(false);
116
- }
117
- };
118
-
119
- var handleScroll = function handleScroll(event) {
120
- if (!event.target.closest('.select__body')) {
121
- setOpen(false);
122
- }
123
- };
148
+ }, [clickHandler, handleScroll, isOpen]);
124
149
 
125
150
  var toggleOpen = function toggleOpen() {
126
- !disabled && setOpen(!isOpen);
151
+ if (isOpen) {
152
+ closeMenu();
153
+ } else {
154
+ !disabled && openMenu();
155
+ }
127
156
  };
128
157
 
129
158
  var handleCloseSelectBody = (0, _react.useCallback)(function (event) {
130
159
  event.stopPropagation();
131
160
 
132
- if (!event.target.classList.contains('disabled') && !event.target.closest('.select__search')) {
133
- setOpen(false);
161
+ if (!event.target.classList.contains('disabled') && !event.target.closest('.options-list__search')) {
162
+ closeMenu();
134
163
  setSearchValue('');
135
164
  }
136
- }, []);
165
+ }, [closeMenu]);
137
166
 
138
167
  var handleSelectOptionClick = function handleSelectOptionClick(selectedOption, option) {
139
168
  if (selectedOption !== input.value) {
@@ -149,7 +178,6 @@ var FormSelect = function FormSelect(_ref) {
149
178
 
150
179
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
151
180
  name: name,
152
- component: "select",
153
181
  validate: required,
154
182
  children: function children(_ref3) {
155
183
  var input = _ref3.input,
@@ -157,7 +185,7 @@ var FormSelect = function FormSelect(_ref) {
157
185
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
158
186
  "data-testid": "select",
159
187
  ref: selectRef,
160
- className: "form-field ".concat(className),
188
+ className: "form-field form-field-select ".concat(className),
161
189
  onClick: toggleOpen,
162
190
  children: [label && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
163
191
  className: selectLabelClassName,
@@ -170,18 +198,21 @@ var FormSelect = function FormSelect(_ref) {
170
198
  })
171
199
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
172
200
  "data-testid": "select-header",
173
- className: "form-field__wrapper",
174
- children: [!hideSelectedOption && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
175
- "data-testid": "selected-option",
176
- className: selectClassName,
177
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
178
- className: "form-field__select-value",
179
- children: input.value && (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label)
180
- }), (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.subLabel) && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
181
- "data-testid": "select-subLabel",
182
- className: "sub-label",
183
- children: selectedOption.subLabel
184
- })]
201
+ className: selectWrapperClassNames,
202
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
203
+ className: "form-field__control",
204
+ children: !hideSelectedOption && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
205
+ "data-testid": "selected-option",
206
+ className: "form-field__select",
207
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
208
+ className: "form-field__select-value",
209
+ children: input.value && (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label)
210
+ }), (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.subLabel) && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
211
+ "data-testid": "select-subLabel",
212
+ className: "form-field__select-sub_label",
213
+ children: selectedOption.subLabel
214
+ })]
215
+ })
185
216
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
186
217
  className: "form-field__icons",
187
218
  children: [input.value && selectedItemAction && /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
@@ -204,8 +235,10 @@ var FormSelect = function FormSelect(_ref) {
204
235
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
205
236
  children: selectedItemAction.icon
206
237
  })
207
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdown.ReactComponent, {
208
- className: "form-field__caret"
238
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
239
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdown.ReactComponent, {
240
+ className: "form-field__caret"
241
+ })
209
242
  })]
210
243
  })]
211
244
  }), isConfirmDialogOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfirmDialog.default, {
@@ -228,9 +261,10 @@ var FormSelect = function FormSelect(_ref) {
228
261
  variant: selectedItemAction.confirm.btnConfirmType
229
262
  },
230
263
  header: selectedItemAction.confirm.title,
264
+ isOpen: isConfirmDialogOpen,
231
265
  message: selectedItemAction.confirm.message
232
266
  }), isOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_PopUpDialog.default, {
233
- className: "select__options-list",
267
+ className: "form-field form-field-select__options-list",
234
268
  customPosition: {
235
269
  element: selectRef,
236
270
  position: 'bottom-right'
@@ -240,10 +274,10 @@ var FormSelect = function FormSelect(_ref) {
240
274
  },
241
275
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
242
276
  "data-testid": "select-body",
243
- className: "select__body",
277
+ className: "options-list__body",
244
278
  onClick: handleCloseSelectBody,
245
279
  children: [search && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
246
- className: "select__search",
280
+ className: "options-list__search",
247
281
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
248
282
  type: "text",
249
283
  placeholder: "Search...",
@@ -266,7 +300,9 @@ var FormSelect = function FormSelect(_ref) {
266
300
  }, option.id);
267
301
  })]
268
302
  })
269
- })]
303
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({}, input), {}, {
304
+ type: "hidden"
305
+ }))]
270
306
  });
271
307
  }
272
308
  });
@@ -283,7 +319,7 @@ FormSelect.defaultProps = {
283
319
  search: false,
284
320
  selectType: '',
285
321
  withoutBorder: false,
286
- withSelectedIcon: false
322
+ withSelectedIcon: true
287
323
  };
288
324
  FormSelect.propTypes = {
289
325
  className: _propTypes.default.string,
@@ -1,45 +1,33 @@
1
1
  @import '../../scss/mixins';
2
2
  @import '../../scss/colors';
3
- @import '../../scss/borders';
4
3
  @import '../../scss/shadows';
5
4
 
6
- .form-field {
7
- position: relative;
8
- display: block;
5
+ .form-field.form-field-select {
9
6
  width: 100%;
10
7
 
11
- &__label {
12
- margin-bottom: 5px;
13
- color: $topaz;
14
- font-size: 12px;
15
- text-transform: capitalize;
16
- background-color: transparent;
8
+ .form-field {
9
+ @include formField;
17
10
 
18
- &-disabled {
19
- color: $spunPearl;
20
- }
21
- }
22
-
23
- &__select {
24
- padding-left: 16px;
25
- padding-right: 30px;
26
- cursor: pointer;
27
-
28
- @include fieldWrapper;
11
+ &__wrapper {
12
+ &-active {
13
+ background: $alabaster;
14
+ }
29
15
 
30
- &-active:not(.without-border) {
31
- background: $alabaster;
32
- }
16
+ .form-field__caret {
17
+ cursor: pointer;
18
+ }
33
19
 
34
- &-disabled {
35
- color: $spunPearl;
36
- cursor: not-allowed;
37
- }
20
+ &-disabled {
21
+ .form-field__caret {
22
+ cursor: not-allowed;
38
23
 
39
- &.without {
40
- &-border {
41
- border-color: transparent;
24
+ path {
25
+ fill: $spunPearl;
26
+ }
27
+ }
28
+ }
42
29
 
30
+ &.without-border {
43
31
  .form-field__caret {
44
32
  display: none;
45
33
  }
@@ -50,254 +38,62 @@
50
38
  }
51
39
  }
52
40
  }
41
+ }
42
+
43
+ &__select {
44
+ display: flex;
45
+ align-items: center;
46
+ width: 100%;
53
47
 
54
- &-label {
55
- padding-left: 16px;
48
+ &-value {
49
+ display: block;
50
+ overflow: hidden;
51
+ white-space: nowrap;
52
+ text-overflow: ellipsis;
56
53
  }
57
- }
58
54
 
59
- &-dense {
60
- padding-top: 12px;
61
- padding-bottom: 12px;
55
+ &-sub_label {
56
+ display: block;
57
+ margin-left: 5px;
58
+ overflow: hidden;
59
+ color: $topaz;
60
+ white-space: nowrap;
61
+ text-overflow: ellipsis;
62
+ }
62
63
  }
64
+ }
63
65
 
64
- &-normal {
65
- padding-top: 14px;
66
- padding-bottom: 14px;
67
- }
66
+ &__options-list {
67
+ .pop-up-dialog {
68
+ width: 100%;
69
+ padding: 0;
68
70
 
69
- &-medium {
70
- padding-top: 16px;
71
- padding-bottom: 16px;
71
+ &__header {
72
+ display: none;
73
+ }
72
74
  }
75
+ .options-list {
76
+ &__body {
77
+ width: 100%;
78
+ max-height: 250px;
79
+ overflow-y: auto;
80
+ color: $mulledWineTwo;
81
+ background-color: $white;
82
+ border: $primaryBorder;
83
+ border-radius: 2px;
84
+ box-shadow: $filterShadow;
85
+ }
73
86
 
74
- &-chunky {
75
- padding-top: 18px;
76
- padding-bottom: 18px;
77
- }
87
+ &__search {
88
+ width: 100%;
78
89
 
79
- &-value {
80
- display: block;
81
- min-height: 18px;
90
+ input {
91
+ width: 100%;
92
+ padding: 10px;
93
+ border: none;
94
+ border-bottom: $primaryBorder;
95
+ }
96
+ }
82
97
  }
83
98
  }
84
99
  }
85
-
86
- // .select {
87
- // position: relative;
88
- // display: flex;
89
- // flex-flow: column;
90
- // flex: 1 0;
91
- // cursor: pointer;
92
-
93
- // @include fieldWrapper;
94
-
95
- // &__label {
96
- // margin-bottom: 5px;
97
- // color: $topaz;
98
- // font-size: 12px;
99
- // text-transform: capitalize;
100
- // background-color: transparent;
101
-
102
- // &-mandatory {
103
- // color: $amaranth;
104
- // }
105
-
106
- // &-disabled {
107
- // color: $spunPearl;
108
-
109
- // .form-field__label-mandatory {
110
- // color: $spunPearl;
111
- // }
112
- // }
113
- // }
114
-
115
- // &_active:not(.without-border) {
116
- // background: $alabaster;
117
- // }
118
-
119
- // &__caret {
120
- // position: absolute;
121
- // top: 50%;
122
- // right: 10px;
123
- // transform: translate(0%, -50%);
124
- // }
125
-
126
- // &.without {
127
- // &-border {
128
- // border: none;
129
-
130
- // .select__caret {
131
- // display: none;
132
- // }
133
-
134
- // &:hover {
135
- // .select__caret {
136
- // display: block;
137
- // }
138
- // }
139
- // }
140
-
141
- // &-label {
142
- // padding-left: 16px;
143
- // }
144
- // }
145
-
146
- // &__header {
147
- // position: relative;
148
- // display: flex;
149
- // align-items: center;
150
- // width: 100%;
151
- // height: 100%;
152
- // }
153
-
154
- // &__value {
155
- // min-width: 96px;
156
- // min-height: 1em;
157
- // padding-right: 50px;
158
- // overflow: hidden;
159
- // color: $mulledWine;
160
- // white-space: nowrap;
161
- // text-overflow: ellipsis;
162
-
163
- // &_floating {
164
- // position: relative;
165
- // top: 6px;
166
- // left: 16px;
167
- // }
168
- // }
169
-
170
- // &__label {
171
- // top: 15px;
172
- // left: 0;
173
- // padding: 0 5px 0 16px;
174
- // color: $topaz;
175
- // font-size: 15px;
176
- // text-transform: capitalize;
177
- // transition: 200ms ease;
178
-
179
- // &_floating {
180
- // position: absolute;
181
- // top: 0;
182
- // left: 0;
183
- // padding-top: 9px;
184
- // font-weight: 700;
185
- // font-size: 10px;
186
- // line-height: 12px;
187
- // letter-spacing: 0.5px;
188
- // transition: 200ms ease;
189
- // }
190
-
191
- // &_top {
192
- // position: absolute;
193
- // top: -20px;
194
- // left: 0;
195
- // padding: 0;
196
- // font-weight: bold;
197
- // font-size: 12px;
198
- // line-height: 15px;
199
-
200
- // & + .select__value {
201
- // padding-left: 15px;
202
- // }
203
- // }
204
- // }
205
-
206
- // &__options-list {
207
- // .pop-up-dialog {
208
- // width: 100%;
209
- // padding: 0;
210
-
211
- // &__header {
212
- // display: none;
213
- // }
214
- // }
215
- // }
216
-
217
- // &.disabled {
218
- // cursor: not-allowed;
219
-
220
- // .select__label,
221
- // .select__value {
222
- // color: $spunPearl;
223
- // }
224
- // }
225
-
226
- // .sub-label {
227
- // margin-left: 5px;
228
- // overflow: hidden;
229
- // color: $topaz;
230
- // white-space: nowrap;
231
- // text-overflow: ellipsis;
232
- // }
233
-
234
- // &__body {
235
- // width: 100%;
236
- // max-height: 250px;
237
- // overflow-y: auto;
238
- // color: $mulledWineTwo;
239
- // background-color: $white;
240
- // border: $primaryBorder;
241
- // border-radius: 2px;
242
- // box-shadow: $filterShadow;
243
- // }
244
-
245
- // &__search {
246
- // width: 100%;
247
-
248
- // input {
249
- // width: 100%;
250
- // padding: 10px;
251
- // border: none;
252
- // border-bottom: $primaryBorder;
253
- // }
254
- // }
255
-
256
- // .actions {
257
- // position: absolute;
258
- // right: 25px;
259
- // }
260
-
261
- // .disabled {
262
- // color: $spunPearl;
263
- // cursor: default;
264
- // user-select: none;
265
-
266
- // &:hover {
267
- // background-color: $white;
268
- // }
269
- // }
270
-
271
- // .pop-up-dialog__overlay {
272
- // top: 100%;
273
- // right: calc(100% + 10px);
274
- // }
275
-
276
- // &-dense {
277
- // height: 40px;
278
-
279
- // .select__label_floating {
280
- // padding-top: 6px;
281
- // }
282
- // }
283
-
284
- // &-normal {
285
- // height: 48px;
286
- // }
287
-
288
- // &-medium {
289
- // height: 52px;
290
-
291
- // .select__label_floating {
292
- // padding-top: 11px;
293
- // }
294
- // }
295
-
296
- // &-chunky {
297
- // height: 56px;
298
-
299
- // .select__label_floating {
300
- // padding-top: 13px;
301
- // }
302
- // }
303
- // }