load item to panelDetails and display data
[arvados-workbench2.git] / src / components / context-menu / context-menu.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
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
8 export interface ContextMenuAction {
9     name: string;
10     icon: string;
11 }
12
13 export type ContextMenuActionGroup = ContextMenuAction[];
14
15 export interface ContextMenuProps<T> {
16     anchorEl?: HTMLElement;
17     actions: ContextMenuActionGroup[];
18     onActionClick: (action: ContextMenuAction) => void;
19     onClose: () => void;
20 }
21
22 export default class ContextMenu<T> extends React.PureComponent<ContextMenuProps<T>> {
23     render() {
24         const { anchorEl, actions, onClose, onActionClick } = this.props;
25         return <Popover
26             anchorEl={anchorEl}
27             open={!!anchorEl}
28             onClose={onClose}
29             transformOrigin={DefaultTransformOrigin}
30             anchorOrigin={DefaultTransformOrigin}>
31             <List dense>
32                 {actions.map((group, groupIndex) =>
33                     <React.Fragment key={groupIndex}>
34                         {group.map((action, actionIndex) =>
35                             <ListItem
36                                 button
37                                 key={actionIndex}
38                                 onClick={() => onActionClick(action)}>
39                                 <ListItemIcon>
40                                     <i className={action.icon} />
41                                 </ListItemIcon>
42                                 <ListItemText>
43                                     {action.name}
44                                 </ListItemText>
45                             </ListItem>)}
46                         {groupIndex < actions.length - 1 && <Divider />}
47                     </React.Fragment>)}
48             </List>
49         </Popover>;
50     }
51 }