import { useState } from "react"; import { Combobox } from "./primitives/combobox"; /** A command is an explicit user action, identified independently of its label. */ export interface CommandItem { id: string; label: string; } /** Searchable actions with arrow-key selection. Opening or filtering never invokes an action. */ export function Command({ label, items, onAction, }: { label: string; items: readonly CommandItem[]; onAction: (id: string) => void; }) { const [query, setQuery] = useState(""); return ( items={items} itemToStringLabel={(item) => item.label} itemToStringValue={(item) => item.id} inputValue={query} onInputValueChange={setQuery} value={null} onValueChange={(item) => { if (item) { onAction(item.id); setQuery(""); } }} > No matching commands {(item: CommandItem) => ( {item.label} )} ); }