1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { Popover as MaterialPopover } from '@material-ui/core';
8 import { PopoverOrigin } from '@material-ui/core/Popover';
9 import IconButton, { IconButtonProps } from '@material-ui/core/IconButton';
11 export interface PopoverProps {
12 triggerComponent?: React.ComponentType<{ onClick: (event: React.MouseEvent<any>) => void }>;
13 closeOnContentClick?: boolean;
17 class Popover extends React.Component<PopoverProps> {
23 transformOrigin: PopoverOrigin = {
29 const Trigger = this.props.triggerComponent || DefaultTrigger;
32 <Trigger onClick={this.handleTriggerClick} />
34 anchorEl={this.state.anchorEl}
35 open={Boolean(this.state.anchorEl)}
36 onClose={this.handleClose}
37 onClick={this.handleSelfClick}
38 transformOrigin={this.transformOrigin}
39 anchorOrigin={this.transformOrigin}
48 this.setState({ anchorEl: undefined });
51 handleTriggerClick = (event: React.MouseEvent<any>) => {
52 this.setState({ anchorEl: event.currentTarget });
55 handleSelfClick = () => {
56 if (this.props.closeOnContentClick) {
63 export const DefaultTrigger: React.SFC<IconButtonProps> = (props) => (
64 <IconButton {...props}>
69 export default Popover;