-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTableToolbar.tsx
More file actions
51 lines (45 loc) · 1.39 KB
/
TableToolbar.tsx
File metadata and controls
51 lines (45 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use client";
import { Input } from "@/components/ui/Input";
import { useQueryParams } from "@/hooks";
import { Search, X } from "lucide-react";
interface TableToolbarProps {
searchable?: boolean;
searchPlaceholder?: string;
searchValue?: string;
onSearchChange?: (value: string) => void;
rightAction?: React.ReactNode;
}
export const TableToolbar = ({
searchable = false,
searchPlaceholder = "Search...",
searchValue = "",
onSearchChange,
rightAction,
}: TableToolbarProps) => {
const { setParam } = useQueryParams();
const clearSearch = () => {
setParam("search", "");
onSearchChange?.("");
};
return (
<div className="flex items-center justify-between gap-4">
{/* Search Section */}
<div className="flex-1">
{searchable && (
<div className="relative max-w-sm">
<Search className="text-muted-foreground absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2" />
<Input
placeholder={searchPlaceholder}
value={searchValue}
onChange={(e) => onSearchChange?.(e.target.value)}
className="pl-10"
suffix={searchValue && <X className="w-5 cursor-pointer" onClick={clearSearch} />}
/>
</div>
)}
</div>
{/* Right Action Section */}
{rightAction && <div className="flex-shrink-0">{rightAction}</div>}
</div>
);
};