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;
16 export class Popover extends React.Component<PopoverProps> {
21 transformOrigin: PopoverOrigin = {
27 const Trigger = this.props.triggerComponent || DefaultTrigger;
30 <Trigger onClick={this.handleTriggerClick} />
32 anchorEl={this.state.anchorEl}
33 open={Boolean(this.state.anchorEl)}
34 onClose={this.handleClose}
35 onClick={this.handleSelfClick}
36 transformOrigin={this.transformOrigin}
37 anchorOrigin={this.transformOrigin}
46 this.setState({ anchorEl: undefined });
49 handleTriggerClick = (event: React.MouseEvent<any>) => {
50 this.setState({ anchorEl: event.currentTarget });
53 handleSelfClick = () => {
54 if (this.props.closeOnContentClick) {
60 export const DefaultTrigger: React.SFC<IconButtonProps> = (props) => (
61 <IconButton {...props}>