2020-09-16 10:30:19 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { EuiFlexItem, EuiPopover, EuiIcon, EuiPopoverTitle, IconType } from '@elastic/eui';
|
|
|
|
import { ToolbarButton, ToolbarButtonProps } from './toolbar_button';
|
|
|
|
import { EuiIconLegend } from '../assets/legend';
|
|
|
|
|
|
|
|
const typeToIconMap: { [type: string]: string | IconType } = {
|
|
|
|
legend: EuiIconLegend as IconType,
|
|
|
|
values: 'visText',
|
|
|
|
};
|
|
|
|
|
|
|
|
export interface ToolbarPopoverProps {
|
|
|
|
/**
|
|
|
|
* Determines popover title
|
|
|
|
*/
|
|
|
|
title: string;
|
|
|
|
/**
|
|
|
|
* Determines the button icon
|
|
|
|
*/
|
|
|
|
type: 'legend' | 'values' | IconType;
|
|
|
|
/**
|
|
|
|
* Determines if the popover is disabled
|
|
|
|
*/
|
|
|
|
isDisabled?: boolean;
|
|
|
|
/**
|
|
|
|
* Button group position
|
|
|
|
*/
|
|
|
|
groupPosition?: ToolbarButtonProps['groupPosition'];
|
2020-09-18 18:41:22 +02:00
|
|
|
buttonDataTestSubj?: string;
|
2020-09-16 10:30:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const ToolbarPopover: React.FunctionComponent<ToolbarPopoverProps> = ({
|
|
|
|
children,
|
|
|
|
title,
|
|
|
|
type,
|
|
|
|
isDisabled = false,
|
|
|
|
groupPosition,
|
2020-09-18 18:41:22 +02:00
|
|
|
buttonDataTestSubj,
|
2020-09-16 10:30:19 +02:00
|
|
|
}) => {
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
|
|
|
const iconType: string | IconType = typeof type === 'string' ? typeToIconMap[type] : type;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<EuiFlexItem grow={false}>
|
|
|
|
<EuiPopover
|
|
|
|
panelClassName="lnsXyToolbar__popover"
|
|
|
|
ownFocus
|
|
|
|
aria-label={title}
|
|
|
|
button={
|
|
|
|
<ToolbarButton
|
|
|
|
fontWeight="normal"
|
|
|
|
onClick={() => {
|
|
|
|
setOpen(!open);
|
|
|
|
}}
|
2020-09-17 17:38:43 +02:00
|
|
|
title={title}
|
2020-09-16 10:30:19 +02:00
|
|
|
hasArrow={false}
|
|
|
|
isDisabled={isDisabled}
|
|
|
|
groupPosition={groupPosition}
|
2020-09-18 18:41:22 +02:00
|
|
|
dataTestSubj={buttonDataTestSubj}
|
2020-09-16 10:30:19 +02:00
|
|
|
>
|
|
|
|
<EuiIcon type={iconType} />
|
|
|
|
</ToolbarButton>
|
|
|
|
}
|
|
|
|
isOpen={open}
|
|
|
|
closePopover={() => {
|
|
|
|
setOpen(false);
|
|
|
|
}}
|
|
|
|
anchorPosition="downRight"
|
|
|
|
>
|
|
|
|
<EuiPopoverTitle>{title}</EuiPopoverTitle>
|
|
|
|
{children}
|
|
|
|
</EuiPopover>
|
|
|
|
</EuiFlexItem>
|
|
|
|
);
|
|
|
|
};
|