react-core-ts 1.2.29 → 1.2.31
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 +14 -21
- package/dist/AutoCompleteWithSelectedList.js.map +1 -1
- package/package.json +1 -1
- package/src/AutoComplete.tsx +47 -47
- package/src/AutoCompleteWithSelectedList.tsx +23 -22
- package/dist/styles/styles/components/autocomplete.css +0 -616
- package/dist/styles/styles/components/selectedautocomplete.css +0 -128
- package/dist/styles/styles/components/tooltip.css +0 -496
- package/dist/styles/styles/components/treedropdown.css +0 -63
- package/dist/styles/styles/global.css +0 -8
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
|
</>
|
|
@@ -108,14 +108,13 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
108
108
|
};
|
|
109
109
|
// Check if there's enough space below the input for the dropdown
|
|
110
110
|
const spaceBelow = window.innerHeight - inputRect.bottom;
|
|
111
|
-
const spaceAbove = inputRect.top + window.scrollY;
|
|
112
111
|
let dropdownHeight = viewMode ? 160 : 380; // Assume a fixed height or calculate based on content
|
|
113
112
|
|
|
114
113
|
if (countOnly && !viewMode) {
|
|
115
114
|
// if (dropdownSelectedRef?.current) {
|
|
116
115
|
// dropdownHeight += dropdownSelectedRef?.current?.clientHeight;
|
|
117
116
|
// }
|
|
118
|
-
dropdownHeight += type === 'auto_suggestion' ?
|
|
117
|
+
dropdownHeight += type === 'auto_suggestion' ? 220 : 192;
|
|
119
118
|
}
|
|
120
119
|
|
|
121
120
|
if (tab.length > 0) {
|
|
@@ -130,9 +129,11 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
130
129
|
? inputRect.top + window.scrollY - dropdownHeight + 18 + topMargin
|
|
131
130
|
: inputRect.top + window.scrollY - dropdownHeight + 73 + topMargin;
|
|
132
131
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
setDropdownStyle({
|
|
134
|
+
...dropdownPosition,
|
|
135
|
+
});
|
|
136
|
+
}, 100);
|
|
136
137
|
}
|
|
137
138
|
};
|
|
138
139
|
|
|
@@ -143,7 +144,7 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
143
144
|
return () => {
|
|
144
145
|
window.removeEventListener('resize', adjustDropdownPosition);
|
|
145
146
|
};
|
|
146
|
-
}, [selectedItems, expandArrowClick]);
|
|
147
|
+
}, [selectedItems, expandArrowClick, dropOpen]);
|
|
147
148
|
|
|
148
149
|
const { suggestions, isLoading, handlePickSuggestions } = useSuggestions(
|
|
149
150
|
getData,
|
|
@@ -398,17 +399,10 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
398
399
|
const handleDropOpen = async (e: any) => {
|
|
399
400
|
e.stopPropagation();
|
|
400
401
|
if (!dropOpen) setDropOpen(true);
|
|
401
|
-
|
|
402
|
-
setTimeout(() => {
|
|
403
|
-
if (viewMode) {
|
|
404
|
-
adjustDropdownPosition();
|
|
405
|
-
}
|
|
406
|
-
}, 100);
|
|
407
402
|
};
|
|
408
403
|
|
|
409
404
|
const handleDropClose = (e: any) => {
|
|
410
405
|
e.stopPropagation();
|
|
411
|
-
console.log('handleDropClose');
|
|
412
406
|
if (dropOpen) setDropOpen(false);
|
|
413
407
|
};
|
|
414
408
|
|
|
@@ -486,12 +480,7 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
486
480
|
</div>
|
|
487
481
|
);
|
|
488
482
|
};
|
|
489
|
-
|
|
490
|
-
if (dropOpen && !viewMode) {
|
|
491
|
-
adjustDropdownPosition();
|
|
492
|
-
}
|
|
493
|
-
}, [dropOpen]);
|
|
494
|
-
console.log(dropdownStyle, 'dropdownStyle');
|
|
483
|
+
|
|
495
484
|
const getTabItems = () => {
|
|
496
485
|
return (
|
|
497
486
|
<ul
|
|
@@ -625,7 +614,14 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
625
614
|
ReactDOM.createPortal(
|
|
626
615
|
<div
|
|
627
616
|
ref={dropRef}
|
|
628
|
-
style={{
|
|
617
|
+
style={{
|
|
618
|
+
...dropdownStyle,
|
|
619
|
+
minHeight: viewMode
|
|
620
|
+
? 160
|
|
621
|
+
: type === 'auto_suggestion'
|
|
622
|
+
? 164
|
|
623
|
+
: 192,
|
|
624
|
+
}}
|
|
629
625
|
className={`qbs-autocomplete-suggestions qbs-autocomplete-selected-suggestions ${
|
|
630
626
|
viewMode ? 'qbs-dropdown-selected-preview' : ''
|
|
631
627
|
} ${viewMode && selectedItems?.length === 0 ? 'hidden' : ''}`}
|
|
@@ -717,7 +713,9 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
717
713
|
ref={dropdownSelectedRef}
|
|
718
714
|
>
|
|
719
715
|
{selectedItems?.length > 0 ? (
|
|
720
|
-
<div
|
|
716
|
+
<div
|
|
717
|
+
className={`qbs-flex qbs-w-full qbs-text-xs items-center`}
|
|
718
|
+
>
|
|
721
719
|
<div className="qbs-selected-lbs qbs-flex-grow">
|
|
722
720
|
Selected Items
|
|
723
721
|
</div>
|
|
@@ -731,7 +729,10 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
731
729
|
</div>
|
|
732
730
|
</div>
|
|
733
731
|
) : (
|
|
734
|
-
<div
|
|
732
|
+
<div className="w-full flex items-center justify-center">
|
|
733
|
+
{' '}
|
|
734
|
+
No Items Selected
|
|
735
|
+
</div>
|
|
735
736
|
)}
|
|
736
737
|
|
|
737
738
|
{getSelectedItems(true)}
|