import { StyledOptions } from "@emotion/styled"; import { Box, Button, Card, Divider, List, Typography, SxProps } from "@mui/material"; import React from "react"; export type Option = { text: string, onClick: () => unknown } export type ContextMenuProps = { options: ('divider'|Option)[], popupItem: React.RefObject } const buttonSx: SxProps = { '&:hover': { background: 'rgb(0, 30, 60)' }, fontSize: '0.7rem', minHeight: '30px', justifyContent: 'center', p: 0 }; function ContextMenu(props: ContextMenuProps) { const [anchor, setAnchor] = React.useState( { x: 0, y: 0 } ); const [show, setShow] = React.useState(false); React.useEffect(() => { const { popupItem: ref } = props; if (ref.current === null) return; const listener = (ev: MouseEvent) => { ev.preventDefault(); setAnchor({ x: ev.x + 10, y: ev.y + 10 }); setShow(true); } ref.current.addEventListener('contextmenu', listener); return () => { if (ref.current) ref.current.removeEventListener('contextmenu', listener) }; }, [ props.popupItem ]) return show ? {props.options.map((item, i) => { return item === 'divider' ? : })} : <> } export default ContextMenu;