celo-poll/components/SearchBar.tsx
2025-12-08 16:31:30 +03:00

45 lines
1.1 KiB
TypeScript

'use client'
import { useState } from 'react'
import { Search, X } from 'lucide-react'
interface SearchBarProps {
onSearch: (query: string) => void
placeholder?: string
}
export default function SearchBar({ onSearch, placeholder = 'Search...' }: SearchBarProps) {
const [query, setQuery] = useState('')
const handleChange = (value: string) => {
setQuery(value)
onSearch(value)
}
const handleClear = () => {
setQuery('')
onSearch('')
}
return (
<div className="relative">
<Search className="absolute left-3 top-3 text-gray-400" size={20} />
<input
type="text"
value={query}
onChange={(e) => handleChange(e.target.value)}
placeholder={placeholder}
className="w-full pl-10 pr-10 py-3 bg-white/10 rounded-xl border border-white/20 focus:border-celo-green outline-none text-white placeholder-gray-400"
/>
{query && (
<button
onClick={handleClear}
className="absolute right-3 top-3 text-gray-400 hover:text-white"
>
<X size={20} />
</button>
)}
</div>
)
}