import React, { useEffect, useRef } from "react"; import { cn } from "@/lib/utils.ts"; interface CommandAutocompleteProps { suggestions: string[]; selectedIndex: number; onSelect: (command: string) => void; position: { top: number; left: number }; visible: boolean; } export function CommandAutocomplete({ suggestions, selectedIndex, onSelect, position, visible, }: CommandAutocompleteProps) { const containerRef = useRef(null); const selectedRef = useRef(null); useEffect(() => { if (selectedRef.current && containerRef.current) { selectedRef.current.scrollIntoView({ block: "nearest", behavior: "smooth", }); } }, [selectedIndex]); if (!visible || suggestions.length === 0) { return null; } const footerHeight = 32; const maxSuggestionsHeight = 240 - footerHeight; return (
{suggestions.map((suggestion, index) => (
onSelect(suggestion)} onMouseEnter={() => {}} > {suggestion}
))}
Tab/Enter to complete • ↑↓ to navigate • Esc to close
); }