react-core-ts 1.2.28 → 1.2.30
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/AutoComplete.d.ts +2 -2
- package/dist/AutoComplete.js +30 -30
- package/dist/AutoCompleteWithSelectedList.js +7 -15
- package/dist/AutoCompleteWithSelectedList.js.map +1 -1
- package/dist/styles/styles/components/autocomplete.css +616 -0
- package/dist/styles/styles/components/selectedautocomplete.css +128 -0
- package/dist/styles/styles/components/tooltip.css +496 -0
- package/dist/styles/styles/components/treedropdown.css +63 -0
- package/dist/styles/styles/global.css +8 -0
- package/package.json +1 -1
- package/src/AutoComplete.tsx +47 -47
- package/src/AutoCompleteWithSelectedList.tsx +11 -16
package/src/AutoComplete.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Tooltip from
|
|
1
|
+
import Tooltip from './utilities/tooltip';
|
|
2
2
|
import React, {
|
|
3
3
|
forwardRef,
|
|
4
4
|
useCallback,
|
|
@@ -6,14 +6,14 @@ import React, {
|
|
|
6
6
|
useImperativeHandle,
|
|
7
7
|
useRef,
|
|
8
8
|
useState,
|
|
9
|
-
} from
|
|
9
|
+
} from 'react';
|
|
10
10
|
|
|
11
|
-
import { AutoSuggestionInputProps } from
|
|
12
|
-
import { useSuggestions } from
|
|
13
|
-
import { debounce } from
|
|
14
|
-
import { deepEqual } from
|
|
15
|
-
import { filterSuggestions } from
|
|
16
|
-
import { Close, DropArrow, Search, Spinner } from
|
|
11
|
+
import { AutoSuggestionInputProps } from './commontypes';
|
|
12
|
+
import { useSuggestions } from './utilities/autosuggestions';
|
|
13
|
+
import { debounce } from './utilities/debounce';
|
|
14
|
+
import { deepEqual } from './utilities/deepEqual';
|
|
15
|
+
import { filterSuggestions } from './utilities/filterSuggestions';
|
|
16
|
+
import { Close, DropArrow, Search, Spinner } from './utilities/icons';
|
|
17
17
|
|
|
18
18
|
type ValueProps = {
|
|
19
19
|
[key: string]: string;
|
|
@@ -31,14 +31,14 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
31
31
|
fullWidth = false,
|
|
32
32
|
placeholder,
|
|
33
33
|
id,
|
|
34
|
-
type =
|
|
34
|
+
type = 'custom_select',
|
|
35
35
|
selectedItems: propsSeelctedItems = [],
|
|
36
36
|
readOnly = false,
|
|
37
37
|
disabled = false,
|
|
38
38
|
value,
|
|
39
39
|
isMultiple = false,
|
|
40
|
-
desc =
|
|
41
|
-
descId =
|
|
40
|
+
desc = 'name',
|
|
41
|
+
descId = 'id',
|
|
42
42
|
singleSelect,
|
|
43
43
|
className,
|
|
44
44
|
async = false,
|
|
@@ -57,12 +57,12 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
57
57
|
const [isInitialRender, setIsInitialRender] = useState(true);
|
|
58
58
|
|
|
59
59
|
const [inputValue, setInputValue] = useState<string>(value);
|
|
60
|
-
const [searchValue, setSearchValue] = useState<string>(
|
|
60
|
+
const [searchValue, setSearchValue] = useState<string>('');
|
|
61
61
|
const [nextPage, setNextPage] = useState<number | undefined>(1);
|
|
62
62
|
const [dropOpen, setDropOpen] = useState<boolean>(false);
|
|
63
63
|
const [selectedItems, setSelectedItems] = useState<ValueProps[]>([]);
|
|
64
64
|
// API call for suggestions through a custom hook
|
|
65
|
-
const [dropdownPosition, setDropdownPosition] = useState(
|
|
65
|
+
const [dropdownPosition, setDropdownPosition] = useState('bottom');
|
|
66
66
|
const inputRef = useRef(null);
|
|
67
67
|
const dropRef = useRef(null);
|
|
68
68
|
useImperativeHandle(ref, () => inputRef.current);
|
|
@@ -75,19 +75,19 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
75
75
|
const spaceAbove = inputBoxRect.top;
|
|
76
76
|
const spaceBelow = viewportHeight - inputBoxRect.bottom;
|
|
77
77
|
if (spaceAbove > spaceBelow) {
|
|
78
|
-
setDropdownPosition(
|
|
78
|
+
setDropdownPosition('top');
|
|
79
79
|
} else {
|
|
80
|
-
setDropdownPosition(
|
|
80
|
+
setDropdownPosition('bottom');
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
useEffect(() => {
|
|
86
|
-
window.addEventListener(
|
|
86
|
+
window.addEventListener('resize', adjustDropdownPosition);
|
|
87
87
|
adjustDropdownPosition();
|
|
88
88
|
|
|
89
89
|
return () => {
|
|
90
|
-
window.removeEventListener(
|
|
90
|
+
window.removeEventListener('resize', adjustDropdownPosition);
|
|
91
91
|
};
|
|
92
92
|
}, [dropOpen]);
|
|
93
93
|
|
|
@@ -120,7 +120,7 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
120
120
|
});
|
|
121
121
|
} else {
|
|
122
122
|
setInputValue(suggestion[desc]);
|
|
123
|
-
setSearchValue(
|
|
123
|
+
setSearchValue('');
|
|
124
124
|
onChange(suggestion);
|
|
125
125
|
setDropOpen(false);
|
|
126
126
|
}
|
|
@@ -128,7 +128,7 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
128
128
|
|
|
129
129
|
// Adding debounce to avoid making API calls on every keystroke
|
|
130
130
|
const handleChangeWithDebounce = debounce((value) => {
|
|
131
|
-
if ((type ===
|
|
131
|
+
if ((type === 'auto_complete' || type === 'auto_suggestion') && async) {
|
|
132
132
|
handlePickSuggestions(value, 1);
|
|
133
133
|
}
|
|
134
134
|
}, 1000);
|
|
@@ -150,7 +150,7 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
150
150
|
setInputValue(suggestion[desc]);
|
|
151
151
|
onChange(suggestion);
|
|
152
152
|
} else {
|
|
153
|
-
setInputValue(
|
|
153
|
+
setInputValue('');
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
};
|
|
@@ -160,7 +160,7 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
160
160
|
}, [propsSeelctedItems]);
|
|
161
161
|
// Effect to set the input value whenever `value` prop changes
|
|
162
162
|
useEffect(() => {
|
|
163
|
-
setInputValue(value ??
|
|
163
|
+
setInputValue(value ?? '');
|
|
164
164
|
}, [value]);
|
|
165
165
|
|
|
166
166
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
@@ -169,8 +169,8 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
169
169
|
setSearchValue(value);
|
|
170
170
|
handleChangeWithDebounce(value);
|
|
171
171
|
if (!value) {
|
|
172
|
-
setInputValue(
|
|
173
|
-
onChange({ [descId]:
|
|
172
|
+
setInputValue('');
|
|
173
|
+
onChange({ [descId]: '', [desc]: '' });
|
|
174
174
|
}
|
|
175
175
|
};
|
|
176
176
|
const handleSuggestionChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
@@ -188,18 +188,18 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
188
188
|
|
|
189
189
|
const handleClear = () => {
|
|
190
190
|
if (searchValue) {
|
|
191
|
-
setSearchValue(
|
|
191
|
+
setSearchValue('');
|
|
192
192
|
setDropOpen(false);
|
|
193
193
|
} else {
|
|
194
|
-
setInputValue(
|
|
195
|
-
onChange({ [descId]:
|
|
194
|
+
setInputValue('');
|
|
195
|
+
onChange({ [descId]: '', [desc]: '' });
|
|
196
196
|
setDropOpen(false);
|
|
197
197
|
}
|
|
198
198
|
};
|
|
199
199
|
|
|
200
200
|
const generateClassName = useCallback(() => {
|
|
201
201
|
return `qbs-textfield-default ${className} ${
|
|
202
|
-
errors && errors?.message ?
|
|
202
|
+
errors && errors?.message ? 'textfield-error' : 'textfield'
|
|
203
203
|
}`;
|
|
204
204
|
}, [errors, name]);
|
|
205
205
|
const handleRemoveSelectedItem = (index: number) => {
|
|
@@ -224,12 +224,12 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
224
224
|
!dropdownRef.current.contains(event.target)
|
|
225
225
|
) {
|
|
226
226
|
setDropOpen(false);
|
|
227
|
-
setSearchValue(
|
|
227
|
+
setSearchValue('');
|
|
228
228
|
}
|
|
229
229
|
};
|
|
230
|
-
document.addEventListener(
|
|
230
|
+
document.addEventListener('mousedown', handleClickOutside as any);
|
|
231
231
|
return () => {
|
|
232
|
-
document.removeEventListener(
|
|
232
|
+
document.removeEventListener('mousedown', handleClickOutside as any);
|
|
233
233
|
};
|
|
234
234
|
}, []);
|
|
235
235
|
|
|
@@ -264,24 +264,24 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
264
264
|
};
|
|
265
265
|
|
|
266
266
|
const handleOnClick = () => {
|
|
267
|
-
!disabled && !readOnly ? setDropOpen(true) :
|
|
267
|
+
!disabled && !readOnly ? setDropOpen(true) : '';
|
|
268
268
|
};
|
|
269
269
|
const tooltipContent =
|
|
270
270
|
selectedItems?.length > 1
|
|
271
271
|
? selectedItems
|
|
272
272
|
?.slice(1)
|
|
273
273
|
.map((item) => item[desc])
|
|
274
|
-
.join(
|
|
275
|
-
:
|
|
274
|
+
.join(', ')
|
|
275
|
+
: '';
|
|
276
276
|
|
|
277
277
|
return (
|
|
278
|
-
<div className={fullWidth ?
|
|
278
|
+
<div className={fullWidth ? 'fullWidth' : 'autoWidth'} ref={dropdownRef}>
|
|
279
279
|
{label && (
|
|
280
280
|
<div
|
|
281
281
|
style={{
|
|
282
282
|
marginBottom: 5,
|
|
283
|
-
display:
|
|
284
|
-
justifyContent:
|
|
283
|
+
display: 'flex',
|
|
284
|
+
justifyContent: 'space-between',
|
|
285
285
|
}}
|
|
286
286
|
>
|
|
287
287
|
<label className={`labels label-text`}>
|
|
@@ -295,7 +295,7 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
295
295
|
)}
|
|
296
296
|
{/* Displaying selected items for multi-select */}
|
|
297
297
|
|
|
298
|
-
<div style={{ position:
|
|
298
|
+
<div style={{ position: 'relative' }}>
|
|
299
299
|
<div className="selected-items-container ">
|
|
300
300
|
{selectedItems?.length > 0 && (
|
|
301
301
|
<>
|
|
@@ -328,7 +328,7 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
328
328
|
ref={inputRef}
|
|
329
329
|
type="text"
|
|
330
330
|
value={
|
|
331
|
-
type ===
|
|
331
|
+
type === 'auto_suggestion'
|
|
332
332
|
? inputValue
|
|
333
333
|
: searchValue || inputValue
|
|
334
334
|
}
|
|
@@ -337,9 +337,9 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
337
337
|
onFocus={onFocus}
|
|
338
338
|
onClick={() => handleOnClick()}
|
|
339
339
|
className={generateClassName()}
|
|
340
|
-
placeholder={selectedItems?.length > 0 ?
|
|
340
|
+
placeholder={selectedItems?.length > 0 ? '' : placeholder ?? ''}
|
|
341
341
|
readOnly={
|
|
342
|
-
readOnly || type ===
|
|
342
|
+
readOnly || type === 'custom_select' || type == 'auto_suggestion'
|
|
343
343
|
}
|
|
344
344
|
disabled={disabled}
|
|
345
345
|
data-testid="custom-autocomplete"
|
|
@@ -376,9 +376,9 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
376
376
|
ref={dropRef}
|
|
377
377
|
className={`qbs-autocomplete-suggestions ${dropdownPosition}`}
|
|
378
378
|
>
|
|
379
|
-
{type ==
|
|
379
|
+
{type == 'auto_suggestion' && (
|
|
380
380
|
<div
|
|
381
|
-
style={{ position:
|
|
381
|
+
style={{ position: 'relative' }}
|
|
382
382
|
className="react-core-ts-search-container"
|
|
383
383
|
>
|
|
384
384
|
<span className="dropdown-search-icon">
|
|
@@ -410,9 +410,9 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
410
410
|
key={idx.toString()}
|
|
411
411
|
className={`qbs-autocomplete-listitem-container ${
|
|
412
412
|
(isMultiple || singleSelect) &&
|
|
413
|
-
|
|
413
|
+
'qbs-autocomplete-checkbox-container'
|
|
414
414
|
} ${
|
|
415
|
-
isSelected(suggestion, selected) ?
|
|
415
|
+
isSelected(suggestion, selected) ? 'is-selected' : ''
|
|
416
416
|
}`}
|
|
417
417
|
>
|
|
418
418
|
{(isMultiple || singleSelect) && (
|
|
@@ -442,7 +442,7 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
442
442
|
<li
|
|
443
443
|
key={idx}
|
|
444
444
|
className={`qbs-autocomplete-suggestions-item ${
|
|
445
|
-
isSelected(suggestion, selected) ?
|
|
445
|
+
isSelected(suggestion, selected) ? 'is-selected' : ''
|
|
446
446
|
}`}
|
|
447
447
|
onClick={() => handleSuggestionClick(suggestion)}
|
|
448
448
|
data-testid={suggestion[desc]}
|
|
@@ -455,7 +455,7 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
455
455
|
<>
|
|
456
456
|
{isLoading ? (
|
|
457
457
|
<div
|
|
458
|
-
style={{ display:
|
|
458
|
+
style={{ display: 'flex', justifyContent: 'center' }}
|
|
459
459
|
>
|
|
460
460
|
<span>
|
|
461
461
|
<Spinner />
|
|
@@ -466,7 +466,7 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
466
466
|
className="qbs-autocomplete-notfound"
|
|
467
467
|
onClick={handleBlur}
|
|
468
468
|
>
|
|
469
|
-
{notDataMessage ??
|
|
469
|
+
{notDataMessage ?? 'No Results Found'}
|
|
470
470
|
</li>
|
|
471
471
|
)}
|
|
472
472
|
</>
|
|
@@ -115,7 +115,7 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
115
115
|
// if (dropdownSelectedRef?.current) {
|
|
116
116
|
// dropdownHeight += dropdownSelectedRef?.current?.clientHeight;
|
|
117
117
|
// }
|
|
118
|
-
dropdownHeight += 192;
|
|
118
|
+
dropdownHeight += type === 'auto_suggestion' ? 220 : 192;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
if (tab.length > 0) {
|
|
@@ -143,7 +143,7 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
143
143
|
return () => {
|
|
144
144
|
window.removeEventListener('resize', adjustDropdownPosition);
|
|
145
145
|
};
|
|
146
|
-
}, [selectedItems, expandArrowClick]);
|
|
146
|
+
}, [selectedItems, expandArrowClick, dropOpen]);
|
|
147
147
|
|
|
148
148
|
const { suggestions, isLoading, handlePickSuggestions } = useSuggestions(
|
|
149
149
|
getData,
|
|
@@ -398,17 +398,10 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
398
398
|
const handleDropOpen = async (e: any) => {
|
|
399
399
|
e.stopPropagation();
|
|
400
400
|
if (!dropOpen) setDropOpen(true);
|
|
401
|
-
|
|
402
|
-
setTimeout(() => {
|
|
403
|
-
if (viewMode) {
|
|
404
|
-
adjustDropdownPosition();
|
|
405
|
-
}
|
|
406
|
-
}, 100);
|
|
407
401
|
};
|
|
408
402
|
|
|
409
403
|
const handleDropClose = (e: any) => {
|
|
410
404
|
e.stopPropagation();
|
|
411
|
-
console.log('handleDropClose');
|
|
412
405
|
if (dropOpen) setDropOpen(false);
|
|
413
406
|
};
|
|
414
407
|
|
|
@@ -486,12 +479,7 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
486
479
|
</div>
|
|
487
480
|
);
|
|
488
481
|
};
|
|
489
|
-
|
|
490
|
-
if (dropOpen && !viewMode) {
|
|
491
|
-
adjustDropdownPosition();
|
|
492
|
-
}
|
|
493
|
-
}, [dropOpen]);
|
|
494
|
-
console.log(dropdownStyle, 'dropdownStyle');
|
|
482
|
+
|
|
495
483
|
const getTabItems = () => {
|
|
496
484
|
return (
|
|
497
485
|
<ul
|
|
@@ -625,7 +613,14 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
625
613
|
ReactDOM.createPortal(
|
|
626
614
|
<div
|
|
627
615
|
ref={dropRef}
|
|
628
|
-
style={{
|
|
616
|
+
style={{
|
|
617
|
+
...dropdownStyle,
|
|
618
|
+
minHeight: viewMode
|
|
619
|
+
? 160
|
|
620
|
+
: type === 'auto_suggestion'
|
|
621
|
+
? 164
|
|
622
|
+
: 192,
|
|
623
|
+
}}
|
|
629
624
|
className={`qbs-autocomplete-suggestions qbs-autocomplete-selected-suggestions ${
|
|
630
625
|
viewMode ? 'qbs-dropdown-selected-preview' : ''
|
|
631
626
|
} ${viewMode && selectedItems?.length === 0 ? 'hidden' : ''}`}
|