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 {
10 name?: string | React.ComponentType;
12 component?: React.ComponentType<any>;
15 export type ContextMenuItemGroup = ContextMenuItem[];
17 export interface ContextMenuProps {
18 anchorEl?: HTMLElement;
19 items: ContextMenuItemGroup[];
21 onItemClick: (action: ContextMenuItem) => void;
25 export class ContextMenu extends React.PureComponent<ContextMenuProps> {
27 const { anchorEl, items, open, onClose, onItemClick } = this.props;
32 transformOrigin={DefaultTransformOrigin}
33 anchorOrigin={DefaultTransformOrigin}
34 onContextMenu={this.handleContextMenu}>
36 {items.map((group, groupIndex) =>
37 <React.Fragment key={groupIndex}>
38 {group.map((item, actionIndex) =>
42 onClick={() => onItemClick(item)} />
46 onClick={() => onItemClick(item)}>
57 items[groupIndex + 1] &&
58 items[groupIndex + 1].length > 0 &&
66 handleContextMenu = (event: React.MouseEvent<HTMLElement>) => {
67 event.preventDefault();