import React, { PureComponent, ReactElement } from 'react'; import Select from './Select'; import { PopoverContent } from '../../../Tooltip/Tooltip'; import { SelectableValue } from '@grafana/data'; interface ButtonComponentProps { label: ReactElement | string | undefined; className: string | undefined; iconClass?: string; } const ButtonComponent = (buttonProps: ButtonComponentProps) => (props: any) => { const { label, className, iconClass } = buttonProps; return (
{iconClass && } {label ? label : ''} {!props.menuIsOpen && } {props.menuIsOpen && }
); }; export interface Props { className: string | undefined; options: Array>; value?: SelectableValue; label?: ReactElement | string; iconClass?: string; components?: any; maxMenuHeight?: number; onChange: (item: SelectableValue) => void; tooltipContent?: PopoverContent; isMenuOpen?: boolean; onOpenMenu?: () => void; onCloseMenu?: () => void; tabSelectsValue?: boolean; autoFocus?: boolean; } export class ButtonSelect extends PureComponent> { onChange = (item: SelectableValue) => { const { onChange } = this.props; onChange(item); }; render() { const { className, options, value, label, iconClass, components, maxMenuHeight, tooltipContent, isMenuOpen, onOpenMenu, onCloseMenu, tabSelectsValue, autoFocus = true, } = this.props; const combinedComponents = { ...components, Control: ButtonComponent({ label, className, iconClass }), }; return (