import { useState } from 'react'; interface Props { fields: string[]; onChange: (fields: string[]) => void; } // Pill list of field names that the value-search uses. Each pill is removable; // the inline input adds a new field on Enter or comma. Persisting to // localStorage is the parent's responsibility. export function SearchFieldChips({ fields, onChange }: Props) { const [input, setInput] = useState(''); const add = (raw: string) => { const next = raw.trim().replace(/,+$/, ''); if (!next) return; if (fields.includes(next)) return; onChange([...fields, next]); setInput(''); }; const remove = (f: string) => onChange(fields.filter((x) => x !== f)); return (
search in: {fields.map((f) => ( {f} ))} { const v = e.target.value; if (v.endsWith(',')) add(v); else setInput(v); }} onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); add(input); } if (e.key === 'Backspace' && input === '' && fields.length > 0) { remove(fields[fields.length - 1]); } }} />
); }