LogsCrossFadeTransition.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React from 'react';
  2. import memoizeOne from 'memoize-one';
  3. import { css } from 'emotion';
  4. import { CSSTransition } from 'react-transition-group';
  5. const transitionDuration = 500;
  6. // We add a bit of delay to the transition as another perf optimisation. As at the start we need to render
  7. // quite a bit of new rows, if we start transition at the same time there can be frame rate drop. This gives time
  8. // for react to first render them and then do the animation.
  9. const transitionDelay = 100;
  10. const getStyles = memoizeOne(() => {
  11. return {
  12. logsEnter: css`
  13. label: logsEnter;
  14. position: absolute;
  15. opacity: 0;
  16. height: auto;
  17. width: auto;
  18. `,
  19. logsEnterActive: css`
  20. label: logsEnterActive;
  21. opacity: 1;
  22. transition: opacity ${transitionDuration}ms ease-out ${transitionDelay}ms;
  23. `,
  24. logsExit: css`
  25. label: logsExit;
  26. position: absolute;
  27. opacity: 1;
  28. height: auto;
  29. width: auto;
  30. `,
  31. logsExitActive: css`
  32. label: logsExitActive;
  33. opacity: 0;
  34. transition: opacity ${transitionDuration}ms ease-out ${transitionDelay}ms;
  35. `,
  36. };
  37. });
  38. type Props = {
  39. children: React.ReactNode;
  40. visible: boolean;
  41. };
  42. /**
  43. * Cross fade transition component that is tied a bit too much to the logs containers so not very useful elsewhere
  44. * right now.
  45. */
  46. export function LogsCrossFadeTransition(props: Props) {
  47. const { visible, children } = props;
  48. const styles = getStyles();
  49. return (
  50. <CSSTransition
  51. in={visible}
  52. mountOnEnter={true}
  53. unmountOnExit={true}
  54. timeout={transitionDuration + transitionDelay}
  55. classNames={{
  56. enter: styles.logsEnter,
  57. enterActive: styles.logsEnterActive,
  58. exit: styles.logsExit,
  59. exitActive: styles.logsExitActive,
  60. }}
  61. >
  62. {children}
  63. </CSSTransition>
  64. );
  65. }