import { useRef } from "preact/hooks"; interface FilterBarProps { value: string; onChange: (value: string) => void; visible: boolean; onHide: () => void; totalCount: number; matchCount: number; inputRef: (el: HTMLInputElement | null) => void; } export function FilterBar({ value, onChange, visible, onHide, totalCount, matchCount, inputRef }: FilterBarProps) { const internalRef = useRef(null); const setRef = (el: HTMLInputElement | null) => { internalRef.current = el; inputRef(el); }; // Show when parent says visible OR when there's an active filter value if (!visible && !value) return null; return (
onChange((e.target as HTMLInputElement).value)} onBlur={() => { onHide(); }} onKeyDown={(e) => { if (e.key === "Escape") { e.preventDefault(); onChange(""); (e.target as HTMLInputElement).blur(); } else if (e.key === "ArrowDown" || e.key === "Enter") { e.preventDefault(); (e.target as HTMLInputElement).blur(); } e.stopPropagation(); }} /> {value && ( {matchCount} of {totalCount} )} {value && ( )} {!value && ( / )}
); }