@firecms/ui 3.0.0-alpha.63 → 3.0.0-alpha.65
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/components/SearchBar.d.ts +7 -2
- package/dist/index.es.js +7357 -7328
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +9 -9
- package/dist/index.umd.js.map +1 -1
- package/dist/util/useDebounceValue.d.ts +1 -0
- package/package.json +2 -2
- package/src/components/Button.tsx +2 -2
- package/src/components/SearchBar.tsx +34 -17
- package/src/util/useDebounceValue.tsx +18 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useDebounceValue<T>(value: T, delay?: number): T;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firecms/ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.0-alpha.
|
|
4
|
+
"version": "3.0.0-alpha.65",
|
|
5
5
|
"description": "Awesome Firebase/Firestore-based headless open-source CMS",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/firecmsco"
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"dist",
|
|
117
117
|
"src"
|
|
118
118
|
],
|
|
119
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "36de2bb0fb9e1baa20262d3c520830389e688f91",
|
|
120
120
|
"publishConfig": {
|
|
121
121
|
"access": "public"
|
|
122
122
|
}
|
|
@@ -45,8 +45,8 @@ export function Button<P extends React.ElementType>({
|
|
|
45
45
|
const sizeClasses = cn(
|
|
46
46
|
{
|
|
47
47
|
"py-1 px-2": size === "small",
|
|
48
|
-
"py-2 px-
|
|
49
|
-
"py-
|
|
48
|
+
"py-2 px-4": size === "medium",
|
|
49
|
+
"py-2.5 px-5": size === "large"
|
|
50
50
|
}
|
|
51
51
|
);
|
|
52
52
|
|
|
@@ -1,39 +1,49 @@
|
|
|
1
|
-
import React, { useCallback,
|
|
1
|
+
import React, { useCallback, useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { defaultBorderMixin, focusedMixin } from "../styles";
|
|
4
|
-
import { IconButton } from "./index";
|
|
4
|
+
import { CircularProgress, IconButton } from "./index";
|
|
5
5
|
import { ClearIcon, SearchIcon } from "../icons";
|
|
6
6
|
import { cn } from "../util";
|
|
7
|
+
import { useDebounceValue } from "../util/useDebounceValue";
|
|
7
8
|
|
|
8
9
|
interface SearchBarProps {
|
|
9
|
-
|
|
10
|
+
onClick?: () => void;
|
|
11
|
+
onTextSearch?: (searchString?: string) => void;
|
|
10
12
|
placeholder?: string;
|
|
11
13
|
expandable?: boolean;
|
|
12
14
|
large?: boolean;
|
|
13
15
|
innerClassName?: string;
|
|
14
16
|
className?: string;
|
|
15
17
|
autoFocus?: boolean;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
loading?: boolean;
|
|
20
|
+
inputRef?: React.Ref<HTMLInputElement>;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
export function SearchBar({
|
|
24
|
+
onClick,
|
|
19
25
|
onTextSearch,
|
|
20
26
|
placeholder = "Search",
|
|
21
27
|
expandable = false,
|
|
22
28
|
large = false,
|
|
23
29
|
innerClassName,
|
|
24
30
|
className,
|
|
25
|
-
autoFocus
|
|
31
|
+
autoFocus,
|
|
32
|
+
disabled,
|
|
33
|
+
loading,
|
|
34
|
+
inputRef
|
|
26
35
|
}: SearchBarProps) {
|
|
27
36
|
|
|
28
37
|
const [searchText, setSearchText] = useState<string>("");
|
|
29
38
|
const [active, setActive] = useState<boolean>(false);
|
|
30
39
|
|
|
31
|
-
const deferredValues =
|
|
40
|
+
const deferredValues = useDebounceValue(searchText, 200);
|
|
32
41
|
|
|
33
42
|
/**
|
|
34
43
|
* Debounce on Search text update
|
|
35
44
|
*/
|
|
36
45
|
React.useEffect(() => {
|
|
46
|
+
if (!onTextSearch) return;
|
|
37
47
|
if (deferredValues) {
|
|
38
48
|
onTextSearch(deferredValues);
|
|
39
49
|
} else {
|
|
@@ -42,31 +52,39 @@ export function SearchBar({
|
|
|
42
52
|
}, [deferredValues]);
|
|
43
53
|
|
|
44
54
|
const clearText = useCallback(() => {
|
|
55
|
+
if (!onTextSearch) return;
|
|
45
56
|
setSearchText("");
|
|
46
57
|
onTextSearch(undefined);
|
|
47
58
|
}, []);
|
|
48
59
|
|
|
49
60
|
return (
|
|
50
|
-
<div
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
<div
|
|
62
|
+
onClick={onClick}
|
|
63
|
+
className={cn("relative",
|
|
64
|
+
large ? "h-14" : "h-[42px]",
|
|
65
|
+
"bg-gray-50 dark:bg-gray-800 transition duration-150 ease-in-out border",
|
|
66
|
+
defaultBorderMixin,
|
|
67
|
+
"rounded",
|
|
68
|
+
className)}>
|
|
56
69
|
<div
|
|
57
70
|
className="absolute p-0 px-4 h-full absolute pointer-events-none flex items-center justify-center top-0">
|
|
58
|
-
<SearchIcon className={"text-gray-500"}/>
|
|
71
|
+
{loading ? <CircularProgress size={"small"}/> : <SearchIcon className={"text-gray-500"}/>}
|
|
59
72
|
</div>
|
|
60
73
|
<input
|
|
61
|
-
placeholder={placeholder}
|
|
62
74
|
value={searchText}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
75
|
+
ref={inputRef}
|
|
76
|
+
onClick={onClick}
|
|
77
|
+
placeholder={placeholder}
|
|
78
|
+
onChange={onTextSearch
|
|
79
|
+
? (event) => {
|
|
80
|
+
setSearchText(event.target.value);
|
|
81
|
+
}
|
|
82
|
+
: undefined}
|
|
66
83
|
autoFocus={autoFocus}
|
|
67
84
|
onFocus={() => setActive(true)}
|
|
68
85
|
onBlur={() => setActive(false)}
|
|
69
86
|
className={cn(
|
|
87
|
+
(disabled || loading) && "pointer-events-none",
|
|
70
88
|
"relative flex items-center rounded transition-all bg-transparent outline-none appearance-none border-none",
|
|
71
89
|
"pl-12 h-full text-current ",
|
|
72
90
|
expandable ? (active ? "w-[220px]" : "w-[180px]") : "",
|
|
@@ -77,7 +95,6 @@ export function SearchBar({
|
|
|
77
95
|
{searchText
|
|
78
96
|
? <IconButton
|
|
79
97
|
className={`${large ? "mr-2 top-1" : "mr-1 top-0"} absolute right-0 z-10`}
|
|
80
|
-
// size={"small"}
|
|
81
98
|
onClick={clearText}>
|
|
82
99
|
<ClearIcon size={"small"}/>
|
|
83
100
|
</IconButton>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
export function useDebounceValue<T>(value: T, delay = 300): T {
|
|
4
|
+
// State and setters for debounced value
|
|
5
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
6
|
+
useEffect(
|
|
7
|
+
() => {
|
|
8
|
+
const handler = setTimeout(() => {
|
|
9
|
+
setDebouncedValue(value);
|
|
10
|
+
}, delay);
|
|
11
|
+
return () => {
|
|
12
|
+
clearTimeout(handler);
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
[value, delay] // Only re-call effect if value or delay changes
|
|
16
|
+
);
|
|
17
|
+
return debouncedValue;
|
|
18
|
+
}
|