react-core-ts 1.0.23 → 1.0.24
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/AutoCompleteWithTreeStructure.d.ts +4 -0
- package/dist/AutoCompleteWithTreeStructure.js +453 -0
- package/dist/AutoCompleteWithTreeStructure.js.map +1 -0
- package/dist/ExpandableAutoComplete.d.ts +2 -2
- package/dist/ExpandableAutoComplete.js +54 -71
- package/dist/ExpandableAutoComplete.js.map +1 -1
- package/dist/commontypes.d.ts +3 -2
- package/dist/components/DropdownList.d.ts +14 -0
- package/dist/components/DropdownList.js +18 -0
- package/dist/components/DropdownList.js.map +1 -0
- package/dist/components/Icons.d.ts +3 -0
- package/dist/components/Icons.js +18 -0
- package/dist/components/Icons.js.map +1 -0
- package/dist/components/InputActions.d.ts +14 -0
- package/dist/components/InputActions.js +18 -0
- package/dist/components/InputActions.js.map +1 -0
- package/dist/components/TreeNode.d.ts +3 -0
- package/dist/components/TreeNode.js +34 -0
- package/dist/components/TreeNode.js.map +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/styles/global.css +4 -0
- package/dist/styles/styles/components/autocomplete.css +585 -0
- package/dist/styles/styles/global.css +5 -0
- package/dist/utilities/filterSuggestions.d.ts +1 -1
- package/dist/utilities/filterSuggestions.js +4 -3
- package/dist/utilities/filterSuggestions.js.map +1 -1
- package/docs/App.tsx +64 -36
- package/docs/store.ts +76 -0
- package/package.json +6 -5
- package/postcss.config.js +4 -5
- package/src/AutoCompleteWithTreeStructure.tsx +638 -0
- package/src/ExpandableAutoComplete.tsx +83 -144
- package/src/commontypes.ts +6 -5
- package/src/components/DropdownList.tsx +70 -0
- package/src/components/Icons.tsx +38 -0
- package/src/components/InputActions.tsx +63 -0
- package/src/components/TreeNode.tsx +79 -0
- package/src/index.tsx +11 -8
- package/src/styles/global.css +4 -0
- package/src/utilities/filterSuggestions.ts +5 -3
- package/tailwind.config.js +15 -0
- package/webpack.config.js +17 -3
|
@@ -5,16 +5,18 @@ import React, {
|
|
|
5
5
|
useImperativeHandle,
|
|
6
6
|
useRef,
|
|
7
7
|
useState,
|
|
8
|
-
} from
|
|
9
|
-
import ReactDOM from
|
|
10
|
-
|
|
11
|
-
import { AutoSuggestionInputProps } from
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
8
|
+
} from "react";
|
|
9
|
+
import ReactDOM from "react-dom";
|
|
10
|
+
|
|
11
|
+
import { AutoSuggestionInputProps } from "./commontypes";
|
|
12
|
+
import DropdownList from "./components/DropdownList";
|
|
13
|
+
import InputActions from "./components/InputActions";
|
|
14
|
+
import { useSuggestions } from "./utilities/autosuggestions";
|
|
15
|
+
import { debounce } from "./utilities/debounce";
|
|
16
|
+
import { deepEqual } from "./utilities/deepEqual";
|
|
17
|
+
import { default as Tooltip } from "./utilities/expandableTootltip";
|
|
18
|
+
import { filterSuggestions } from "./utilities/filterSuggestions";
|
|
19
|
+
import { Search, Spinner } from "./utilities/icons";
|
|
18
20
|
|
|
19
21
|
type ValueProps = {
|
|
20
22
|
[key: string]: string;
|
|
@@ -35,14 +37,14 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
35
37
|
fullWidth = false,
|
|
36
38
|
placeholder,
|
|
37
39
|
id,
|
|
38
|
-
type =
|
|
40
|
+
type = "custom_select",
|
|
39
41
|
selectedItems: propsSeelctedItems = [],
|
|
40
42
|
readOnly = false,
|
|
41
43
|
disabled = false,
|
|
42
44
|
value,
|
|
43
45
|
isMultiple = false,
|
|
44
|
-
desc =
|
|
45
|
-
descId =
|
|
46
|
+
desc = "name",
|
|
47
|
+
descId = "id",
|
|
46
48
|
singleSelect,
|
|
47
49
|
className,
|
|
48
50
|
async = false,
|
|
@@ -57,6 +59,7 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
57
59
|
textCount = 10,
|
|
58
60
|
itemCount = 1,
|
|
59
61
|
scrollRef,
|
|
62
|
+
isTreeDropdown = false,
|
|
60
63
|
},
|
|
61
64
|
ref
|
|
62
65
|
) => {
|
|
@@ -65,7 +68,7 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
65
68
|
const [isInitialRender, setIsInitialRender] = useState(true);
|
|
66
69
|
|
|
67
70
|
const [inputValue, setInputValue] = useState<string>(value);
|
|
68
|
-
const [searchValue, setSearchValue] = useState<string>(
|
|
71
|
+
const [searchValue, setSearchValue] = useState<string>("");
|
|
69
72
|
const [nextPage, setNextPage] = useState<number | undefined>(1);
|
|
70
73
|
const [dropOpen, setDropOpen] = useState<boolean>(false);
|
|
71
74
|
const [selectedItems, setSelectedItems] = useState<ValueProps[]>([]);
|
|
@@ -107,11 +110,11 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
107
110
|
};
|
|
108
111
|
|
|
109
112
|
useEffect(() => {
|
|
110
|
-
window.addEventListener(
|
|
113
|
+
window.addEventListener("resize", adjustDropdownPosition);
|
|
111
114
|
adjustDropdownPosition();
|
|
112
115
|
|
|
113
116
|
return () => {
|
|
114
|
-
window.removeEventListener(
|
|
117
|
+
window.removeEventListener("resize", adjustDropdownPosition);
|
|
115
118
|
};
|
|
116
119
|
}, [dropOpen, selectedItems]);
|
|
117
120
|
|
|
@@ -136,7 +139,7 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
136
139
|
} else {
|
|
137
140
|
setInputValue(suggestion[desc]);
|
|
138
141
|
}
|
|
139
|
-
setSearchValue(
|
|
142
|
+
setSearchValue("");
|
|
140
143
|
setInputValue(suggestion[desc]);
|
|
141
144
|
onChange(suggestion);
|
|
142
145
|
setDropOpen(false);
|
|
@@ -144,7 +147,7 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
144
147
|
|
|
145
148
|
// Adding debounce to avoid making API calls on every keystroke
|
|
146
149
|
const handleChangeWithDebounce = debounce((value) => {
|
|
147
|
-
if ((type ===
|
|
150
|
+
if ((type === "auto_complete" || type === "auto_suggestion") && async) {
|
|
148
151
|
handlePickSuggestions(value, 1);
|
|
149
152
|
}
|
|
150
153
|
}, 1000);
|
|
@@ -166,7 +169,7 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
166
169
|
setInputValue(suggestion[desc]);
|
|
167
170
|
onChange(suggestion);
|
|
168
171
|
} else {
|
|
169
|
-
setInputValue(
|
|
172
|
+
setInputValue("");
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
175
|
};
|
|
@@ -176,7 +179,7 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
176
179
|
}, [propsSeelctedItems]);
|
|
177
180
|
// Effect to set the input value whenever `value` prop changes
|
|
178
181
|
useEffect(() => {
|
|
179
|
-
setInputValue(value ??
|
|
182
|
+
setInputValue(value ?? "");
|
|
180
183
|
}, [value]);
|
|
181
184
|
|
|
182
185
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
@@ -185,7 +188,7 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
185
188
|
setSearchValue(value);
|
|
186
189
|
handleChangeWithDebounce(value);
|
|
187
190
|
if (!value) {
|
|
188
|
-
setInputValue(
|
|
191
|
+
setInputValue("");
|
|
189
192
|
// onChange({ [descId]: '', [desc]: '' });
|
|
190
193
|
}
|
|
191
194
|
};
|
|
@@ -204,19 +207,19 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
204
207
|
|
|
205
208
|
const handleClear = () => {
|
|
206
209
|
if (searchValue) {
|
|
207
|
-
setSearchValue(
|
|
210
|
+
setSearchValue("");
|
|
208
211
|
setDropOpen(false);
|
|
209
212
|
} else {
|
|
210
|
-
setInputValue(
|
|
211
|
-
onChange({ [descId]:
|
|
213
|
+
setInputValue("");
|
|
214
|
+
onChange({ [descId]: "", [desc]: "" });
|
|
212
215
|
setDropOpen(false);
|
|
213
216
|
}
|
|
214
217
|
};
|
|
215
218
|
|
|
216
219
|
const generateClassName = useCallback(() => {
|
|
217
220
|
return `qbs-textfield-default ${className} ${
|
|
218
|
-
errors && errors?.message ?
|
|
219
|
-
} ${expandable ?
|
|
221
|
+
errors && errors?.message ? "textfield-error" : "textfield"
|
|
222
|
+
} ${expandable ? "expandable" : ""}`;
|
|
220
223
|
}, [errors, name]);
|
|
221
224
|
const handleRemoveSelectedItem = (index: number) => {
|
|
222
225
|
setSelectedItems((prev) => {
|
|
@@ -238,33 +241,33 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
238
241
|
dropRef.current &&
|
|
239
242
|
event.target instanceof Node &&
|
|
240
243
|
!dropRef.current.contains(event.target) &&
|
|
241
|
-
event.target.nodeName !==
|
|
244
|
+
event.target.nodeName !== "svg"
|
|
242
245
|
) {
|
|
243
246
|
setDropOpen(false);
|
|
244
|
-
setSearchValue(
|
|
247
|
+
setSearchValue("");
|
|
245
248
|
}
|
|
246
249
|
};
|
|
247
|
-
document.addEventListener(
|
|
248
|
-
window.addEventListener(
|
|
250
|
+
document.addEventListener("mousedown", handleClickOutside as any);
|
|
251
|
+
window.addEventListener("scroll", handleClickOutside as any);
|
|
249
252
|
|
|
250
253
|
const scrollableDivs = document.querySelectorAll(
|
|
251
254
|
'div[style*="overflow"]'
|
|
252
255
|
);
|
|
253
256
|
scrollableDivs.forEach((div) =>
|
|
254
|
-
div.addEventListener(
|
|
257
|
+
div.addEventListener("scroll", handleClickOutside as any)
|
|
255
258
|
);
|
|
256
259
|
if (scrollRef && scrollRef.current && scrollRef.current !== null) {
|
|
257
|
-
scrollRef.current.addEventListener(
|
|
260
|
+
scrollRef.current.addEventListener("scroll", handleClickOutside as any);
|
|
258
261
|
}
|
|
259
262
|
return () => {
|
|
260
|
-
document.removeEventListener(
|
|
261
|
-
window.removeEventListener(
|
|
263
|
+
document.removeEventListener("mousedown", handleClickOutside as any);
|
|
264
|
+
window.removeEventListener("scroll", handleClickOutside as any);
|
|
262
265
|
scrollableDivs.forEach((div) =>
|
|
263
|
-
div.removeEventListener(
|
|
266
|
+
div.removeEventListener("scroll", handleClickOutside as any)
|
|
264
267
|
);
|
|
265
268
|
if (scrollRef && scrollRef.current && scrollRef.current !== null) {
|
|
266
269
|
scrollRef.current.removeEventListener(
|
|
267
|
-
|
|
270
|
+
"scroll",
|
|
268
271
|
handleClickOutside as any
|
|
269
272
|
);
|
|
270
273
|
}
|
|
@@ -279,7 +282,8 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
279
282
|
type,
|
|
280
283
|
desc,
|
|
281
284
|
selected,
|
|
282
|
-
async
|
|
285
|
+
async,
|
|
286
|
+
isTreeDropdown
|
|
283
287
|
);
|
|
284
288
|
const isSelected = (
|
|
285
289
|
item: ValueProps,
|
|
@@ -302,7 +306,7 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
302
306
|
};
|
|
303
307
|
|
|
304
308
|
const handleOnClick = () => {
|
|
305
|
-
!disabled && !readOnly ? setDropOpen(true) :
|
|
309
|
+
!disabled && !readOnly ? setDropOpen(true) : "";
|
|
306
310
|
};
|
|
307
311
|
const onInputFocus = () => {
|
|
308
312
|
if (inputRef.current) inputRef.current.focus();
|
|
@@ -314,27 +318,25 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
314
318
|
? selectedItems
|
|
315
319
|
?.slice(itemCount)
|
|
316
320
|
.map((item) => item[desc])
|
|
317
|
-
.join(
|
|
318
|
-
:
|
|
321
|
+
.join(", ")
|
|
322
|
+
: "";
|
|
319
323
|
|
|
320
324
|
const handleDropOpen = (e: any) => {
|
|
321
|
-
console.log('Attempting to open dropdown');
|
|
322
325
|
if (!dropOpen) setDropOpen(true);
|
|
323
326
|
};
|
|
324
327
|
|
|
325
328
|
const handleDropClose = (e: any) => {
|
|
326
|
-
console.log('Attempting to close dropdown');
|
|
327
329
|
if (dropOpen) setDropOpen(false);
|
|
328
330
|
};
|
|
329
331
|
|
|
330
332
|
return (
|
|
331
|
-
<div className={fullWidth ?
|
|
333
|
+
<div className={fullWidth ? "fullWidth" : "autoWidth"} ref={dropdownRef}>
|
|
332
334
|
{label && (
|
|
333
335
|
<div
|
|
334
336
|
style={{
|
|
335
337
|
marginBottom: 5,
|
|
336
|
-
display:
|
|
337
|
-
justifyContent:
|
|
338
|
+
display: "flex",
|
|
339
|
+
justifyContent: "space-between",
|
|
338
340
|
}}
|
|
339
341
|
>
|
|
340
342
|
<label className={`labels label-text`}>
|
|
@@ -350,9 +352,9 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
350
352
|
|
|
351
353
|
<div
|
|
352
354
|
className={`${
|
|
353
|
-
expandable ?
|
|
355
|
+
expandable ? "qbs-expandable-container" : "qbs-container"
|
|
354
356
|
}`}
|
|
355
|
-
style={{ position:
|
|
357
|
+
style={{ position: "relative" }}
|
|
356
358
|
>
|
|
357
359
|
{selectedItems?.length > 0 && (
|
|
358
360
|
<>
|
|
@@ -364,7 +366,7 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
364
366
|
: selectedItems?.length
|
|
365
367
|
)
|
|
366
368
|
.map((item, index) => (
|
|
367
|
-
<div className="selected-items-container">
|
|
369
|
+
<div key={index} className="selected-items-container">
|
|
368
370
|
<Tooltip
|
|
369
371
|
title={item?.[desc]}
|
|
370
372
|
enabled={item?.[desc]?.length > textCount}
|
|
@@ -399,12 +401,12 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
399
401
|
|
|
400
402
|
<div
|
|
401
403
|
className={`qbs-textfield-expandable ${
|
|
402
|
-
!expandable ?
|
|
404
|
+
!expandable ? "qbs-normal" : ""
|
|
403
405
|
}`}
|
|
404
406
|
data-value={
|
|
405
407
|
selectedItems?.length > 0 || searchValue
|
|
406
408
|
? searchValue
|
|
407
|
-
: placeholder ??
|
|
409
|
+
: placeholder ?? ""
|
|
408
410
|
}
|
|
409
411
|
onClick={() => onInputFocus()}
|
|
410
412
|
>
|
|
@@ -413,7 +415,7 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
413
415
|
ref={inputRef}
|
|
414
416
|
type="text"
|
|
415
417
|
value={
|
|
416
|
-
type ===
|
|
418
|
+
type === "auto_suggestion" && !expandable
|
|
417
419
|
? inputValue
|
|
418
420
|
: searchValue || inputValue
|
|
419
421
|
}
|
|
@@ -422,11 +424,11 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
422
424
|
onFocus={onFocus}
|
|
423
425
|
onClick={() => handleOnClick()}
|
|
424
426
|
className={generateClassName()}
|
|
425
|
-
placeholder={selectedItems?.length > 0 ?
|
|
427
|
+
placeholder={selectedItems?.length > 0 ? "" : placeholder ?? ""}
|
|
426
428
|
readOnly={
|
|
427
429
|
readOnly ||
|
|
428
|
-
type ===
|
|
429
|
-
(type ==
|
|
430
|
+
type === "custom_select" ||
|
|
431
|
+
(type == "auto_suggestion" && !expandable)
|
|
430
432
|
}
|
|
431
433
|
disabled={disabled}
|
|
432
434
|
data-testid="custom-autocomplete"
|
|
@@ -434,46 +436,18 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
434
436
|
</div>
|
|
435
437
|
|
|
436
438
|
{/* Icons for Clearing Input or Toggling Dropdown */}
|
|
437
|
-
<div
|
|
438
|
-
className="qbs-autocomplete-close-icon"
|
|
439
|
-
onClick={(e) => e.stopPropagation()}
|
|
440
|
-
>
|
|
441
|
-
{(inputValue || searchValue) &&
|
|
442
|
-
!disabled &&
|
|
443
|
-
!readOnly &&
|
|
444
|
-
!expandable && (
|
|
445
|
-
<button
|
|
446
|
-
onClick={handleClear}
|
|
447
|
-
className="icon-button"
|
|
448
|
-
aria-label="clear"
|
|
449
|
-
>
|
|
450
|
-
<Close />
|
|
451
|
-
</button>
|
|
452
|
-
)}
|
|
453
|
-
{dropOpen ? (
|
|
454
|
-
<button
|
|
455
|
-
type="button"
|
|
456
|
-
onClick={(e) => handleDropClose(e)}
|
|
457
|
-
className="icon-button"
|
|
458
|
-
aria-label="toggle"
|
|
459
|
-
name="toggle"
|
|
460
|
-
>
|
|
461
|
-
<DropArrow className={`icon-button-rotate`} />
|
|
462
|
-
</button>
|
|
463
|
-
) : (
|
|
464
|
-
<button
|
|
465
|
-
disabled={disabled || readOnly}
|
|
466
|
-
type="button"
|
|
467
|
-
className="icon-button"
|
|
468
|
-
onClick={(e) => handleDropOpen(e)}
|
|
469
|
-
aria-label="toggle"
|
|
470
|
-
name="toggle"
|
|
471
|
-
>
|
|
472
|
-
<DropArrow />
|
|
473
|
-
</button>
|
|
474
|
-
)}
|
|
475
|
-
</div>
|
|
476
439
|
|
|
440
|
+
<InputActions
|
|
441
|
+
inputValue={inputValue}
|
|
442
|
+
searchValue={searchValue}
|
|
443
|
+
dropOpen={dropOpen}
|
|
444
|
+
handleDropOpen={handleDropOpen}
|
|
445
|
+
handleDropClose={handleDropClose}
|
|
446
|
+
disabled={disabled}
|
|
447
|
+
readOnly={readOnly}
|
|
448
|
+
expandable={expandable}
|
|
449
|
+
handleClear={handleClear}
|
|
450
|
+
/>
|
|
477
451
|
{/* Displaying Loading Spinner */}
|
|
478
452
|
|
|
479
453
|
{/* Suggestions Dropdown */}
|
|
@@ -485,9 +459,9 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
485
459
|
style={{ ...dropdownStyle, minHeight: 192 }}
|
|
486
460
|
className={`qbs-autocomplete-suggestions`}
|
|
487
461
|
>
|
|
488
|
-
{type ==
|
|
462
|
+
{type == "auto_suggestion" && !expandable && (
|
|
489
463
|
<div
|
|
490
|
-
style={{ position:
|
|
464
|
+
style={{ position: "relative" }}
|
|
491
465
|
className="react-core-ts-search-container"
|
|
492
466
|
>
|
|
493
467
|
<span className="dropdown-search-icon">
|
|
@@ -502,61 +476,26 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
502
476
|
</div>
|
|
503
477
|
)}
|
|
504
478
|
|
|
505
|
-
<div className=
|
|
479
|
+
<div className={`qbs-autocomplete-suggestions-sub `}>
|
|
506
480
|
{filteredData?.length > 0 ? (
|
|
507
481
|
filteredData.map((suggestion: ValueProps, idx: number) => (
|
|
508
|
-
<
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
{
|
|
518
|
-
|
|
519
|
-
<input
|
|
520
|
-
onChange={(e) => handleMultiSelect(e, suggestion)}
|
|
521
|
-
type="checkbox"
|
|
522
|
-
checked={isSelected(suggestion, selected)}
|
|
523
|
-
id={`qbs-checkbox-${idx.toString()}`}
|
|
524
|
-
/>
|
|
525
|
-
<label htmlFor={`qbs-checkbox-${idx.toString()}`}>
|
|
526
|
-
<svg
|
|
527
|
-
width="8"
|
|
528
|
-
height="6"
|
|
529
|
-
viewBox="0 0 8 6"
|
|
530
|
-
fill="none"
|
|
531
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
532
|
-
>
|
|
533
|
-
<path
|
|
534
|
-
d="M0 3.21739L2.89883 6L8 1.06994L6.89494 0L2.89883 3.86768L1.09728 2.14745L0 3.21739Z"
|
|
535
|
-
fill="white"
|
|
536
|
-
/>
|
|
537
|
-
</svg>
|
|
538
|
-
</label>
|
|
539
|
-
</div>
|
|
540
|
-
)}
|
|
541
|
-
<li
|
|
542
|
-
key={idx}
|
|
543
|
-
className={`qbs-autocomplete-suggestions-item ${
|
|
544
|
-
isSelected(suggestion, selected)
|
|
545
|
-
? 'is-selected'
|
|
546
|
-
: ''
|
|
547
|
-
}`}
|
|
548
|
-
onClick={() => handleSuggestionClick(suggestion)}
|
|
549
|
-
data-testid={suggestion[desc]}
|
|
550
|
-
>
|
|
551
|
-
{suggestion[desc]}
|
|
552
|
-
</li>
|
|
553
|
-
</div>
|
|
482
|
+
<DropdownList
|
|
483
|
+
idx={idx}
|
|
484
|
+
suggestion={suggestion}
|
|
485
|
+
isSelected={isSelected}
|
|
486
|
+
handleSuggestionClick={handleSuggestionClick}
|
|
487
|
+
handleMultiSelect={handleMultiSelect}
|
|
488
|
+
selected={selected}
|
|
489
|
+
isMultiple={isMultiple}
|
|
490
|
+
singleSelect={singleSelect}
|
|
491
|
+
desc={desc}
|
|
492
|
+
/>
|
|
554
493
|
))
|
|
555
494
|
) : (
|
|
556
495
|
<>
|
|
557
496
|
{isLoading ? (
|
|
558
497
|
<div
|
|
559
|
-
style={{ display:
|
|
498
|
+
style={{ display: "flex", justifyContent: "center" }}
|
|
560
499
|
>
|
|
561
500
|
<span>
|
|
562
501
|
<Spinner />
|
|
@@ -567,7 +506,7 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
567
506
|
className="qbs-autocomplete-notfound"
|
|
568
507
|
onClick={handleBlur}
|
|
569
508
|
>
|
|
570
|
-
{notDataMessage ??
|
|
509
|
+
{notDataMessage ?? "No Results Found"}
|
|
571
510
|
</li>
|
|
572
511
|
)}
|
|
573
512
|
</>
|
package/src/commontypes.ts
CHANGED
|
@@ -8,12 +8,12 @@ export interface AutoSuggestionInputProps {
|
|
|
8
8
|
required?: boolean;
|
|
9
9
|
value?: string;
|
|
10
10
|
onChange: (value?: ValueProps | ValueProps[]) => void;
|
|
11
|
-
data?:
|
|
11
|
+
data?: any[];
|
|
12
12
|
type?:
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
13
|
+
| "custom_select"
|
|
14
|
+
| "auto_complete"
|
|
15
|
+
| "custom_search_select"
|
|
16
|
+
| "auto_suggestion";
|
|
17
17
|
placeholder?: string;
|
|
18
18
|
getData?: (key?: string, nextBlock?: number) => any;
|
|
19
19
|
errors?: any;
|
|
@@ -39,4 +39,5 @@ export interface AutoSuggestionInputProps {
|
|
|
39
39
|
expandable?: boolean;
|
|
40
40
|
textCount?: number;
|
|
41
41
|
itemCount?: number;
|
|
42
|
+
isTreeDropdown?: boolean;
|
|
42
43
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type ValueProps = {
|
|
4
|
+
idx: number;
|
|
5
|
+
suggestion: any;
|
|
6
|
+
isSelected: (item: any, selectedItems: any[] | string) => boolean;
|
|
7
|
+
handleSuggestionClick: (suggestion: any) => void;
|
|
8
|
+
handleMultiSelect: (e: any, suggestion: any) => void;
|
|
9
|
+
selected: any;
|
|
10
|
+
isMultiple?: boolean;
|
|
11
|
+
singleSelect?: boolean;
|
|
12
|
+
desc: string;
|
|
13
|
+
};
|
|
14
|
+
const DropdownList: React.FC<ValueProps> = ({
|
|
15
|
+
idx,
|
|
16
|
+
suggestion,
|
|
17
|
+
isSelected,
|
|
18
|
+
handleSuggestionClick,
|
|
19
|
+
handleMultiSelect,
|
|
20
|
+
selected,
|
|
21
|
+
isMultiple,
|
|
22
|
+
singleSelect,
|
|
23
|
+
desc,
|
|
24
|
+
}) => {
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
key={idx.toString()}
|
|
28
|
+
className={`qbs-autocomplete-listitem-container ${
|
|
29
|
+
(isMultiple || singleSelect) && 'qbs-autocomplete-checkbox-container'
|
|
30
|
+
} ${isSelected(suggestion, selected) ? 'is-selected' : ''}`}
|
|
31
|
+
>
|
|
32
|
+
{(isMultiple || singleSelect) && (
|
|
33
|
+
<div className="qbs-autocomplete-checkbox">
|
|
34
|
+
<input
|
|
35
|
+
onChange={(e) => handleMultiSelect(e, suggestion)}
|
|
36
|
+
type="checkbox"
|
|
37
|
+
checked={isSelected(suggestion, selected)}
|
|
38
|
+
id={`qbs-checkbox-${idx.toString()}`}
|
|
39
|
+
/>
|
|
40
|
+
<label htmlFor={`qbs-checkbox-${idx.toString()}`}>
|
|
41
|
+
<svg
|
|
42
|
+
width="8"
|
|
43
|
+
height="6"
|
|
44
|
+
viewBox="0 0 8 6"
|
|
45
|
+
fill="none"
|
|
46
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
47
|
+
>
|
|
48
|
+
<path
|
|
49
|
+
d="M0 3.21739L2.89883 6L8 1.06994L6.89494 0L2.89883 3.86768L1.09728 2.14745L0 3.21739Z"
|
|
50
|
+
fill="white"
|
|
51
|
+
/>
|
|
52
|
+
</svg>
|
|
53
|
+
</label>
|
|
54
|
+
</div>
|
|
55
|
+
)}
|
|
56
|
+
<li
|
|
57
|
+
key={idx}
|
|
58
|
+
className={`qbs-autocomplete-suggestions-item ${
|
|
59
|
+
isSelected(suggestion, selected) ? 'is-selected' : ''
|
|
60
|
+
}`}
|
|
61
|
+
onClick={() => handleSuggestionClick(suggestion)}
|
|
62
|
+
data-testid={suggestion[desc]}
|
|
63
|
+
>
|
|
64
|
+
{suggestion[desc]}
|
|
65
|
+
</li>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default DropdownList;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
export const DropdownIcon: React.FC<any> = (className) => {
|
|
4
|
+
return (
|
|
5
|
+
<svg
|
|
6
|
+
width="14"
|
|
7
|
+
height="12"
|
|
8
|
+
className={className}
|
|
9
|
+
viewBox="0 0 14 12"
|
|
10
|
+
fill="none"
|
|
11
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
12
|
+
>
|
|
13
|
+
<path
|
|
14
|
+
d="M13.2996 0.759638L0.699221 0.759638C0.571648 0.760037 0.446601 0.795222 0.337538 0.861405C0.228475 0.927588 0.139526 1.02226 0.080267 1.13523C0.0210075 1.24821 -0.00631905 1.37521 0.00122929 1.50256C0.00877762 1.62991 0.0509148 1.75279 0.123105 1.85797L6.42328 10.9582C6.68439 11.3355 7.31301 11.3355 7.57482 10.9582L13.875 1.85797C13.9479 1.75301 13.9907 1.63006 13.9986 1.5025C14.0066 1.37494 13.9794 1.24764 13.9201 1.13442C13.8608 1.02121 13.7716 0.926414 13.6622 0.860339C13.5528 0.794264 13.4274 0.759437 13.2996 0.759638Z"
|
|
15
|
+
fill="#003C71"
|
|
16
|
+
/>
|
|
17
|
+
</svg>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const DropSideIcon: React.FC<any> = (className) => {
|
|
22
|
+
return (
|
|
23
|
+
|
|
24
|
+
<svg
|
|
25
|
+
width="12"
|
|
26
|
+
height="14"
|
|
27
|
+
className={className}
|
|
28
|
+
viewBox="0 0 12 14"
|
|
29
|
+
fill="none"
|
|
30
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
31
|
+
>
|
|
32
|
+
<path
|
|
33
|
+
d="M0.884639 0.700422V13.3008C0.885038 13.4284 0.920223 13.5534 0.986406 13.6625C1.05259 13.7715 1.14726 13.8605 1.26024 13.9197C1.37321 13.979 1.50021 14.0063 1.62756 13.9988C1.75491 13.9912 1.87779 13.9491 1.98297 13.8769L11.0832 7.57672C11.4605 7.31561 11.4605 6.68699 11.0832 6.42518L1.98297 0.125005C1.87801 0.0520805 1.75506 0.00931579 1.6275 0.00135729C1.49994 -0.00660121 1.37264 0.0205509 1.25942 0.0798637C1.14621 0.139176 1.05142 0.228381 0.98534 0.337786C0.919266 0.447191 0.884438 0.572612 0.884639 0.700422Z"
|
|
34
|
+
fill="#003C71"
|
|
35
|
+
/>
|
|
36
|
+
</svg>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Close, DropArrow } from '../utilities/icons';
|
|
3
|
+
|
|
4
|
+
type ValueProps = {
|
|
5
|
+
inputValue: string;
|
|
6
|
+
searchValue: string;
|
|
7
|
+
dropOpen: boolean;
|
|
8
|
+
handleDropOpen: (e: any) => void;
|
|
9
|
+
handleDropClose: (e: any) => void;
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
readOnly: boolean;
|
|
12
|
+
expandable: boolean;
|
|
13
|
+
handleClear: () => void;
|
|
14
|
+
};
|
|
15
|
+
const InputActions: React.FC<ValueProps> = ({
|
|
16
|
+
inputValue,
|
|
17
|
+
searchValue,
|
|
18
|
+
dropOpen,
|
|
19
|
+
handleDropOpen,
|
|
20
|
+
handleDropClose,
|
|
21
|
+
disabled,
|
|
22
|
+
readOnly,
|
|
23
|
+
expandable,
|
|
24
|
+
handleClear,
|
|
25
|
+
}) => {
|
|
26
|
+
return (
|
|
27
|
+
<div className="qbs-autocomplete-close-icon">
|
|
28
|
+
{(inputValue || searchValue) && !disabled && !readOnly && !expandable && (
|
|
29
|
+
<button
|
|
30
|
+
onClick={handleClear}
|
|
31
|
+
className="icon-button"
|
|
32
|
+
aria-label="clear"
|
|
33
|
+
>
|
|
34
|
+
<Close />
|
|
35
|
+
</button>
|
|
36
|
+
)}
|
|
37
|
+
{dropOpen ? (
|
|
38
|
+
<button
|
|
39
|
+
type="button"
|
|
40
|
+
onClick={(e) => handleDropClose(e)}
|
|
41
|
+
className="icon-button"
|
|
42
|
+
aria-label="toggle"
|
|
43
|
+
name="toggle"
|
|
44
|
+
>
|
|
45
|
+
<DropArrow className={`icon-button-rotate`} />
|
|
46
|
+
</button>
|
|
47
|
+
) : (
|
|
48
|
+
<button
|
|
49
|
+
disabled={disabled || readOnly}
|
|
50
|
+
type="button"
|
|
51
|
+
className="icon-button"
|
|
52
|
+
onClick={(e) => handleDropOpen(e)}
|
|
53
|
+
aria-label="toggle"
|
|
54
|
+
name="toggle"
|
|
55
|
+
>
|
|
56
|
+
<DropArrow />
|
|
57
|
+
</button>
|
|
58
|
+
)}
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default InputActions;
|