intelicoreact 1.3.32 → 1.3.34

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.
@@ -347,7 +347,7 @@ const Datepicker = props => {
347
347
  className: "date-picker__button",
348
348
  onClick: () => onCancel(),
349
349
  variant: buttonsTypes === null || buttonsTypes === void 0 ? void 0 : buttonsTypes.cancel
350
- }, (txt === null || txt === void 0 ? void 0 : (_txt$buttons = txt.buttons) === null || _txt$buttons === void 0 ? void 0 : _txt$buttons.cancel) || "cancel"), /*#__PURE__*/_react.default.createElement(_Button.default, {
350
+ }, (txt === null || txt === void 0 ? void 0 : (_txt$buttons = txt.buttons) === null || _txt$buttons === void 0 ? void 0 : _txt$buttons.cancel) || "Cancel"), /*#__PURE__*/_react.default.createElement(_Button.default, {
351
351
  className: "date-picker__button",
352
352
  variant: buttonsTypes === null || buttonsTypes === void 0 ? void 0 : buttonsTypes.apply,
353
353
  disabled: !startDate || !endDate,
@@ -19,6 +19,8 @@ var _reactFeather = require("react-feather");
19
19
 
20
20
  var _fieldValueFormatters = require("../../../Functions/fieldValueFormatters");
21
21
 
22
+ var _useDebounce = require("../../../Functions/useDebounce");
23
+
22
24
  var _useIsMobile = _interopRequireDefault(require("../../../Functions/useIsMobile"));
23
25
 
24
26
  var _CheckboxInput = _interopRequireDefault(require("../../FormElements/CheckboxInput/CheckboxInput"));
@@ -39,7 +41,7 @@ const RC = "tags-dropdown";
39
41
  const MIN_ITEMS_FOR_SHOW_MOBILE_SEARCH = 10;
40
42
 
41
43
  const TagsDropdown = _ref => {
42
- var _dropdownListWrapperR, _dropdownListWrapperR2, _dropdownListRef$curr5, _dropdownListRef$curr6;
44
+ var _Object$keys, _dropdownListWrapperR, _dropdownListWrapperR2, _dropdownListRef$curr5, _dropdownListRef$curr6;
43
45
 
44
46
  let {
45
47
  options,
@@ -50,9 +52,6 @@ const TagsDropdown = _ref => {
50
52
  onKeyPress = () => {},
51
53
  placeholder,
52
54
  label,
53
- isLabelBold,
54
- hint,
55
- hintSide,
56
55
  disabled,
57
56
  isValuesInTags,
58
57
  error,
@@ -75,6 +74,8 @@ const TagsDropdown = _ref => {
75
74
  noOptionsText = "No options available",
76
75
  mobileSearchPlaceholder,
77
76
  isSearchable = true,
77
+ useLiveSearch,
78
+ doRequest: doLiveSearchRequest,
78
79
  attributesOfNativeInput = {},
79
80
  withMobileLogic,
80
81
  minItemsForShowMobileSearch = MIN_ITEMS_FOR_SHOW_MOBILE_SEARCH
@@ -96,7 +97,51 @@ const TagsDropdown = _ref => {
96
97
  const [isFixedMaxHeight, setIsFixedMaxHeight] = (0, _react.useState)(false);
97
98
  const [scrollTop, setScrollTop] = (0, _react.useState)(0);
98
99
  const [scrollHeight, setScrollHeight] = (0, _react.useState)(1);
99
- const singleLevelOptions = options === null || options === void 0 ? void 0 : options.reduce((acc, item) => [...acc, ...(item.groupName ? item.list : [item])], []);
100
+ const debouncedSearchTerm = (0, _useDebounce.useDebounce)({
101
+ searchValue,
102
+ delay: 600
103
+ });
104
+ const [isValueDeleted, setIsValueDeleted] = (0, _react.useState)(false);
105
+ const searchValueRef = (0, _react.useRef)(null);
106
+ const [localOptionsStore, setLocalOptionsStore] = (0, _react.useState)({});
107
+ const singleLevelOptions = options === null || options === void 0 ? void 0 : options.reduce((acc, item) => {
108
+ const checkUniqAndPush = (acc, item) => {
109
+ const isExist = acc === null || acc === void 0 ? void 0 : acc.findIndex(value => value === (item === null || item === void 0 ? void 0 : item.value));
110
+
111
+ if (isExist !== -1) {
112
+ acc[isExist] = item;
113
+ } else {
114
+ acc.push(item);
115
+ }
116
+ };
117
+
118
+ if (item.groupName) {
119
+ var _item$list;
120
+
121
+ (_item$list = item.list) === null || _item$list === void 0 ? void 0 : _item$list.map(item => checkUniqAndPush(acc, item));
122
+ } else {
123
+ checkUniqAndPush(acc, item);
124
+ }
125
+
126
+ return acc;
127
+ }, (_Object$keys = Object.keys(localOptionsStore)) === null || _Object$keys === void 0 ? void 0 : _Object$keys.map(value => ({
128
+ value,
129
+ label: localOptionsStore === null || localOptionsStore === void 0 ? void 0 : localOptionsStore[value]
130
+ })));
131
+
132
+ const setSearchValueInterceptor = value => {
133
+ setSearchValue(value);
134
+ setIsValueDeleted(value === "");
135
+ searchValueRef.current = value;
136
+ };
137
+
138
+ const doScrollCallback = (0, _react.useCallback)(e => {
139
+ if (doLiveSearchRequest && typeof doLiveSearchRequest === "function") {
140
+ if (Math.round(e.target.clientHeight + e.target.scrollTop) == e.target.scrollHeight) {
141
+ doLiveSearchRequest(searchValueRef.current, true);
142
+ }
143
+ }
144
+ }, [options]);
100
145
 
101
146
  const handleClickOutside = _ref2 => {
102
147
  var _getListContainer;
@@ -105,16 +150,20 @@ const TagsDropdown = _ref => {
105
150
  target
106
151
  } = _ref2;
107
152
 
108
- if (!((_getListContainer = getListContainer()) !== null && _getListContainer !== void 0 && _getListContainer.contains(target))
153
+ if ( // eslint-disable-next-line no-use-before-define
154
+ !((_getListContainer = getListContainer()) !== null && _getListContainer !== void 0 && _getListContainer.contains(target))
109
155
  /* && !isTargetInParent(target) */
110
156
  ) {
111
157
  setIsOpen(false);
112
- setSearchValue("");
158
+ setSearchValueInterceptor("");
113
159
  }
114
160
  };
115
161
 
116
162
  const deleteChosen = value => {
117
163
  if (isMobile ? closeOnRemoveMobile : closeOnRemove) setIsOpen(false);
164
+ setLocalOptionsStore(options => ({ ...options,
165
+ [value]: undefined
166
+ }));
118
167
  onChange(chosenOptions.filter(item => item !== value), "chosenOptions");
119
168
  };
120
169
 
@@ -125,13 +174,16 @@ const TagsDropdown = _ref => {
125
174
  if (item.closeOnOptionSelect) setIsOpen(false);
126
175
  } else if (isMobile ? closeOnSelectMobile : closeOnSelect) setIsOpen(false);
127
176
 
128
- setSearchValue("");
177
+ setSearchValueInterceptor("");
129
178
 
130
179
  if (chosenOptions.some(el => el === item.value)) {
131
180
  deleteChosen(item.value);
132
181
  return null;
133
182
  }
134
183
 
184
+ setLocalOptionsStore(options => ({ ...options,
185
+ [item === null || item === void 0 ? void 0 : item.value]: item === null || item === void 0 ? void 0 : item.label
186
+ }));
135
187
  onChange([...chosenOptions, item.value], "chosenOptions");
136
188
  return null;
137
189
  };
@@ -139,7 +191,7 @@ const TagsDropdown = _ref => {
139
191
  const onSearchHandler = name => {
140
192
  let inputValue = name;
141
193
  if (!isNotValidateASCII) inputValue = (0, _fieldValueFormatters.formatToOnlyASCIICodeText)(inputValue);
142
- setSearchValue(inputValue);
194
+ setSearchValueInterceptor(inputValue);
143
195
  };
144
196
 
145
197
  const onWrapperClick = e => {
@@ -198,7 +250,7 @@ const TagsDropdown = _ref => {
198
250
  className: (0, _classnames.default)("".concat(RC, "__list-item-description"))
199
251
  }, description)), isMobile ? (_item$customMobileIco = item === null || item === void 0 ? void 0 : item.customMobileIcon) !== null && _item$customMobileIco !== void 0 ? _item$customMobileIco : /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
200
252
  value: chosenOptions === null || chosenOptions === void 0 ? void 0 : chosenOptions.some(value => value === item.value),
201
- onChange: v => {
253
+ onChange: () => {
202
254
  onChangeHandler(item);
203
255
  }
204
256
  }) : "");
@@ -208,32 +260,42 @@ const TagsDropdown = _ref => {
208
260
  return options === null || options === void 0 ? void 0 : options.map(option => option !== null && option !== void 0 && option.groupName ? option === null || option === void 0 ? void 0 : option.list : option).flat();
209
261
  };
210
262
 
211
- const selectAllItems = e => {
212
- var _prepareOptions, _prepareOptions$filte;
263
+ const selectAllItems = () => {
264
+ var _prepareOptions;
213
265
 
214
- onChange([...chosenOptions, ...(((_prepareOptions = prepareOptions(options)) === null || _prepareOptions === void 0 ? void 0 : (_prepareOptions$filte = _prepareOptions.filter(_ref3 => {
266
+ const preparedOptions = (_prepareOptions = prepareOptions(options)) === null || _prepareOptions === void 0 ? void 0 : _prepareOptions.filter(_ref3 => {
215
267
  let {
216
268
  isFreezed,
217
269
  value
218
270
  } = _ref3;
219
271
  return !isFreezed && !(chosenOptions !== null && chosenOptions !== void 0 && chosenOptions.includes(value)) && value !== "open_modal";
220
- })) === null || _prepareOptions$filte === void 0 ? void 0 : _prepareOptions$filte.map(_ref4 => {
272
+ });
273
+ setLocalOptionsStore(options => preparedOptions === null || preparedOptions === void 0 ? void 0 : preparedOptions.reduce((result, _ref4) => {
221
274
  let {
222
- value
275
+ value,
276
+ label
223
277
  } = _ref4;
278
+ result[value] = label;
279
+ return result;
280
+ }, options));
281
+ onChange([...chosenOptions, ...((preparedOptions === null || preparedOptions === void 0 ? void 0 : preparedOptions.map(_ref5 => {
282
+ let {
283
+ value
284
+ } = _ref5;
224
285
  return value;
225
286
  })) || [])], "chosenOptions");
226
287
  if (isMobile ? closeOnSelectAllMobile : closeOnSelectAll) setIsOpen(false);
227
288
  };
228
289
 
229
- const unselectAllItems = e => {
290
+ const unselectAllItems = () => {
291
+ setLocalOptionsStore({});
230
292
  onChange(chosenOptions === null || chosenOptions === void 0 ? void 0 : chosenOptions.filter(item => {
231
293
  var _prepareOptions2, _prepareOptions2$find;
232
294
 
233
- return (_prepareOptions2 = prepareOptions(options)) === null || _prepareOptions2 === void 0 ? void 0 : (_prepareOptions2$find = _prepareOptions2.find(_ref5 => {
295
+ return (_prepareOptions2 = prepareOptions(options)) === null || _prepareOptions2 === void 0 ? void 0 : (_prepareOptions2$find = _prepareOptions2.find(_ref6 => {
234
296
  let {
235
297
  value
236
- } = _ref5;
298
+ } = _ref6;
237
299
  return value === item;
238
300
  })) === null || _prepareOptions2$find === void 0 ? void 0 : _prepareOptions2$find.isFreezed;
239
301
  }), "chosenOptions");
@@ -241,9 +303,9 @@ const TagsDropdown = _ref => {
241
303
  };
242
304
 
243
305
  const getParentNode = () => {
244
- var _ref6, _document$querySelect;
306
+ var _ref7, _document$querySelect;
245
307
 
246
- return (_ref6 = (_document$querySelect = document.querySelector("div#root")) !== null && _document$querySelect !== void 0 ? _document$querySelect : document.querySelector("div#app")) !== null && _ref6 !== void 0 ? _ref6 : document.querySelector("div#storybook-root");
308
+ return (_ref7 = (_document$querySelect = document.querySelector("div#root")) !== null && _document$querySelect !== void 0 ? _document$querySelect : document.querySelector("div#app")) !== null && _ref7 !== void 0 ? _ref7 : document.querySelector("div#storybook-root");
247
309
  };
248
310
 
249
311
  const initListContainer = () => {
@@ -263,7 +325,7 @@ const TagsDropdown = _ref => {
263
325
  try {
264
326
  var _document$getElementB;
265
327
 
266
- (_document$getElementB = document.getElementById("mlw-".concat(dropdownId))) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
328
+ (_document$getElementB = document.getElementById("mlw-".concat(dropdownId))) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove(); // eslint-disable-next-line no-empty
267
329
  } catch (e) {}
268
330
 
269
331
  const dropdownMobileListWrapper = document.createElement("div");
@@ -322,7 +384,8 @@ const TagsDropdown = _ref => {
322
384
 
323
385
  const renderListContainer = () => {
324
386
  const lc = getListContainer();
325
- if (!lc) return null;
387
+ if (!lc) return null; // eslint-disable-next-line no-use-before-define
388
+
326
389
  return /*#__PURE__*/(0, _reactDom.createPortal)(getListMarkUp(), lc);
327
390
  };
328
391
 
@@ -360,9 +423,9 @@ const TagsDropdown = _ref => {
360
423
  const getTotalOptions = (0, _react.useCallback)(() => {
361
424
  return options === null || options === void 0 ? void 0 : options.reduce((result, item) => {
362
425
  if (item !== null && item !== void 0 && item.list) {
363
- var _item$list;
426
+ var _item$list2;
364
427
 
365
- result += (item === null || item === void 0 ? void 0 : (_item$list = item.list) === null || _item$list === void 0 ? void 0 : _item$list.length) || 0;
428
+ result += (item === null || item === void 0 ? void 0 : (_item$list2 = item.list) === null || _item$list2 === void 0 ? void 0 : _item$list2.length) || 0;
366
429
  } else {
367
430
  ++result;
368
431
  }
@@ -409,12 +472,11 @@ const TagsDropdown = _ref => {
409
472
  }, /*#__PURE__*/_react.default.createElement(_Input.default, (0, _extends2.default)({
410
473
  className: "".concat(RC, "__input"),
411
474
  value: searchValue,
412
- onChange: v => setSearchValue(v),
475
+ onChange: v => setSearchValueInterceptor(v),
413
476
  placeholder: mobileSearchPlaceholder || "Search",
414
477
  withDelete: true,
415
- onMouseDown: e => {
478
+ onMouseDown: () => {
416
479
  if (!isOpen) {
417
- setIsSearchInputFocused(true);
418
480
  setIsOpen(true);
419
481
  }
420
482
  }
@@ -432,17 +494,17 @@ const TagsDropdown = _ref => {
432
494
  }, /*#__PURE__*/_react.default.createElement("span", {
433
495
  className: "".concat(RC, "-group__name")
434
496
  }, option.groupName), (_option$list2 = option.list) === null || _option$list2 === void 0 ? void 0 : _option$list2.map(item => getMarkupForElement(item))) : getMarkupForElement(option);
435
- }), ((_filteredOptions$filt = filteredOptions.filter(_ref7 => {
497
+ }), ((_filteredOptions$filt = filteredOptions.filter(_ref8 => {
436
498
  let {
437
499
  value
438
- } = _ref7;
500
+ } = _ref8;
439
501
  return value !== "open_modal";
440
502
  })) === null || _filteredOptions$filt === void 0 ? void 0 : _filteredOptions$filt.length) === 0 ? /*#__PURE__*/_react.default.createElement("div", {
441
503
  className: "".concat(RC, "__no-options")
442
- }, noOptionsText) : null), (footerContent || isMobile) && ((_filteredOptions$filt2 = filteredOptions.filter(_ref8 => {
504
+ }, noOptionsText) : null), (footerContent || isMobile) && ((_filteredOptions$filt2 = filteredOptions.filter(_ref9 => {
443
505
  let {
444
506
  value
445
- } = _ref8;
507
+ } = _ref9;
446
508
  return value !== "open_modal";
447
509
  })) === null || _filteredOptions$filt2 === void 0 ? void 0 : _filteredOptions$filt2.length) > 0 ? /*#__PURE__*/_react.default.createElement("div", {
448
510
  className: (0, _classnames.default)("".concat(RC, "__footer"), {
@@ -522,6 +584,14 @@ const TagsDropdown = _ref => {
522
584
  setIsFixedMaxHeight((dropdownListRef === null || dropdownListRef === void 0 ? void 0 : (_dropdownListRef$curr3 = dropdownListRef.current) === null || _dropdownListRef$curr3 === void 0 ? void 0 : _dropdownListRef$curr3.scrollHeight) > (dropdownListRef === null || dropdownListRef === void 0 ? void 0 : (_dropdownListRef$curr4 = dropdownListRef.current) === null || _dropdownListRef$curr4 === void 0 ? void 0 : _dropdownListRef$curr4.clientHeight));
523
585
  }
524
586
  }
587
+
588
+ if (isOpen && dropdownListRef && dropdownListRef.current) {
589
+ dropdownListRef.current.addEventListener("scroll", doScrollCallback);
590
+ }
591
+
592
+ return () => {
593
+ removeEventListener("scroll", doScrollCallback);
594
+ };
525
595
  }, [isOpen, isMobile, dropdownListRef === null || dropdownListRef === void 0 ? void 0 : dropdownListRef.current, dropdownListRef === null || dropdownListRef === void 0 ? void 0 : (_dropdownListRef$curr5 = dropdownListRef.current) === null || _dropdownListRef$curr5 === void 0 ? void 0 : _dropdownListRef$curr5.scrollHeight, dropdownListRef === null || dropdownListRef === void 0 ? void 0 : (_dropdownListRef$curr6 = dropdownListRef.current) === null || _dropdownListRef$curr6 === void 0 ? void 0 : _dropdownListRef$curr6.clientHeight]);
526
596
  (0, _react.useEffect)(() => {
527
597
  const setScrollTopValue = e => {
@@ -555,6 +625,11 @@ const TagsDropdown = _ref => {
555
625
  (_getListContainerWrap = getListContainerWrapper()) === null || _getListContainerWrap === void 0 ? void 0 : _getListContainerWrap.remove();
556
626
  };
557
627
  }, []);
628
+ (0, _react.useEffect)(() => {
629
+ if (isSearchable && useLiveSearch && debouncedSearchTerm || isValueDeleted) {
630
+ doLiveSearchRequest === null || doLiveSearchRequest === void 0 ? void 0 : doLiveSearchRequest(debouncedSearchTerm);
631
+ }
632
+ }, [debouncedSearchTerm, isValueDeleted]);
558
633
  return /*#__PURE__*/_react.default.createElement("div", {
559
634
  className: (0, _classnames.default)(RC, className, {
560
635
  ["".concat(RC, "_disabled")]: disabled,
@@ -565,17 +640,17 @@ const TagsDropdown = _ref => {
565
640
  className: (0, _classnames.default)("".concat(RC, "__trigger"), {
566
641
  "tags-dropdown__error": error
567
642
  }),
568
- onClick: _ref9 => {
643
+ onClick: _ref10 => {
569
644
  let {
570
645
  target
571
- } = _ref9;
646
+ } = _ref10;
572
647
  if ((target === null || target === void 0 ? void 0 : target.tagName) === "INPUT") setIsOpen(true);else if (isTargetInParent(target)) {
573
648
  setIsOpen(isOpen => !isOpen);
574
649
  }
575
650
  }
576
651
  }, noTagsWrap ? /*#__PURE__*/_react.default.createElement(_TagList.default, {
577
652
  items: chosenOptions === null || chosenOptions === void 0 ? void 0 : chosenOptions.map((value, i) => {
578
- const tag = singleLevelOptions === null || singleLevelOptions === void 0 ? void 0 : singleLevelOptions.find(el => el.value === value);
653
+ const tag = singleLevelOptions === null || singleLevelOptions === void 0 ? void 0 : singleLevelOptions.find(el => el.value == value);
579
654
  const label = isValuesInTags ? tag === null || tag === void 0 ? void 0 : tag.value : (tag === null || tag === void 0 ? void 0 : tag.label) || (tag === null || tag === void 0 ? void 0 : tag.name) || (tag === null || tag === void 0 ? void 0 : tag.title);
580
655
  return {
581
656
  value,
@@ -586,7 +661,7 @@ const TagsDropdown = _ref => {
586
661
  }),
587
662
  disableShowMore: true
588
663
  }) : chosenOptions === null || chosenOptions === void 0 ? void 0 : chosenOptions.map(value => {
589
- const tag = singleLevelOptions === null || singleLevelOptions === void 0 ? void 0 : singleLevelOptions.find(el => el.value === value);
664
+ const tag = singleLevelOptions === null || singleLevelOptions === void 0 ? void 0 : singleLevelOptions.find(el => el.value == value);
590
665
  const label = isValuesInTags ? tag === null || tag === void 0 ? void 0 : tag.value : (tag === null || tag === void 0 ? void 0 : tag.label) || (tag === null || tag === void 0 ? void 0 : tag.name) || (tag === null || tag === void 0 ? void 0 : tag.title);
591
666
  return /*#__PURE__*/_react.default.createElement(_Tag.default, {
592
667
  key: value,
@@ -229,8 +229,15 @@
229
229
  .tag {
230
230
  margin-top: 1px;
231
231
  margin-bottom: 1px;
232
+ max-width: 100%;
233
+ overflow: hidden;
232
234
 
233
235
  cursor: auto;
236
+
237
+ &__label {
238
+ text-overflow: ellipsis;
239
+ overflow: hidden;
240
+ }
234
241
  }
235
242
 
236
243
  .tag-list_wrapper {
@@ -574,4 +581,4 @@
574
581
  }
575
582
  }
576
583
  }
577
- }
584
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "1.3.32",
3
+ "version": "1.3.34",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [