react-core-ts 1.3.21 → 1.3.23
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.js +51 -32
- package/dist/AutoCompleteWithTreeStructure.js.map +1 -1
- package/dist/ReactAutoComplete.d.ts +3 -3
- package/dist/ReactAutoComplete.js +85 -83
- package/dist/ReactAutoComplete.js.map +1 -1
- package/dist/components/TreeNode.js +1 -1
- package/dist/components/TreeNode.js.map +1 -1
- package/package.json +1 -1
- package/src/AutoCompleteWithTreeStructure.tsx +37 -28
- package/src/ReactAutoComplete.tsx +109 -105
- package/src/components/TreeNode.tsx +1 -1
|
@@ -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;
|
|
@@ -16,7 +16,7 @@ type valueProps = {
|
|
|
16
16
|
param2?: string | number | null;
|
|
17
17
|
param3?: string | number | null;
|
|
18
18
|
param4?: string | number | null;
|
|
19
|
-
from?: number
|
|
19
|
+
from?: number;
|
|
20
20
|
};
|
|
21
21
|
interface AutoSuggestionInputProps {
|
|
22
22
|
id?: string;
|
|
@@ -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);
|
|
@@ -115,8 +115,8 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
115
115
|
) => {
|
|
116
116
|
return substring &&
|
|
117
117
|
mainString &&
|
|
118
|
-
typeof mainString ===
|
|
119
|
-
typeof subString ===
|
|
118
|
+
typeof mainString === "string" &&
|
|
119
|
+
typeof subString === "string"
|
|
120
120
|
? mainString
|
|
121
121
|
.toString()
|
|
122
122
|
.toLowerCase()
|
|
@@ -131,13 +131,13 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
131
131
|
return (
|
|
132
132
|
checkIncludesIfExists(mainString, subString) ||
|
|
133
133
|
(!!checkParams &&
|
|
134
|
-
((checkArrayContains(checkParams,
|
|
134
|
+
((checkArrayContains(checkParams, "param1") &&
|
|
135
135
|
checkIncludesIfExists(param1, subString)) ||
|
|
136
|
-
(checkArrayContains(checkParams,
|
|
136
|
+
(checkArrayContains(checkParams, "param2") &&
|
|
137
137
|
checkIncludesIfExists(param2, subString)) ||
|
|
138
|
-
(checkArrayContains(checkParams,
|
|
138
|
+
(checkArrayContains(checkParams, "param3") &&
|
|
139
139
|
checkIncludesIfExists(param3, subString)) ||
|
|
140
|
-
(checkArrayContains(checkParams,
|
|
140
|
+
(checkArrayContains(checkParams, "param4") &&
|
|
141
141
|
checkIncludesIfExists(param4, subString))))
|
|
142
142
|
);
|
|
143
143
|
};
|
|
@@ -148,8 +148,8 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
148
148
|
setInputValue(value);
|
|
149
149
|
handleValChange(value);
|
|
150
150
|
if (!value) {
|
|
151
|
-
setInputValue(
|
|
152
|
-
onChange({ id: undefined, name:
|
|
151
|
+
setInputValue("");
|
|
152
|
+
onChange({ id: undefined, name: "", from: 2 });
|
|
153
153
|
}
|
|
154
154
|
};
|
|
155
155
|
|
|
@@ -157,11 +157,11 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
157
157
|
debounce(
|
|
158
158
|
(value: string) => {
|
|
159
159
|
setDropOpen(true);
|
|
160
|
-
onChange({ id: undefined, name:
|
|
161
|
-
if (value.trim() ===
|
|
160
|
+
onChange({ id: undefined, name: "", from: 1 });
|
|
161
|
+
if (value.trim() === "" && type === "auto_complete") {
|
|
162
162
|
setSuggestions([]);
|
|
163
163
|
if (autoFilter) {
|
|
164
|
-
handleDropData(
|
|
164
|
+
handleDropData("*");
|
|
165
165
|
} else {
|
|
166
166
|
setDropOpen(false);
|
|
167
167
|
}
|
|
@@ -174,11 +174,11 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
174
174
|
[]
|
|
175
175
|
);
|
|
176
176
|
const handleDropData = (value?: string) => {
|
|
177
|
-
if (type ===
|
|
177
|
+
if (type === "auto_complete") {
|
|
178
178
|
if (isStaticList) {
|
|
179
179
|
loadStaticData();
|
|
180
180
|
const filteredData =
|
|
181
|
-
value && value !==
|
|
181
|
+
value && value !== "*"
|
|
182
182
|
? data?.filter((item) =>
|
|
183
183
|
checkIncludes(
|
|
184
184
|
item.name,
|
|
@@ -192,13 +192,13 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
192
192
|
setSuggestions(filteredData);
|
|
193
193
|
} else handlePickSuggestions(value);
|
|
194
194
|
} else if (
|
|
195
|
-
(type ===
|
|
195
|
+
(type === "custom_select" || type === "custom_search_select") &&
|
|
196
196
|
(!data || data?.length === 0)
|
|
197
197
|
) {
|
|
198
198
|
handlePickSuggestions();
|
|
199
|
-
} else if (type ===
|
|
199
|
+
} else if (type === "custom_search_select" && data && data?.length > 0) {
|
|
200
200
|
const filteredData =
|
|
201
|
-
value && value !==
|
|
201
|
+
value && value !== "*"
|
|
202
202
|
? data.filter((item) =>
|
|
203
203
|
checkIncludes(
|
|
204
204
|
item.name,
|
|
@@ -228,10 +228,10 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
228
228
|
const onLabelClick = () => {
|
|
229
229
|
if (!isDisabled) {
|
|
230
230
|
inputRef?.current?.focus();
|
|
231
|
-
if (autoFilter && inputValue ===
|
|
232
|
-
handleValChange(
|
|
231
|
+
if (autoFilter && inputValue === "") {
|
|
232
|
+
handleValChange("*");
|
|
233
233
|
} else if (
|
|
234
|
-
(type ===
|
|
234
|
+
(type === "custom_select" || type === "custom_search_select") &&
|
|
235
235
|
data &&
|
|
236
236
|
data?.length > 0
|
|
237
237
|
) {
|
|
@@ -258,8 +258,8 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
258
258
|
if (getData) {
|
|
259
259
|
try {
|
|
260
260
|
setIsLoading(true);
|
|
261
|
-
handlePickSuggestions(
|
|
262
|
-
const fetchedSuggestions = await getData?.(
|
|
261
|
+
handlePickSuggestions("*");
|
|
262
|
+
const fetchedSuggestions = await getData?.("*");
|
|
263
263
|
fetchedSuggestions?.forEach((element: any) => {
|
|
264
264
|
data?.push(element);
|
|
265
265
|
});
|
|
@@ -271,9 +271,9 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
271
271
|
}
|
|
272
272
|
};
|
|
273
273
|
useEffect(() => {
|
|
274
|
-
document.addEventListener(
|
|
274
|
+
document.addEventListener("click", handleClickOutside);
|
|
275
275
|
return () => {
|
|
276
|
-
document.removeEventListener(
|
|
276
|
+
document.removeEventListener("click", handleClickOutside);
|
|
277
277
|
};
|
|
278
278
|
}, []);
|
|
279
279
|
|
|
@@ -284,10 +284,10 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
284
284
|
}, [autoFocus]);
|
|
285
285
|
const onInputFocus = () => {
|
|
286
286
|
if (!isDisabled) {
|
|
287
|
-
if (autoFilter && inputValue ===
|
|
288
|
-
handleValChange(
|
|
287
|
+
if (autoFilter && inputValue === "") {
|
|
288
|
+
handleValChange("*");
|
|
289
289
|
} else if (
|
|
290
|
-
(type ===
|
|
290
|
+
(type === "custom_select" || type === "custom_search_select") &&
|
|
291
291
|
data &&
|
|
292
292
|
data?.length > 0
|
|
293
293
|
) {
|
|
@@ -306,14 +306,14 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
306
306
|
name: suggestion.name,
|
|
307
307
|
...(suggestion?.label ? { label: suggestion?.label } : {}),
|
|
308
308
|
});
|
|
309
|
-
if (type !==
|
|
309
|
+
if (type !== "custom_select") setInputValue(suggestion.name);
|
|
310
310
|
setDropOpen(false);
|
|
311
311
|
};
|
|
312
312
|
const handleOpen = (e: any) => {
|
|
313
313
|
if (!suggestions || suggestions?.length === 0) handleDropData();
|
|
314
314
|
if (!isLoading) {
|
|
315
315
|
setDropOpen(!dropOpen);
|
|
316
|
-
if (type !==
|
|
316
|
+
if (type !== "custom_select") setInputValue("");
|
|
317
317
|
}
|
|
318
318
|
};
|
|
319
319
|
|
|
@@ -323,25 +323,27 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
323
323
|
|
|
324
324
|
useEffect(() => {
|
|
325
325
|
if (!insideOpen) {
|
|
326
|
-
window.addEventListener(
|
|
326
|
+
window.addEventListener("scroll", handleScroll);
|
|
327
327
|
|
|
328
|
-
const mainElement = document.querySelector(
|
|
329
|
-
mainElement?.addEventListener(
|
|
328
|
+
const mainElement = document.querySelector("main");
|
|
329
|
+
mainElement?.addEventListener("scroll", handleScroll);
|
|
330
330
|
|
|
331
|
-
const gridElements = document.querySelectorAll(
|
|
331
|
+
const gridElements = document.querySelectorAll(
|
|
332
|
+
".k-grid-content, .overflow-auto, .overflow-y-auto, .overflow-x-auto"
|
|
333
|
+
);
|
|
332
334
|
gridElements.forEach((gridElement: any) => {
|
|
333
|
-
gridElement.addEventListener(
|
|
335
|
+
gridElement.addEventListener("scroll", handleScroll);
|
|
334
336
|
});
|
|
335
|
-
window.addEventListener(
|
|
337
|
+
window.addEventListener("resize", getDropPosition);
|
|
336
338
|
getDropPosition();
|
|
337
339
|
return () => {
|
|
338
|
-
window.removeEventListener(
|
|
339
|
-
const mainElement = document.querySelector(
|
|
340
|
-
mainElement?.removeEventListener(
|
|
341
|
-
window.addEventListener(
|
|
342
|
-
const gridElements = document.querySelectorAll(
|
|
340
|
+
window.removeEventListener("scroll", handleScroll);
|
|
341
|
+
const mainElement = document.querySelector("main");
|
|
342
|
+
mainElement?.removeEventListener("scroll", handleScroll);
|
|
343
|
+
window.addEventListener("resize", getDropPosition);
|
|
344
|
+
const gridElements = document.querySelectorAll(".k-grid-content");
|
|
343
345
|
gridElements.forEach((gridElement: any) => {
|
|
344
|
-
gridElement.removeEventListener(
|
|
346
|
+
gridElement.removeEventListener("scroll", handleScroll);
|
|
345
347
|
});
|
|
346
348
|
};
|
|
347
349
|
}
|
|
@@ -349,13 +351,13 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
349
351
|
|
|
350
352
|
const handleClear = () => {
|
|
351
353
|
setDropOpen(false);
|
|
352
|
-
setInputValue(
|
|
353
|
-
onChange({ id: undefined, name:
|
|
354
|
+
setInputValue("");
|
|
355
|
+
onChange({ id: undefined, name: "", from: 3 });
|
|
354
356
|
onLabelClick();
|
|
355
357
|
};
|
|
356
358
|
|
|
357
359
|
useEffect(() => {
|
|
358
|
-
setInputValue(value?.name ??
|
|
360
|
+
setInputValue(value?.name ?? "");
|
|
359
361
|
}, [value?.name]);
|
|
360
362
|
|
|
361
363
|
useEffect(() => {
|
|
@@ -363,7 +365,7 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
363
365
|
}, [data]);
|
|
364
366
|
|
|
365
367
|
const getErrors = (err: any) => {
|
|
366
|
-
let errMsg =
|
|
368
|
+
let errMsg = "";
|
|
367
369
|
if (err.message) {
|
|
368
370
|
errMsg = err?.message;
|
|
369
371
|
} else if (err?.id?.message) {
|
|
@@ -374,59 +376,59 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
374
376
|
return errMsg;
|
|
375
377
|
};
|
|
376
378
|
const generateClassName = (
|
|
377
|
-
type:
|
|
379
|
+
type: "input" | "label" | "message" | "adorement"
|
|
378
380
|
): string => {
|
|
379
381
|
let className = propsClassName;
|
|
380
382
|
switch (type) {
|
|
381
|
-
case
|
|
383
|
+
case "input":
|
|
382
384
|
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 ${
|
|
383
385
|
label && isModern
|
|
384
|
-
?
|
|
385
|
-
:
|
|
386
|
+
? "placeholder-transparent"
|
|
387
|
+
: "focus:placeholder-grey-secondary placeholder-input-label"
|
|
386
388
|
} focus:placeholder-grey-secondary`;
|
|
387
389
|
|
|
388
390
|
if (errors && errors[name]) {
|
|
389
391
|
className +=
|
|
390
|
-
|
|
392
|
+
" border-[#FDA29B] focus:border-error-[#FDA29B] focus:ring-[#FDA29B] focus:ring-3 focus:outline-[#FDA29B] input-outline";
|
|
391
393
|
} else {
|
|
392
394
|
className +=
|
|
393
|
-
|
|
395
|
+
" text-grey-dark border-input-light focus:border-blue-navy focus:outline-none focus:ring-0";
|
|
394
396
|
}
|
|
395
397
|
|
|
396
398
|
break;
|
|
397
|
-
case
|
|
399
|
+
case "label":
|
|
398
400
|
className += ` modern-input-label peer-focus:modern-input-peer-focus-label-size
|
|
399
401
|
${
|
|
400
402
|
isDisabled
|
|
401
|
-
?
|
|
402
|
-
:
|
|
403
|
+
? "cursor-pointer"
|
|
404
|
+
: "cursor-text peer-focus:cursor-pointer"
|
|
403
405
|
} ${
|
|
404
406
|
!isDisabled || !checkIsEmptyField()
|
|
405
|
-
?
|
|
407
|
+
? "active-input-label-bg"
|
|
406
408
|
: isDisabled && !checkIsEmptyField()
|
|
407
|
-
?
|
|
408
|
-
:
|
|
409
|
+
? "disabled-input-label-bg"
|
|
410
|
+
: ""
|
|
409
411
|
} 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 ${
|
|
410
412
|
isDisabled
|
|
411
|
-
?
|
|
412
|
-
:
|
|
413
|
+
? "cursor-pointer"
|
|
414
|
+
: "cursor-text peer-focus:cursor-pointer"
|
|
413
415
|
}
|
|
414
416
|
${
|
|
415
417
|
checkIsEmptyField()
|
|
416
|
-
?
|
|
417
|
-
:
|
|
418
|
+
? "modern-input-label-size"
|
|
419
|
+
: "modern-input-peer-focus-label-size"
|
|
418
420
|
}`;
|
|
419
421
|
if (errors && errors[name]) {
|
|
420
|
-
className +=
|
|
422
|
+
className += " text-error-light ";
|
|
421
423
|
} else {
|
|
422
|
-
className +=
|
|
424
|
+
className += " text-grey-dark peer-focus:text-blue-navy";
|
|
423
425
|
}
|
|
424
426
|
break;
|
|
425
|
-
case
|
|
426
|
-
className =
|
|
427
|
+
case "message":
|
|
428
|
+
className = " text-error-icon ";
|
|
427
429
|
break;
|
|
428
|
-
case
|
|
429
|
-
className +=
|
|
430
|
+
case "adorement":
|
|
431
|
+
className += " absolute right-0 adorement gap-1 flex items-center ";
|
|
430
432
|
break;
|
|
431
433
|
default:
|
|
432
434
|
break;
|
|
@@ -451,27 +453,27 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
451
453
|
// return 'bottom'
|
|
452
454
|
// }
|
|
453
455
|
const filteredData =
|
|
454
|
-
inputValue !==
|
|
456
|
+
inputValue !== "*" && type !== "custom_select" && !noLocalFilter
|
|
455
457
|
? suggestions?.filter((item: valueProps) =>
|
|
456
458
|
checkIncludes(
|
|
457
459
|
item.name,
|
|
458
460
|
inputValue,
|
|
459
|
-
item.param1 ??
|
|
460
|
-
item.param2 ??
|
|
461
|
-
item.param3 ??
|
|
462
|
-
item.param4 ??
|
|
461
|
+
item.param1 ?? "",
|
|
462
|
+
item.param2 ?? "",
|
|
463
|
+
item.param3 ?? "",
|
|
464
|
+
item.param4 ?? ""
|
|
463
465
|
)
|
|
464
466
|
)
|
|
465
467
|
: suggestions;
|
|
466
468
|
|
|
467
469
|
const handleError = (data: any) => {
|
|
468
470
|
if (
|
|
469
|
-
getErrors(data[name]) ===
|
|
470
|
-
getErrors(data[name]) ===
|
|
471
|
+
getErrors(data[name]) === "required" ||
|
|
472
|
+
getErrors(data[name]) === "Required"
|
|
471
473
|
) {
|
|
472
474
|
return `${label ?? labelTitle} is ${getErrors(data[name])}`;
|
|
473
475
|
} else {
|
|
474
|
-
return getErrors(data[name]) ??
|
|
476
|
+
return getErrors(data[name]) ?? "";
|
|
475
477
|
}
|
|
476
478
|
};
|
|
477
479
|
|
|
@@ -527,8 +529,8 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
527
529
|
<li
|
|
528
530
|
className={`${
|
|
529
531
|
value?.id === suggestion?.id
|
|
530
|
-
?
|
|
531
|
-
:
|
|
532
|
+
? "bg-blue-navy text-white"
|
|
533
|
+
: "hover:bg-table-hover"
|
|
532
534
|
} cursor-pointer p-1 text-xxs ps-3.5 pl-[10px]`}
|
|
533
535
|
key={suggestion?.id}
|
|
534
536
|
data-testid={suggestion.name}
|
|
@@ -539,7 +541,8 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
539
541
|
))}
|
|
540
542
|
</>
|
|
541
543
|
) : (
|
|
542
|
-
showNoResults &&
|
|
544
|
+
showNoResults &&
|
|
545
|
+
!isLoading && (
|
|
543
546
|
<li
|
|
544
547
|
className={`$ cursor-pointer p-1 rounded-sm text-xxs`}
|
|
545
548
|
onClick={handleClose}
|
|
@@ -568,11 +571,12 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
568
571
|
|
|
569
572
|
useEffect(() => {
|
|
570
573
|
applyPositionClass(dropdownref, isHovered);
|
|
574
|
+
setDropOpen(false);
|
|
571
575
|
}, [isHovered]);
|
|
572
576
|
|
|
573
577
|
return (
|
|
574
578
|
<div
|
|
575
|
-
className={` flex-grow ${fullWidth ?
|
|
579
|
+
className={` flex-grow ${fullWidth ? "w-full" : "w-auto"}`}
|
|
576
580
|
ref={dropdownref}
|
|
577
581
|
>
|
|
578
582
|
{label && !isModern && (
|
|
@@ -589,15 +593,15 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
589
593
|
)}
|
|
590
594
|
|
|
591
595
|
<div
|
|
592
|
-
className={`flex relative ${fullWidth ?
|
|
596
|
+
className={`flex relative ${fullWidth ? "w-full" : "w-auto"}`}
|
|
593
597
|
style={{ width: width }}
|
|
594
598
|
>
|
|
595
599
|
<div className="relative w-full">
|
|
596
600
|
<input
|
|
597
601
|
id={id}
|
|
598
602
|
type="text"
|
|
599
|
-
readOnly={readOnly ?? type ===
|
|
600
|
-
value={inputValue ? inputValue :
|
|
603
|
+
readOnly={readOnly ?? type === "custom_select"}
|
|
604
|
+
value={inputValue ? inputValue : ""}
|
|
601
605
|
onBlur={handleClearInputValue}
|
|
602
606
|
disabled={disabled}
|
|
603
607
|
ref={inputRef}
|
|
@@ -616,18 +620,18 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
616
620
|
}
|
|
617
621
|
: {}),
|
|
618
622
|
}}
|
|
619
|
-
className={` ${generateClassName(
|
|
623
|
+
className={` ${generateClassName("input")}`}
|
|
620
624
|
onChange={handleChange}
|
|
621
625
|
placeholder={
|
|
622
|
-
type ===
|
|
626
|
+
type === "auto_complete"
|
|
623
627
|
? placeholder && isCustomPlaceholder
|
|
624
628
|
? placeholder
|
|
625
|
-
:
|
|
626
|
-
: placeholder ??
|
|
629
|
+
: "Type to search"
|
|
630
|
+
: placeholder ?? "--Select--"
|
|
627
631
|
}
|
|
628
632
|
onFocus={onInputFocus}
|
|
629
633
|
onClick={(e) => {
|
|
630
|
-
if (type ===
|
|
634
|
+
if (type === "custom_select") {
|
|
631
635
|
setDropOpen(!dropOpen);
|
|
632
636
|
handleOpen(e);
|
|
633
637
|
} else {
|
|
@@ -639,9 +643,9 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
639
643
|
<label
|
|
640
644
|
htmlFor={id}
|
|
641
645
|
onClick={() => onLabelClick()}
|
|
642
|
-
className={generateClassName(
|
|
646
|
+
className={generateClassName("label")}
|
|
643
647
|
>
|
|
644
|
-
{label ? label :
|
|
648
|
+
{label ? label : ""}
|
|
645
649
|
{required ? <span className="text-error"> *</span> : <></>}
|
|
646
650
|
</label>
|
|
647
651
|
)}
|
|
@@ -649,12 +653,12 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
649
653
|
<div className="flex items-center justify-center ">
|
|
650
654
|
<div
|
|
651
655
|
ref={adorementRef}
|
|
652
|
-
className={`${generateClassName(
|
|
653
|
-
isLoading ?
|
|
656
|
+
className={`${generateClassName("adorement")} mr-[1px] ${
|
|
657
|
+
isLoading ? "bg-white" : ""
|
|
654
658
|
}`}
|
|
655
659
|
>
|
|
656
660
|
{value?.name &&
|
|
657
|
-
(value?.id || String(value?.id) ===
|
|
661
|
+
(value?.id || String(value?.id) === "0") &&
|
|
658
662
|
!disabled &&
|
|
659
663
|
!readOnly &&
|
|
660
664
|
isClose && (
|
|
@@ -668,7 +672,7 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
668
672
|
</button>
|
|
669
673
|
)}
|
|
670
674
|
{isLoading && <Spinner />}
|
|
671
|
-
{type !==
|
|
675
|
+
{type !== "auto_complete" && !disabled && !readOnly && (
|
|
672
676
|
<button
|
|
673
677
|
disabled={disabled ?? readOnly}
|
|
674
678
|
onClick={(e) => handleOpen(e)}
|
|
@@ -688,7 +692,7 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
|
|
|
688
692
|
{errors && errors[name] && (
|
|
689
693
|
<div
|
|
690
694
|
className={` text-error-label relative cursor-pointer ${generateClassName(
|
|
691
|
-
|
|
695
|
+
"message"
|
|
692
696
|
)}`}
|
|
693
697
|
onMouseEnter={() => setIsHovered(true)}
|
|
694
698
|
onMouseLeave={() => setIsHovered(false)}
|