import { useState } from 'react'; import { VariableIcon } from 'lucide-react'; import { Button } from '../ui/button'; import { Input } from '../ui/input'; import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'; export interface VariableOption { name: string; label: string; example: string; } /** * The "Insert variable" menu of a template field: a searchable list of the * variables the site knows, each with what it renders to here. */ export const VariablesMenu = ({ variables, onPick, }: { variables: VariableOption[]; onPick: (name: string) => void; }): JSX.Element => { const [open, setOpen] = useState(false); const [query, setQuery] = useState(''); const needle = query.trim().toLowerCase(); const shown = needle ? variables.filter( variable => variable.name.toLowerCase().includes(needle) || variable.label.toLowerCase().includes(needle) ) : variables; return ( { setOpen(next); if (!next) { setQuery(''); } }} > } aria-label="Insert a variable" > Variables setQuery(event.target.value)} placeholder="Search variables" className="mb-2 h-8" /> ); };