PanelHeaderLoadingIndicator.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { css } from '@emotion/css';
  2. import React, { FC } from 'react';
  3. import { GrafanaTheme, LoadingState } from '@grafana/data';
  4. import { Icon, Tooltip, useStyles } from '@grafana/ui';
  5. interface Props {
  6. state: LoadingState;
  7. onClick: () => void;
  8. }
  9. export const PanelHeaderLoadingIndicator: FC<Props> = ({ state, onClick }) => {
  10. const styles = useStyles(getStyles);
  11. if (state === LoadingState.Loading) {
  12. return (
  13. <div className="panel-loading" onClick={onClick}>
  14. <Tooltip content="Cancel query">
  15. <Icon className="panel-loading__spinner spin-clockwise" name="sync" />
  16. </Tooltip>
  17. </div>
  18. );
  19. }
  20. if (state === LoadingState.Streaming) {
  21. return (
  22. <div className="panel-loading" onClick={onClick}>
  23. <div title="Streaming (click to stop)" className={styles.streamIndicator} />
  24. </div>
  25. );
  26. }
  27. return null;
  28. };
  29. function getStyles(theme: GrafanaTheme) {
  30. return {
  31. streamIndicator: css`
  32. width: 10px;
  33. height: 10px;
  34. background: ${theme.colors.textFaint};
  35. box-shadow: 0 0 2px ${theme.colors.textFaint};
  36. border-radius: 50%;
  37. position: relative;
  38. top: 6px;
  39. right: 1px;
  40. `,
  41. };
  42. }