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 { DataItem } from "./data-item";
9 export type ContextMenuAction = (item: DataItem) => void;
10 export interface ContextMenuActions {
11 onShare: ContextMenuAction;
12 onMoveTo: ContextMenuAction;
13 onAddToFavourite: ContextMenuAction;
14 onRename: ContextMenuAction;
15 onCopy: ContextMenuAction;
16 onDownload: ContextMenuAction;
17 onRemove: ContextMenuAction;
19 export interface ContextMenuProps {
20 anchorEl?: HTMLElement;
23 actions: ContextMenuActions;
26 export const ContextMenu: React.SFC<ContextMenuProps> = ({ anchorEl, onClose, actions, item }) =>
29 open={Boolean(anchorEl)}
31 transformOrigin={DefaultTransformOrigin}
32 anchorOrigin={DefaultTransformOrigin}>
33 <Actions {...{ actions, item, onClose }} />
36 interface ActionsProps {
37 actions: ContextMenuActions;
42 const Actions: React.SFC<ActionsProps> = ({ actions, item, onClose }) =>
47 onClick: actions.onShare
50 icon: "fas fa-sign-out-alt",
52 onClick: actions.onMoveTo
56 label: "Add to favourite",
57 onClick: actions.onAddToFavourite
62 onClick: actions.onRename
67 onClick: actions.onCopy
70 icon: "fas fa-download",
72 onClick: actions.onDownload
73 }].map((props, index) =>
81 icon="fas fa-trash-alt"
85 onClick={actions.onRemove} />
88 interface ActionProps {
89 onClick: ContextMenuAction;
96 const Action: React.SFC<ActionProps> = ({ onClick, onClose, item, icon, label }) =>
97 <ListItem button onClick={() => {
104 <i className={icon} />