next-helios-fe 1.10.13 → 1.10.15
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/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import React from "react";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import { useDebouncedCallback } from "use-debounce";
|
|
3
4
|
import { Icon } from "@iconify/react";
|
|
4
5
|
|
|
5
6
|
export interface SearchProps
|
|
@@ -7,10 +8,21 @@ export interface SearchProps
|
|
|
7
8
|
options?: {
|
|
8
9
|
width?: "full" | "fit";
|
|
9
10
|
height?: "short" | "medium" | "high";
|
|
11
|
+
delayed?: boolean;
|
|
10
12
|
};
|
|
13
|
+
value?: string;
|
|
14
|
+
onChange?: (e: { target: { value: string } }) => void;
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
export const Search: React.FC<SearchProps> = ({
|
|
17
|
+
export const Search: React.FC<SearchProps> = ({
|
|
18
|
+
options,
|
|
19
|
+
value,
|
|
20
|
+
onChange,
|
|
21
|
+
...rest
|
|
22
|
+
}) => {
|
|
23
|
+
const [tempValue, setTempValue] = useState<string>(
|
|
24
|
+
value ?? (rest.defaultValue as string) ?? ""
|
|
25
|
+
);
|
|
14
26
|
const width = options?.width === "fit" ? "w-fit" : "w-full";
|
|
15
27
|
const height =
|
|
16
28
|
options?.height === "short"
|
|
@@ -19,6 +31,13 @@ export const Search: React.FC<SearchProps> = ({ options, ...rest }) => {
|
|
|
19
31
|
? "py-2"
|
|
20
32
|
: "py-1.5";
|
|
21
33
|
|
|
34
|
+
const handleDelayedValueUpdate = useDebouncedCallback((value) => {
|
|
35
|
+
onChange &&
|
|
36
|
+
onChange({
|
|
37
|
+
target: { value } as HTMLInputElement,
|
|
38
|
+
} as React.ChangeEvent<HTMLInputElement>);
|
|
39
|
+
}, 1250);
|
|
40
|
+
|
|
22
41
|
return (
|
|
23
42
|
<label className={`relative flex items-center ${width}`}>
|
|
24
43
|
<Icon
|
|
@@ -28,16 +47,30 @@ export const Search: React.FC<SearchProps> = ({ options, ...rest }) => {
|
|
|
28
47
|
<input
|
|
29
48
|
type="search"
|
|
30
49
|
className={`w-full px-9 pe-4 border-default border rounded-md bg-secondary-bg placeholder:duration-300 placeholder:translate-x-0 [&::-webkit-search-cancel-button]:appearance-none focus:placeholder:translate-x-1 placeholder:text-silent focus:outline-none focus:ring-1 focus:ring-primary focus:shadow focus:shadow-primary focus:border-primary-dark disabled:bg-secondary-light disabled:text-disabled ${height}`}
|
|
50
|
+
value={tempValue}
|
|
51
|
+
onChange={(e) => {
|
|
52
|
+
setTempValue(e.target.value);
|
|
53
|
+
|
|
54
|
+
if (options?.delayed) {
|
|
55
|
+
handleDelayedValueUpdate(e.target.value);
|
|
56
|
+
} else {
|
|
57
|
+
onChange &&
|
|
58
|
+
onChange({
|
|
59
|
+
target: { value: e.target.value } as HTMLInputElement,
|
|
60
|
+
} as React.ChangeEvent<HTMLInputElement>);
|
|
61
|
+
}
|
|
62
|
+
}}
|
|
31
63
|
{...rest}
|
|
32
64
|
/>
|
|
33
|
-
{
|
|
65
|
+
{value && (
|
|
34
66
|
<div
|
|
35
67
|
className={
|
|
36
68
|
"absolute right-4 p-1 rounded-full text-xl text-disabled cursor-pointer hover:bg-secondary-light"
|
|
37
69
|
}
|
|
38
70
|
onClick={() => {
|
|
39
|
-
|
|
40
|
-
|
|
71
|
+
setTempValue("");
|
|
72
|
+
onChange &&
|
|
73
|
+
onChange({
|
|
41
74
|
target: { value: "" } as HTMLInputElement,
|
|
42
75
|
} as React.ChangeEvent<HTMLInputElement>);
|
|
43
76
|
}}
|