1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
4 import * as React from "react";
5 import { Popover, List, ListItem, ListItemIcon, ListItemText, Divider } from "@material-ui/core";
6 import { DefaultTransformOrigin } from "../popover/helpers";
7 import { IconType } from "../icon/icon";
9 export interface ContextMenuItem {
14 export type ContextMenuItemGroup = ContextMenuItem[];
16 export interface ContextMenuProps {
17 anchorEl?: HTMLElement;
18 items: ContextMenuItemGroup[];
19 onItemClick: (action: ContextMenuItem) => void;
23 export default class ContextMenu extends React.PureComponent<ContextMenuProps> {
25 const { anchorEl, items, onClose, onItemClick} = this.props;
30 transformOrigin={DefaultTransformOrigin}
31 anchorOrigin={DefaultTransformOrigin}
32 onContextMenu={this.handleContextMenu}>
34 {items.map((group, groupIndex) =>
35 <React.Fragment key={groupIndex}>
36 {group.map((item, actionIndex) =>
40 onClick={() => onItemClick(item)}>
48 {groupIndex < items.length - 1 && <Divider />}
54 handleContextMenu = (event: React.MouseEvent<HTMLElement>) => {
55 event.preventDefault();