import { FC, useEffect, useRef } from 'react'; import { CommandDefinition } from '../../../../api'; interface ChatInputCommandSelectorViewProps { commands: CommandDefinition[]; selectedIndex: number; onSelect: (command: CommandDefinition) => void; onHover: (index: number) => void; /** * When true, render the flat minimalist look (gray list, dark-blue * selection). When false / undefined (default) the picker wears the * Habbo NitroCard chrome with the green :command header strip. */ newStyle?: boolean; } /** * :command autocomplete popover. Two visual modes, both driven by the * "New style" toggle in user settings (memenu.settings.other.catalog.classic.style): * * - newStyle = false (default): cream cardstock, habbo-green header, * UbuntuCondensed names, green ":" tile, custom Habbo scrollbar. * - newStyle = true: flat gray list, dark-blue selection, plain text rows. */ export const ChatInputCommandSelectorView: FC = props => { const { commands = [], selectedIndex = 0, onSelect = null, onHover = null, newStyle = false } = 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 ]); if(newStyle) { return (
{ commands.map((cmd, index) => (
onSelect(cmd) } onMouseEnter={ () => onHover(index) } > :{ cmd.key } { cmd.description }
)) }
); } return (
: Command
{ commands.map((cmd, index) => { const isSelected = (index === selectedIndex); const rowClass = [ 'chat-input-command-row', isSelected ? 'is-selected' : '' ].filter(Boolean).join(' '); return (
onSelect(cmd) } onMouseEnter={ () => onHover(index) } >
:
:{ cmd.key } { cmd.description && { cmd.description } }
); }) }
); };