X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6de571a660401585bc96dd92fd2563e9b64c58c6..2f83fcd45b4b23db2bb5bb4afbe1e863ebd77ec6:/services/workbench2/src/components/dropdown-menu/dropdown-menu.tsx?ds=sidebyside

diff --git a/services/workbench2/src/components/dropdown-menu/dropdown-menu.tsx b/services/workbench2/src/components/dropdown-menu/dropdown-menu.tsx
new file mode 100644
index 0000000000..bb661bc288
--- /dev/null
+++ b/services/workbench2/src/components/dropdown-menu/dropdown-menu.tsx
@@ -0,0 +1,65 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import React from 'react';
+import Menu from '@material-ui/core/Menu';
+import IconButton from '@material-ui/core/IconButton';
+import { PopoverOrigin } from '@material-ui/core/Popover';
+import { Tooltip } from '@material-ui/core';
+
+interface DropdownMenuProps {
+    id: string;
+    icon: React.ReactElement<any>;
+    title: string;
+}
+
+interface DropdownMenuState {
+    anchorEl: any;
+}
+
+export class DropdownMenu extends React.Component<DropdownMenuProps, DropdownMenuState> {
+    state = {
+        anchorEl: undefined
+    };
+
+    transformOrigin: PopoverOrigin = {
+        vertical: -50,
+        horizontal: 0
+    };
+
+    render() {
+        const { icon, id, children, title } = this.props;
+        const { anchorEl } = this.state;
+        return (
+            <div>
+                <Tooltip title={title}>
+                    <IconButton
+                        aria-owns={anchorEl ? id : undefined}
+                        aria-haspopup="true"
+                        color="inherit"
+                        onClick={this.handleOpen}>
+                        {icon}
+                    </IconButton>
+                </Tooltip>
+                <Menu
+                    id={id}
+                    anchorEl={anchorEl}
+                    open={Boolean(anchorEl)}
+                    onClose={this.handleClose}
+                    onClick={this.handleClose}
+                    transformOrigin={this.transformOrigin}>
+                    {children}
+                </Menu>
+            </div>
+        );
+    }
+
+    handleClose = () => {
+        this.setState({ anchorEl: undefined });
+    }
+
+    handleOpen = (event: React.MouseEvent<HTMLButtonElement>) => {
+        this.setState({ anchorEl: event.currentTarget });
+    }
+}
