LiveTailButton.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { CSSTransition } from 'react-transition-group';
  4. import { Tooltip, ButtonGroup, ToolbarButton } from '@grafana/ui';
  5. type LiveTailButtonProps = {
  6. splitted: boolean;
  7. start: () => void;
  8. stop: () => void;
  9. pause: () => void;
  10. resume: () => void;
  11. isLive: boolean;
  12. isPaused: boolean;
  13. };
  14. export function LiveTailButton(props: LiveTailButtonProps) {
  15. const { start, pause, resume, isLive, isPaused, stop, splitted } = props;
  16. const buttonVariant = isLive && !isPaused ? 'active' : 'default';
  17. const onClickMain = isLive ? (isPaused ? resume : pause) : start;
  18. return (
  19. <ButtonGroup>
  20. <Tooltip
  21. content={isLive && !isPaused ? <>Pause the live stream</> : <>Start live stream your logs</>}
  22. placement="bottom"
  23. >
  24. <ToolbarButton
  25. iconOnly={splitted}
  26. variant={buttonVariant}
  27. icon={!isLive || isPaused ? 'play' : 'pause'}
  28. onClick={onClickMain}
  29. >
  30. {isLive && isPaused ? 'Paused' : 'Live'}
  31. </ToolbarButton>
  32. </Tooltip>
  33. <CSSTransition
  34. mountOnEnter={true}
  35. unmountOnExit={true}
  36. timeout={100}
  37. in={isLive}
  38. classNames={{
  39. enter: styles.stopButtonEnter,
  40. enterActive: styles.stopButtonEnterActive,
  41. exit: styles.stopButtonExit,
  42. exitActive: styles.stopButtonExitActive,
  43. }}
  44. >
  45. <Tooltip content={<>Stop and exit the live stream</>} placement="bottom">
  46. <ToolbarButton variant={buttonVariant} onClick={stop} icon="square-shape" />
  47. </Tooltip>
  48. </CSSTransition>
  49. </ButtonGroup>
  50. );
  51. }
  52. const styles = {
  53. stopButtonEnter: css`
  54. label: stopButtonEnter;
  55. width: 0;
  56. opacity: 0;
  57. overflow: hidden;
  58. `,
  59. stopButtonEnterActive: css`
  60. label: stopButtonEnterActive;
  61. opacity: 1;
  62. width: 32px;
  63. `,
  64. stopButtonExit: css`
  65. label: stopButtonExit;
  66. width: 32px;
  67. opacity: 1;
  68. overflow: hidden;
  69. `,
  70. stopButtonExitActive: css`
  71. label: stopButtonExitActive;
  72. opacity: 0;
  73. width: 0;
  74. `,
  75. };