mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 22:12:36 +08:00

* update eslint, tsconfig + esbuild to handle new jsx transform * remove thing that breaks the new jsx transform * remove react imports * adjust grafana-icons build * is this the correct syntax? * try this * well this was much easier than expected... * change grafana-plugin-configs webpack config * fixes * fix lockfile * fix 2 more violations * use path.resolve instead of require.resolve * remove react import * fix react imports * more fixes * remove React import * remove import React from docs * remove another react import
69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
import { css, cx } from '@emotion/css';
|
|
import * as React from 'react';
|
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
import { IconButton, IconName, useStyles2 } from '@grafana/ui';
|
|
|
|
interface BaseQueryOperationActionProps {
|
|
icon: IconName;
|
|
title: string;
|
|
onClick: (e: React.MouseEvent) => void;
|
|
disabled?: boolean;
|
|
dataTestId?: string;
|
|
}
|
|
|
|
function BaseQueryOperationAction(props: QueryOperationActionProps | QueryOperationToggleActionProps) {
|
|
const styles = useStyles2(getStyles);
|
|
|
|
return (
|
|
<div className={cx(styles.icon, 'active' in props && props.active && styles.active)}>
|
|
<IconButton
|
|
name={props.icon}
|
|
tooltip={props.title}
|
|
className={styles.icon}
|
|
disabled={!!props.disabled}
|
|
onClick={props.onClick}
|
|
type="button"
|
|
data-testid={props.dataTestId ?? selectors.components.QueryEditorRow.actionButton(props.title)}
|
|
{...('active' in props && { 'aria-pressed': props.active })}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
interface QueryOperationActionProps extends BaseQueryOperationActionProps {}
|
|
export function QueryOperationAction(props: QueryOperationActionProps) {
|
|
return <BaseQueryOperationAction {...props} />;
|
|
}
|
|
|
|
interface QueryOperationToggleActionProps extends BaseQueryOperationActionProps {
|
|
active: boolean;
|
|
}
|
|
export const QueryOperationToggleAction = (props: QueryOperationToggleActionProps) => {
|
|
return <BaseQueryOperationAction {...props} />;
|
|
};
|
|
|
|
const getStyles = (theme: GrafanaTheme2) => {
|
|
return {
|
|
icon: css({
|
|
display: 'flex',
|
|
position: 'relative',
|
|
color: theme.colors.text.secondary,
|
|
}),
|
|
active: css({
|
|
'&:before': {
|
|
display: 'block',
|
|
content: '" "',
|
|
position: 'absolute',
|
|
left: -1,
|
|
right: 2,
|
|
height: 3,
|
|
borderRadius: theme.shape.radius.default,
|
|
bottom: -8,
|
|
backgroundImage: theme.colors.gradients.brandHorizontal,
|
|
},
|
|
}),
|
|
};
|
|
};
|