SlideDown.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import React from 'react';
  2. import Transition from 'react-transition-group/Transition';
  3. const defaultMaxHeight = '200px'; // When animating using max-height we need to use a static value.
  4. // If this is not enough, pass in <SlideDown maxHeight="....
  5. const defaultDuration = 200;
  6. const defaultStyle = {
  7. transition: `max-height ${defaultDuration}ms ease-in-out`,
  8. overflow: 'hidden',
  9. };
  10. export default ({ children, in: inProp, maxHeight = defaultMaxHeight }) => {
  11. // There are 4 main states a Transition can be in:
  12. // ENTERING, ENTERED, EXITING, EXITED
  13. // https://reactcommunity.org/react-transition-group/
  14. const transitionStyles = {
  15. exited: { maxHeight: 0 },
  16. entering: { maxHeight: maxHeight },
  17. entered: { maxHeight: maxHeight, overflow: 'visible' },
  18. exiting: { maxHeight: 0 },
  19. };
  20. return (
  21. <Transition in={inProp} timeout={defaultDuration}>
  22. {state => (
  23. <div
  24. style={{
  25. ...defaultStyle,
  26. ...transitionStyles[state],
  27. }}
  28. >
  29. {children}
  30. </div>
  31. )}
  32. </Transition>
  33. );
  34. };