import React from 'react' import MenuItem from '@mui/material/MenuItem' import { PopoverPosition } from '@mui/material/Popover' import { ContextMenu } from '../layout/ContextMenu' import ToolButton from '../toolbar/ToolButton' interface Command { name: string action: Function hotkey?: string } interface MainMenuProp { commands: Command[] icon: any } const MainMenu = ({ commands, icon }: MainMenuProp) => { const [anchorPosition, setAnchorPosition] = React.useState(undefined) const [anchorEl, setAnchorEl] = React.useState(null) const open = Boolean(anchorEl) const onOpen = (event: React.MouseEvent) => { event.preventDefault() event.stopPropagation() setAnchorEl(event.currentTarget) setAnchorPosition({ left: 0, top: event.currentTarget.offsetHeight + 6 }) } const handleClose = () => { setAnchorEl(null) setAnchorPosition(undefined) } const renderMenu = (command: Command) => { const menuItem = ( { command.action() handleClose() }} > {command.name} {command.hotkey &&
{command.hotkey}
}
) return menuItem } return ( <> {commands.map((command: Command) => renderMenu(command))} ) } export default MainMenu