react-core-ts 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.
- package/dist/AutoCompleteWithSelectedList.js +5 -2
- package/dist/AutoCompleteWithSelectedList.js.map +1 -1
- package/dist/AutoCompleteWithTreeStructure.js +5 -2
- package/dist/AutoCompleteWithTreeStructure.js.map +1 -1
- package/dist/ReactAutoComplete.d.ts +3 -3
- package/dist/ReactAutoComplete.js +93 -84
- package/dist/ReactAutoComplete.js.map +1 -1
- package/dist/commontypes.d.ts +1 -1
- package/dist/styles/styles/components/autocomplete.css +624 -0
- package/dist/styles/styles/components/selectedautocomplete.css +130 -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/AutoCompleteWithSelectedList.tsx +6 -11
- package/src/AutoCompleteWithTreeStructure.tsx +7 -11
- package/src/ReactAutoComplete.tsx +116 -105
- package/src/commontypes.ts +1 -1
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
forwardRef,
|
|
3
|
-
useCallback,
|
|
4
|
-
useEffect,
|
|
5
|
-
useImperativeHandle,
|
|
6
|
-
useRef,
|
|
7
|
-
useState,
|
|
8
|
-
} from 'react';
|
|
1
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
9
2
|
import ReactDOM from 'react-dom';
|
|
10
3
|
|
|
11
4
|
import { AutoSuggestionInputProps, TabPops, ValueProps } from './commontypes';
|
|
@@ -73,9 +66,9 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
73
66
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
74
67
|
const dropdownSelectedRef = useRef<HTMLDivElement>(null);
|
|
75
68
|
const tabRef = useRef<HTMLUListElement>(null);
|
|
69
|
+
const dropLevelRef = useRef<string>('bottom');
|
|
76
70
|
// State Hooks Section
|
|
77
71
|
const [isInitialRender, setIsInitialRender] = useState(true);
|
|
78
|
-
|
|
79
72
|
const [inputValue, setInputValue] = useState<string>(value);
|
|
80
73
|
const [searchValue, setSearchValue] = useState<string>('');
|
|
81
74
|
const [searchOldValue, setSearchOldValue] = useState<string>('');
|
|
@@ -121,9 +114,11 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
121
114
|
if (tabRef?.current) dropdownHeight += tabRef?.current?.clientHeight;
|
|
122
115
|
}
|
|
123
116
|
if (spaceBelow >= dropdownHeight) {
|
|
117
|
+
dropLevelRef.current = 'bottom';
|
|
124
118
|
dropdownPosition.top =
|
|
125
119
|
inputRect.top + window.scrollY + inputRect.height;
|
|
126
120
|
} else {
|
|
121
|
+
dropLevelRef.current = 'top';
|
|
127
122
|
dropdownPosition.top =
|
|
128
123
|
inputRect.top + window.scrollY - dropdownHeight + 73 + topMargin;
|
|
129
124
|
}
|
|
@@ -514,8 +509,8 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
514
509
|
);
|
|
515
510
|
};
|
|
516
511
|
useEffect(() => {
|
|
517
|
-
handleUpdateParent?.(dropOpen)
|
|
518
|
-
}, [dropOpen]);
|
|
512
|
+
handleUpdateParent?.(dropOpen, dropLevelRef.current)
|
|
513
|
+
}, [dropOpen, dropLevelRef.current]);
|
|
519
514
|
return (
|
|
520
515
|
<div className={fullWidth ? 'fullWidth' : 'autoWidth'} ref={dropdownRef}>
|
|
521
516
|
{label && (
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
forwardRef,
|
|
3
|
-
useCallback,
|
|
4
|
-
useEffect,
|
|
5
|
-
useImperativeHandle,
|
|
6
|
-
useRef,
|
|
7
|
-
useState,
|
|
8
|
-
} from 'react';
|
|
1
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
9
2
|
import ReactDOM from 'react-dom';
|
|
10
3
|
|
|
11
4
|
import { AutoSuggestionInputProps } from './commontypes';
|
|
@@ -80,7 +73,7 @@ const AutoCompleteWithTreeStructure = forwardRef<
|
|
|
80
73
|
const [dropDownData, setDropDownData] = useState<ValueProps[]>(data);
|
|
81
74
|
const inputRef = useRef(null);
|
|
82
75
|
const dropRef = useRef(null);
|
|
83
|
-
|
|
76
|
+
const dropLevelRef = useRef<string>('bottom');
|
|
84
77
|
useEffect(() => {
|
|
85
78
|
if (data) {
|
|
86
79
|
if (flatArray) {
|
|
@@ -91,6 +84,7 @@ const AutoCompleteWithTreeStructure = forwardRef<
|
|
|
91
84
|
}
|
|
92
85
|
}, [data, dropOpen]);
|
|
93
86
|
useImperativeHandle(ref, () => inputRef.current);
|
|
87
|
+
|
|
94
88
|
const [dropdownStyle, setDropdownStyle] = useState({
|
|
95
89
|
top: 0,
|
|
96
90
|
left: 0,
|
|
@@ -113,9 +107,11 @@ const AutoCompleteWithTreeStructure = forwardRef<
|
|
|
113
107
|
if (spaceBelow >= dropdownHeight) {
|
|
114
108
|
dropdownPosition.top =
|
|
115
109
|
inputRect.top + window.scrollY + inputRect.height;
|
|
110
|
+
dropLevelRef.current = 'bottom';
|
|
116
111
|
} else {
|
|
117
112
|
dropdownPosition.top =
|
|
118
113
|
inputRect.top + window.scrollY - dropdownHeight + 73;
|
|
114
|
+
dropLevelRef.current = 'top';
|
|
119
115
|
}
|
|
120
116
|
|
|
121
117
|
setDropdownStyle({
|
|
@@ -210,8 +206,8 @@ const AutoCompleteWithTreeStructure = forwardRef<
|
|
|
210
206
|
}
|
|
211
207
|
};
|
|
212
208
|
useEffect(() => {
|
|
213
|
-
handleUpdateParent?.(dropOpen)
|
|
214
|
-
}, [dropOpen]);
|
|
209
|
+
handleUpdateParent?.(dropOpen, dropLevelRef.current)
|
|
210
|
+
}, [dropOpen, dropLevelRef.current]);
|
|
215
211
|
const generateClassName = useCallback(() => {
|
|
216
212
|
return `qbs-textfield-default ${className} ${
|
|
217
213
|
errors && errors?.message ? 'textfield-error' : 'tree-textfield'
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef, useState } from
|
|
2
|
-
import { FieldErrors } from
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { FieldErrors } from "react-hook-form";
|
|
3
3
|
|
|
4
|
-
import CustomIcons from
|
|
5
|
-
import Spinner from
|
|
6
|
-
import Portal from
|
|
7
|
-
import { debounce } from
|
|
8
|
-
import { applyPositionClass } from
|
|
9
|
-
import { DropArrow } from
|
|
4
|
+
import CustomIcons from "./components/customIcons";
|
|
5
|
+
import Spinner from "./components/loader/Spinner";
|
|
6
|
+
import Portal from "./components/portal";
|
|
7
|
+
import { debounce } from "./utilities/debounce";
|
|
8
|
+
import { applyPositionClass } from "./utilities/getPosition";
|
|
9
|
+
import { DropArrow } from "./utilities/icons";
|
|
10
10
|
|
|
11
11
|
type valueProps = {
|
|
12
12
|
id?: string | number;
|
|
@@ -30,7 +30,7 @@ interface AutoSuggestionInputProps {
|
|
|
30
30
|
value?: valueProps;
|
|
31
31
|
onChange: (value?: valueProps) => void;
|
|
32
32
|
data?: any[];
|
|
33
|
-
type?:
|
|
33
|
+
type?: "custom_select" | "auto_complete" | "custom_search_select";
|
|
34
34
|
placeholder?: string;
|
|
35
35
|
getData?: ((key?: string) => Promise<any>) | ((key?: string) => any);
|
|
36
36
|
errors?: FieldErrors;
|
|
@@ -66,7 +66,7 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
66
66
|
placeholder,
|
|
67
67
|
id,
|
|
68
68
|
className: propsClassName,
|
|
69
|
-
type =
|
|
69
|
+
type = "custom_select",
|
|
70
70
|
readOnly,
|
|
71
71
|
disabled = false,
|
|
72
72
|
value,
|
|
@@ -83,7 +83,7 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
83
83
|
labelTitle,
|
|
84
84
|
isModern = true,
|
|
85
85
|
}) => {
|
|
86
|
-
const [inputValue, setInputValue] = useState<any>(value?.name ??
|
|
86
|
+
const [inputValue, setInputValue] = useState<any>(value?.name ?? "");
|
|
87
87
|
const [isHovered, setIsHovered] = useState<boolean>(false);
|
|
88
88
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
89
89
|
const [dropOpen, setDropOpen] = useState<boolean>(false);
|
|
@@ -96,6 +96,7 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
96
96
|
const adorementRef = useRef<HTMLDivElement>(null);
|
|
97
97
|
const dropdownref = useRef<HTMLDivElement>(null);
|
|
98
98
|
const dropBtnRef = useRef<HTMLButtonElement>(null);
|
|
99
|
+
const timerRef = useRef<number>(0); // To fix the no results found issue on second type
|
|
99
100
|
const [dropPosition, setDropPosition] = useState<any>({
|
|
100
101
|
top: 0,
|
|
101
102
|
left: 0,
|
|
@@ -116,8 +117,8 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
116
117
|
) => {
|
|
117
118
|
return substring &&
|
|
118
119
|
mainString &&
|
|
119
|
-
typeof mainString ===
|
|
120
|
-
typeof subString ===
|
|
120
|
+
typeof mainString === "string" &&
|
|
121
|
+
typeof subString === "string"
|
|
121
122
|
? mainString
|
|
122
123
|
.toString()
|
|
123
124
|
.toLowerCase()
|
|
@@ -132,25 +133,26 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
132
133
|
return (
|
|
133
134
|
checkIncludesIfExists(mainString, subString) ||
|
|
134
135
|
(!!checkParams &&
|
|
135
|
-
((checkArrayContains(checkParams,
|
|
136
|
+
((checkArrayContains(checkParams, "param1") &&
|
|
136
137
|
checkIncludesIfExists(param1, subString)) ||
|
|
137
|
-
(checkArrayContains(checkParams,
|
|
138
|
+
(checkArrayContains(checkParams, "param2") &&
|
|
138
139
|
checkIncludesIfExists(param2, subString)) ||
|
|
139
|
-
(checkArrayContains(checkParams,
|
|
140
|
+
(checkArrayContains(checkParams, "param3") &&
|
|
140
141
|
checkIncludesIfExists(param3, subString)) ||
|
|
141
|
-
(checkArrayContains(checkParams,
|
|
142
|
+
(checkArrayContains(checkParams, "param4") &&
|
|
142
143
|
checkIncludesIfExists(param4, subString))))
|
|
143
144
|
);
|
|
144
145
|
};
|
|
145
146
|
|
|
146
147
|
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
147
148
|
const { value } = event.target;
|
|
149
|
+
timerRef.current = 0;
|
|
148
150
|
|
|
149
151
|
setInputValue(value);
|
|
150
152
|
handleValChange(value);
|
|
151
153
|
if (!value) {
|
|
152
|
-
setInputValue(
|
|
153
|
-
onChange({ id: undefined, name:
|
|
154
|
+
setInputValue("");
|
|
155
|
+
onChange({ id: undefined, name: "", from: 2 });
|
|
154
156
|
}
|
|
155
157
|
};
|
|
156
158
|
|
|
@@ -158,28 +160,31 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
158
160
|
debounce(
|
|
159
161
|
(value: string) => {
|
|
160
162
|
setDropOpen(true);
|
|
161
|
-
onChange({ id: undefined, name:
|
|
162
|
-
if (value.trim() ===
|
|
163
|
+
onChange({ id: undefined, name: "", from: 1 });
|
|
164
|
+
if (value.trim() === "" && type === "auto_complete") {
|
|
163
165
|
setSuggestions([]);
|
|
164
166
|
if (autoFilter) {
|
|
165
|
-
handleDropData(
|
|
167
|
+
handleDropData("*");
|
|
166
168
|
} else {
|
|
167
169
|
setDropOpen(false);
|
|
168
170
|
}
|
|
169
171
|
} else {
|
|
170
172
|
handleDropData(value);
|
|
171
173
|
}
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
timerRef.current = 1;
|
|
176
|
+
}, 200);
|
|
172
177
|
},
|
|
173
178
|
isStaticList ? 0 : 1000
|
|
174
179
|
),
|
|
175
180
|
[]
|
|
176
181
|
);
|
|
177
182
|
const handleDropData = (value?: string) => {
|
|
178
|
-
if (type ===
|
|
183
|
+
if (type === "auto_complete") {
|
|
179
184
|
if (isStaticList) {
|
|
180
185
|
loadStaticData();
|
|
181
186
|
const filteredData =
|
|
182
|
-
value && value !==
|
|
187
|
+
value && value !== "*"
|
|
183
188
|
? data?.filter((item) =>
|
|
184
189
|
checkIncludes(
|
|
185
190
|
item.name,
|
|
@@ -193,13 +198,13 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
193
198
|
setSuggestions(filteredData);
|
|
194
199
|
} else handlePickSuggestions(value);
|
|
195
200
|
} else if (
|
|
196
|
-
(type ===
|
|
201
|
+
(type === "custom_select" || type === "custom_search_select") &&
|
|
197
202
|
(!data || data?.length === 0)
|
|
198
203
|
) {
|
|
199
204
|
handlePickSuggestions();
|
|
200
|
-
} else if (type ===
|
|
205
|
+
} else if (type === "custom_search_select" && data && data?.length > 0) {
|
|
201
206
|
const filteredData =
|
|
202
|
-
value && value !==
|
|
207
|
+
value && value !== "*"
|
|
203
208
|
? data.filter((item) =>
|
|
204
209
|
checkIncludes(
|
|
205
210
|
item.name,
|
|
@@ -229,10 +234,10 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
229
234
|
const onLabelClick = () => {
|
|
230
235
|
if (!isDisabled) {
|
|
231
236
|
inputRef?.current?.focus();
|
|
232
|
-
if (autoFilter && inputValue ===
|
|
233
|
-
handleValChange(
|
|
237
|
+
if (autoFilter && inputValue === "") {
|
|
238
|
+
handleValChange("*");
|
|
234
239
|
} else if (
|
|
235
|
-
(type ===
|
|
240
|
+
(type === "custom_select" || type === "custom_search_select") &&
|
|
236
241
|
data &&
|
|
237
242
|
data?.length > 0
|
|
238
243
|
) {
|
|
@@ -259,8 +264,8 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
259
264
|
if (getData) {
|
|
260
265
|
try {
|
|
261
266
|
setIsLoading(true);
|
|
262
|
-
handlePickSuggestions(
|
|
263
|
-
const fetchedSuggestions = await getData?.(
|
|
267
|
+
handlePickSuggestions("*");
|
|
268
|
+
const fetchedSuggestions = await getData?.("*");
|
|
264
269
|
fetchedSuggestions?.forEach((element: any) => {
|
|
265
270
|
data?.push(element);
|
|
266
271
|
});
|
|
@@ -272,9 +277,9 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
272
277
|
}
|
|
273
278
|
};
|
|
274
279
|
useEffect(() => {
|
|
275
|
-
document.addEventListener(
|
|
280
|
+
document.addEventListener("click", handleClickOutside);
|
|
276
281
|
return () => {
|
|
277
|
-
document.removeEventListener(
|
|
282
|
+
document.removeEventListener("click", handleClickOutside);
|
|
278
283
|
};
|
|
279
284
|
}, []);
|
|
280
285
|
|
|
@@ -285,10 +290,10 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
285
290
|
}, [autoFocus]);
|
|
286
291
|
const onInputFocus = () => {
|
|
287
292
|
if (!isDisabled) {
|
|
288
|
-
if (autoFilter && inputValue ===
|
|
289
|
-
handleValChange(
|
|
293
|
+
if (autoFilter && inputValue === "") {
|
|
294
|
+
handleValChange("*");
|
|
290
295
|
} else if (
|
|
291
|
-
(type ===
|
|
296
|
+
(type === "custom_select" || type === "custom_search_select") &&
|
|
292
297
|
data &&
|
|
293
298
|
data?.length > 0
|
|
294
299
|
) {
|
|
@@ -307,14 +312,14 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
307
312
|
name: suggestion.name,
|
|
308
313
|
...(suggestion?.label ? { label: suggestion?.label } : {}),
|
|
309
314
|
});
|
|
310
|
-
if (type !==
|
|
315
|
+
if (type !== "custom_select") setInputValue(suggestion.name);
|
|
311
316
|
setDropOpen(false);
|
|
312
317
|
};
|
|
313
318
|
const handleOpen = (e: any) => {
|
|
314
319
|
if (!suggestions || suggestions?.length === 0) handleDropData();
|
|
315
320
|
if (!isLoading) {
|
|
316
321
|
setDropOpen(!dropOpen);
|
|
317
|
-
if (type !==
|
|
322
|
+
if (type !== "custom_select") setInputValue("");
|
|
318
323
|
}
|
|
319
324
|
};
|
|
320
325
|
|
|
@@ -324,27 +329,27 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
324
329
|
|
|
325
330
|
useEffect(() => {
|
|
326
331
|
if (!insideOpen) {
|
|
327
|
-
window.addEventListener(
|
|
332
|
+
window.addEventListener("scroll", handleScroll);
|
|
328
333
|
|
|
329
|
-
const mainElement = document.querySelector(
|
|
330
|
-
mainElement?.addEventListener(
|
|
334
|
+
const mainElement = document.querySelector("main");
|
|
335
|
+
mainElement?.addEventListener("scroll", handleScroll);
|
|
331
336
|
|
|
332
337
|
const gridElements = document.querySelectorAll(
|
|
333
|
-
|
|
338
|
+
".k-grid-content, .overflow-auto, .overflow-y-auto, .overflow-x-auto"
|
|
334
339
|
);
|
|
335
340
|
gridElements.forEach((gridElement: any) => {
|
|
336
|
-
gridElement.addEventListener(
|
|
341
|
+
gridElement.addEventListener("scroll", handleScroll);
|
|
337
342
|
});
|
|
338
|
-
window.addEventListener(
|
|
343
|
+
window.addEventListener("resize", getDropPosition);
|
|
339
344
|
getDropPosition();
|
|
340
345
|
return () => {
|
|
341
|
-
window.removeEventListener(
|
|
342
|
-
const mainElement = document.querySelector(
|
|
343
|
-
mainElement?.removeEventListener(
|
|
344
|
-
window.addEventListener(
|
|
345
|
-
const gridElements = document.querySelectorAll(
|
|
346
|
+
window.removeEventListener("scroll", handleScroll);
|
|
347
|
+
const mainElement = document.querySelector("main");
|
|
348
|
+
mainElement?.removeEventListener("scroll", handleScroll);
|
|
349
|
+
window.addEventListener("resize", getDropPosition);
|
|
350
|
+
const gridElements = document.querySelectorAll(".k-grid-content");
|
|
346
351
|
gridElements.forEach((gridElement: any) => {
|
|
347
|
-
gridElement.removeEventListener(
|
|
352
|
+
gridElement.removeEventListener("scroll", handleScroll);
|
|
348
353
|
});
|
|
349
354
|
};
|
|
350
355
|
}
|
|
@@ -352,13 +357,13 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
352
357
|
|
|
353
358
|
const handleClear = () => {
|
|
354
359
|
setDropOpen(false);
|
|
355
|
-
setInputValue(
|
|
356
|
-
onChange({ id: undefined, name:
|
|
360
|
+
setInputValue("");
|
|
361
|
+
onChange({ id: undefined, name: "", from: 3 });
|
|
357
362
|
onLabelClick();
|
|
358
363
|
};
|
|
359
364
|
|
|
360
365
|
useEffect(() => {
|
|
361
|
-
setInputValue(value?.name ??
|
|
366
|
+
setInputValue(value?.name ?? "");
|
|
362
367
|
}, [value?.name]);
|
|
363
368
|
|
|
364
369
|
useEffect(() => {
|
|
@@ -366,7 +371,7 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
366
371
|
}, [data]);
|
|
367
372
|
|
|
368
373
|
const getErrors = (err: any) => {
|
|
369
|
-
let errMsg =
|
|
374
|
+
let errMsg = "";
|
|
370
375
|
if (err.message) {
|
|
371
376
|
errMsg = err?.message;
|
|
372
377
|
} else if (err?.id?.message) {
|
|
@@ -377,59 +382,59 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
377
382
|
return errMsg;
|
|
378
383
|
};
|
|
379
384
|
const generateClassName = (
|
|
380
|
-
type:
|
|
385
|
+
type: "input" | "label" | "message" | "adorement"
|
|
381
386
|
): string => {
|
|
382
387
|
let className = propsClassName;
|
|
383
388
|
switch (type) {
|
|
384
|
-
case
|
|
389
|
+
case "input":
|
|
385
390
|
className += `block text-common text-input-text font-normal px-3.5 w-full text-sm text-gray-900 bg-transparent border appearance-none peer h-10 rounded-[4px] disabled:text-input-disabled bg-white disabled:bg-disabled ${
|
|
386
391
|
label && isModern
|
|
387
|
-
?
|
|
388
|
-
:
|
|
392
|
+
? "placeholder-transparent"
|
|
393
|
+
: "focus:placeholder-grey-secondary placeholder-input-label"
|
|
389
394
|
} focus:placeholder-grey-secondary`;
|
|
390
395
|
|
|
391
396
|
if (errors && errors[name]) {
|
|
392
397
|
className +=
|
|
393
|
-
|
|
398
|
+
" border-[#FDA29B] focus:border-error-[#FDA29B] focus:ring-[#FDA29B] focus:ring-3 focus:outline-[#FDA29B] input-outline";
|
|
394
399
|
} else {
|
|
395
400
|
className +=
|
|
396
|
-
|
|
401
|
+
" text-grey-dark border-input-light focus:border-blue-navy focus:outline-none focus:ring-0";
|
|
397
402
|
}
|
|
398
403
|
|
|
399
404
|
break;
|
|
400
|
-
case
|
|
405
|
+
case "label":
|
|
401
406
|
className += ` modern-input-label peer-focus:modern-input-peer-focus-label-size
|
|
402
407
|
${
|
|
403
408
|
isDisabled
|
|
404
|
-
?
|
|
405
|
-
:
|
|
409
|
+
? "cursor-pointer"
|
|
410
|
+
: "cursor-text peer-focus:cursor-pointer"
|
|
406
411
|
} ${
|
|
407
412
|
!isDisabled || !checkIsEmptyField()
|
|
408
|
-
?
|
|
413
|
+
? "active-input-label-bg"
|
|
409
414
|
: isDisabled && !checkIsEmptyField()
|
|
410
|
-
?
|
|
411
|
-
:
|
|
415
|
+
? "disabled-input-label-bg"
|
|
416
|
+
: ""
|
|
412
417
|
} absolute duration-300 transform -translate-y-4 top-2 z-1 origin-[0] px-0 peer-placeholder-shown:-translate-y-1/2 peer-placeholder-shown:top-1/2 peer-focus:top-2 peer-focus:-translate-y-4 start-[14px] rtl:peer-focus:translate-x-1/4 rtl:peer-focus:left-auto ${
|
|
413
418
|
isDisabled
|
|
414
|
-
?
|
|
415
|
-
:
|
|
419
|
+
? "cursor-pointer"
|
|
420
|
+
: "cursor-text peer-focus:cursor-pointer"
|
|
416
421
|
}
|
|
417
422
|
${
|
|
418
423
|
checkIsEmptyField()
|
|
419
|
-
?
|
|
420
|
-
:
|
|
424
|
+
? "modern-input-label-size"
|
|
425
|
+
: "modern-input-peer-focus-label-size"
|
|
421
426
|
}`;
|
|
422
427
|
if (errors && errors[name]) {
|
|
423
|
-
className +=
|
|
428
|
+
className += " text-error-light ";
|
|
424
429
|
} else {
|
|
425
|
-
className +=
|
|
430
|
+
className += " text-grey-dark peer-focus:text-blue-navy";
|
|
426
431
|
}
|
|
427
432
|
break;
|
|
428
|
-
case
|
|
429
|
-
className =
|
|
433
|
+
case "message":
|
|
434
|
+
className = " text-error-icon ";
|
|
430
435
|
break;
|
|
431
|
-
case
|
|
432
|
-
className +=
|
|
436
|
+
case "adorement":
|
|
437
|
+
className += " absolute right-0 adorement gap-1 flex items-center ";
|
|
433
438
|
break;
|
|
434
439
|
default:
|
|
435
440
|
break;
|
|
@@ -454,27 +459,27 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
454
459
|
// return 'bottom'
|
|
455
460
|
// }
|
|
456
461
|
const filteredData =
|
|
457
|
-
inputValue !==
|
|
462
|
+
inputValue !== "*" && type !== "custom_select" && !noLocalFilter
|
|
458
463
|
? suggestions?.filter((item: valueProps) =>
|
|
459
464
|
checkIncludes(
|
|
460
465
|
item.name,
|
|
461
466
|
inputValue,
|
|
462
|
-
item.param1 ??
|
|
463
|
-
item.param2 ??
|
|
464
|
-
item.param3 ??
|
|
465
|
-
item.param4 ??
|
|
467
|
+
item.param1 ?? "",
|
|
468
|
+
item.param2 ?? "",
|
|
469
|
+
item.param3 ?? "",
|
|
470
|
+
item.param4 ?? ""
|
|
466
471
|
)
|
|
467
472
|
)
|
|
468
473
|
: suggestions;
|
|
469
474
|
|
|
470
475
|
const handleError = (data: any) => {
|
|
471
476
|
if (
|
|
472
|
-
getErrors(data[name]) ===
|
|
473
|
-
getErrors(data[name]) ===
|
|
477
|
+
getErrors(data[name]) === "required" ||
|
|
478
|
+
getErrors(data[name]) === "Required"
|
|
474
479
|
) {
|
|
475
480
|
return `${label ?? labelTitle} is ${getErrors(data[name])}`;
|
|
476
481
|
} else {
|
|
477
|
-
return getErrors(data[name]) ??
|
|
482
|
+
return getErrors(data[name]) ?? "";
|
|
478
483
|
}
|
|
479
484
|
};
|
|
480
485
|
|
|
@@ -508,7 +513,12 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
508
513
|
const [showNoResults, setShowNoResults] = useState(false);
|
|
509
514
|
|
|
510
515
|
useEffect(() => {
|
|
511
|
-
if (
|
|
516
|
+
if (
|
|
517
|
+
inputValue &&
|
|
518
|
+
filteredData?.length === 0 &&
|
|
519
|
+
!isLoading &&
|
|
520
|
+
showNoResults
|
|
521
|
+
) {
|
|
512
522
|
const timer = setTimeout(() => {
|
|
513
523
|
setShowNoResults(true);
|
|
514
524
|
}, 500); // Delay in milliseconds
|
|
@@ -530,8 +540,8 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
530
540
|
<li
|
|
531
541
|
className={`${
|
|
532
542
|
value?.id === suggestion?.id
|
|
533
|
-
?
|
|
534
|
-
:
|
|
543
|
+
? "bg-blue-navy text-white"
|
|
544
|
+
: "hover:bg-table-hover"
|
|
535
545
|
} cursor-pointer p-1 text-xxs ps-3.5 pl-[10px]`}
|
|
536
546
|
key={suggestion?.id}
|
|
537
547
|
data-testid={suggestion.name}
|
|
@@ -543,7 +553,8 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
543
553
|
</>
|
|
544
554
|
) : (
|
|
545
555
|
showNoResults &&
|
|
546
|
-
!isLoading &&
|
|
556
|
+
!isLoading &&
|
|
557
|
+
timerRef.current === 1 && (
|
|
547
558
|
<li
|
|
548
559
|
className={`$ cursor-pointer p-1 rounded-sm text-xxs`}
|
|
549
560
|
onClick={handleClose}
|
|
@@ -578,7 +589,7 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
578
589
|
useEffect(() => {
|
|
579
590
|
const shouldShowClose =
|
|
580
591
|
value?.name &&
|
|
581
|
-
(value?.id || String(value?.id) ===
|
|
592
|
+
(value?.id || String(value?.id) === "0") &&
|
|
582
593
|
!disabled &&
|
|
583
594
|
!readOnly &&
|
|
584
595
|
isClose;
|
|
@@ -589,7 +600,7 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
589
600
|
|
|
590
601
|
return (
|
|
591
602
|
<div
|
|
592
|
-
className={` flex-grow ${fullWidth ?
|
|
603
|
+
className={` flex-grow ${fullWidth ? "w-full" : "w-auto"}`}
|
|
593
604
|
ref={dropdownref}
|
|
594
605
|
>
|
|
595
606
|
{label && !isModern && (
|
|
@@ -606,15 +617,15 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
606
617
|
)}
|
|
607
618
|
|
|
608
619
|
<div
|
|
609
|
-
className={`flex relative ${fullWidth ?
|
|
620
|
+
className={`flex relative ${fullWidth ? "w-full" : "w-auto"}`}
|
|
610
621
|
style={{ width: width }}
|
|
611
622
|
>
|
|
612
623
|
<div className="relative w-full">
|
|
613
624
|
<input
|
|
614
625
|
id={id}
|
|
615
626
|
type="text"
|
|
616
|
-
readOnly={readOnly ?? type ===
|
|
617
|
-
value={inputValue ? inputValue :
|
|
627
|
+
readOnly={readOnly ?? type === "custom_select"}
|
|
628
|
+
value={inputValue ? inputValue : ""}
|
|
618
629
|
onBlur={handleClearInputValue}
|
|
619
630
|
disabled={disabled}
|
|
620
631
|
ref={inputRef}
|
|
@@ -633,18 +644,18 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
633
644
|
}
|
|
634
645
|
: {}),
|
|
635
646
|
}}
|
|
636
|
-
className={` ${generateClassName(
|
|
647
|
+
className={` ${generateClassName("input")}`}
|
|
637
648
|
onChange={handleChange}
|
|
638
649
|
placeholder={
|
|
639
|
-
type ===
|
|
650
|
+
type === "auto_complete"
|
|
640
651
|
? placeholder && isCustomPlaceholder
|
|
641
652
|
? placeholder
|
|
642
|
-
:
|
|
643
|
-
: placeholder ??
|
|
653
|
+
: "Type to search"
|
|
654
|
+
: placeholder ?? "--Select--"
|
|
644
655
|
}
|
|
645
656
|
onFocus={onInputFocus}
|
|
646
657
|
onClick={(e) => {
|
|
647
|
-
if (type ===
|
|
658
|
+
if (type === "custom_select") {
|
|
648
659
|
setDropOpen(!dropOpen);
|
|
649
660
|
handleOpen(e);
|
|
650
661
|
} else {
|
|
@@ -656,9 +667,9 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
656
667
|
<label
|
|
657
668
|
htmlFor={id}
|
|
658
669
|
onClick={() => onLabelClick()}
|
|
659
|
-
className={generateClassName(
|
|
670
|
+
className={generateClassName("label")}
|
|
660
671
|
>
|
|
661
|
-
{label ? label :
|
|
672
|
+
{label ? label : ""}
|
|
662
673
|
{required ? <span className="text-error"> *</span> : <></>}
|
|
663
674
|
</label>
|
|
664
675
|
)}
|
|
@@ -667,9 +678,9 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
667
678
|
<div
|
|
668
679
|
ref={adorementRef}
|
|
669
680
|
className={`${generateClassName(
|
|
670
|
-
|
|
681
|
+
"adorement"
|
|
671
682
|
)} qbs-autocomplete-adorement mr-[1px] ${
|
|
672
|
-
isLoading ?
|
|
683
|
+
isLoading ? "bg-white" : ""
|
|
673
684
|
}`}
|
|
674
685
|
>
|
|
675
686
|
{showClose && (
|
|
@@ -683,7 +694,7 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
683
694
|
</button>
|
|
684
695
|
)}
|
|
685
696
|
{isLoading && <Spinner />}
|
|
686
|
-
{type !==
|
|
697
|
+
{type !== "auto_complete" && !disabled && !readOnly && (
|
|
687
698
|
<button
|
|
688
699
|
disabled={disabled ?? readOnly}
|
|
689
700
|
onClick={(e) => handleOpen(e)}
|
|
@@ -703,7 +714,7 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
703
714
|
{errors && errors[name] && (
|
|
704
715
|
<div
|
|
705
716
|
className={` text-error-label relative cursor-pointer ${generateClassName(
|
|
706
|
-
|
|
717
|
+
"message"
|
|
707
718
|
)}`}
|
|
708
719
|
onMouseEnter={() => setIsHovered(true)}
|
|
709
720
|
onMouseLeave={() => setIsHovered(false)}
|
package/src/commontypes.ts
CHANGED
|
@@ -63,7 +63,7 @@ export interface AutoSuggestionInputProps {
|
|
|
63
63
|
currentTab?: number; // current active tab
|
|
64
64
|
selectedLabel?: string; // Able to change the "Item selected" label
|
|
65
65
|
viewMode?: boolean; // show only selected items
|
|
66
|
-
handleUpdateParent?: (val:boolean) => void;
|
|
66
|
+
handleUpdateParent?: (val: boolean, level?: string) => void;
|
|
67
67
|
}
|
|
68
68
|
export interface IconsProps {
|
|
69
69
|
name: any;
|