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";
8 export interface ContextMenuAction {
13 export type ContextMenuActionGroup = ContextMenuAction[];
15 export interface ContextMenuProps<T> {
16 anchorEl?: HTMLElement;
17 actions: ContextMenuActionGroup[];
18 onActionClick: (action: ContextMenuAction) => void;
22 export default class ContextMenu<T> extends React.PureComponent<ContextMenuProps<T>> {
24 const { anchorEl, actions, onClose, onActionClick } = this.props;
29 transformOrigin={DefaultTransformOrigin}
30 anchorOrigin={DefaultTransformOrigin}
31 onContextMenu={this.handleContextMenu}>
33 {actions.map((group, groupIndex) =>
34 <React.Fragment key={groupIndex}>
35 {group.map((action, actionIndex) =>
39 onClick={() => onActionClick(action)}>
41 <i className={action.icon} />
47 {groupIndex < actions.length - 1 && <Divider />}
53 handleContextMenu = (event: React.MouseEvent<HTMLElement>) => {
54 event.preventDefault();