-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathSearchInput.tsx
More file actions
46 lines (39 loc) · 1.3 KB
/
Copy pathSearchInput.tsx
File metadata and controls
46 lines (39 loc) · 1.3 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
"use client";
import { useState, useEffect } from "react";
import { Search } from "lucide-react";
interface SearchInputProps {
value: string;
onChange: (value: string) => void;
placeholder?: string;
}
export default function SearchInput({
value,
onChange,
placeholder = "Search programs...",
}: SearchInputProps): JSX.Element {
const [localValue, setLocalValue] = useState(value);
// Debounce search to prevent excessive filtering during typing
useEffect(() => {
const timer = setTimeout(() => {
onChange(localValue);
}, 150); // 150ms debounce
return () => clearTimeout(timer);
}, [localValue, onChange]);
// Sync external changes
useEffect(() => {
setLocalValue(value);
}, [value]);
return (
<div className="relative flex-[3] min-w-0">
<Search className="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 w-5 h-5 pointer-events-none z-10" />
<input
type="text"
placeholder={placeholder}
value={localValue}
onChange={(e) => setLocalValue(e.target.value)}
className="w-full bg-dash-surface border border-dash-border rounded-xl py-3 pl-12 pr-4 text-text-primary placeholder-gray-500 focus:outline-none focus:border-brand-purple transition-colors"
aria-label="Search programs"
/>
</div>
);
}