import { css } from '@emotion/css'; import React, { FC, MouseEvent, useCallback } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; import { Icon, Tooltip, useStyles2 } from '@grafana/ui'; interface Props { onClick: () => void; text: string; loading: boolean; onCancel: () => void; disabled: boolean; // todo: optional? /** * htmlFor, needed for the label */ id: string; } export const VariableLink: FC = ({ loading, disabled, onClick: propsOnClick, text, onCancel, id }) => { const styles = useStyles2(getStyles); const onClick = useCallback( (event: MouseEvent) => { event.stopPropagation(); event.preventDefault(); propsOnClick(); }, [propsOnClick] ); if (loading) { return (
); } return ( ); }; interface VariableLinkTextProps { text: string; } const VariableLinkText: FC = ({ text }) => { const styles = useStyles2(getStyles); return {text}; }; const LoadingIndicator: FC> = ({ onCancel }) => { const onClick = useCallback( (event: MouseEvent) => { event.preventDefault(); onCancel(); }, [onCancel] ); return ( ); }; const getStyles = (theme: GrafanaTheme2) => ({ container: css` max-width: 500px; padding-right: 10px; padding: 0 ${theme.spacing(1)}; background-color: ${theme.components.input.background}; border: 1px solid ${theme.components.input.borderColor}; border-radius: ${theme.shape.borderRadius(1)}; display: flex; align-items: center; color: ${theme.colors.text}; height: ${theme.spacing(theme.components.height.md)}; .label-tag { margin: 0 5px; } &:disabled { background-color: ${theme.colors.action.disabledBackground}; color: ${theme.colors.action.disabledText}; border: 1px solid ${theme.colors.action.disabledBackground}; } `, textAndTags: css` overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: ${theme.spacing(0.25)}; user-select: none; `, });