2020-04-11 09:07:18 -05:00
|
|
|
import { IconName, IconButton, stylesFactory, useTheme } from '@grafana/ui';
|
2020-04-09 14:23:22 -05:00
|
|
|
import React from 'react';
|
2020-04-11 09:07:18 -05:00
|
|
|
import { css } from 'emotion';
|
2020-04-09 14:23:22 -05:00
|
|
|
import { GrafanaTheme } from '@grafana/data';
|
|
|
|
|
|
|
|
interface QueryOperationActionProps {
|
|
|
|
icon: IconName;
|
|
|
|
title?: string;
|
|
|
|
onClick: (e: React.MouseEvent) => void;
|
|
|
|
disabled?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const QueryOperationAction: React.FC<QueryOperationActionProps> = ({ icon, disabled, title, ...otherProps }) => {
|
|
|
|
const theme = useTheme();
|
2020-04-11 09:07:18 -05:00
|
|
|
const styles = getStyles(theme);
|
|
|
|
|
2020-04-09 14:23:22 -05:00
|
|
|
const onClick = (e: React.MouseEvent) => {
|
|
|
|
if (!disabled) {
|
|
|
|
otherProps.onClick(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<div title={title}>
|
2020-04-11 09:07:18 -05:00
|
|
|
<IconButton
|
|
|
|
name={icon}
|
|
|
|
className={styles.icon}
|
|
|
|
disabled={!!disabled}
|
|
|
|
onClick={onClick}
|
|
|
|
aria-label={`${title} query operation action`}
|
|
|
|
/>
|
2020-04-09 14:23:22 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-04-11 09:07:18 -05:00
|
|
|
QueryOperationAction.displayName = 'QueryOperationAction';
|
|
|
|
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme) => {
|
2020-04-09 14:23:22 -05:00
|
|
|
return {
|
2020-04-11 09:07:18 -05:00
|
|
|
icon: css`
|
|
|
|
color: ${theme.colors.textWeak};
|
|
|
|
`,
|
2020-04-09 14:23:22 -05:00
|
|
|
};
|
|
|
|
});
|