import { FC, useEffect, useRef } from 'react'; import { CommandDefinition } from '../../../../api'; interface ChatInputCommandSelectorViewProps { commands: CommandDefinition[]; selectedIndex: number; onSelect: (command: CommandDefinition) => void; onHover: (index: number) => void; } export const ChatInputCommandSelectorView: FC = props => { const { commands = [], selectedIndex = 0, onSelect = null, onHover = null } = props; const listRef = useRef(null); useEffect(() => { if(!listRef.current) return; const selected = listRef.current.children[selectedIndex] as HTMLElement; if(selected) selected.scrollIntoView({ block: 'nearest' }); }, [ selectedIndex ]); return (
{ commands.map((cmd, index) => (
onSelect(cmd) } onMouseEnter={ () => onHover(index) } > :{ cmd.key } { cmd.description }
)) }
); };