import { forwardRef, useEffect, useState } from 'react'; interface SearchBoxProps { onSearch: (query: string) => void; } /** * Owns the raw input value so typing only re-renders this box; the list * receives the debounced query. */ export const SearchBox = forwardRef(function SearchBox({ onSearch }, ref) { const [value, setValue] = useState(''); useEffect(() => { const t = window.setTimeout(() => onSearch(value.trim()), 350); return () => window.clearTimeout(t); }, [value, onSearch]); return (
setValue(e.target.value)} onKeyDown={(e) => { if (e.key === 'Escape') { setValue(''); e.currentTarget.blur(); } }} className="input-field !py-2.5 pl-10 pr-4 !rounded-full w-full sm:w-56 sm:focus:w-72 transition-[width] text-sm" />
); });