You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
834 B

  1. import React from 'react';
  2. import Motion from 'flavours/glitch/util/optional_motion';
  3. import spring from 'react-motion/lib/spring';
  4. import PropTypes from 'prop-types';
  5. const Collapsable = ({ fullHeight, isVisible, children }) => (
  6. <Motion defaultStyle={{ opacity: !isVisible ? 0 : 100, height: isVisible ? fullHeight : 0 }} style={{ opacity: spring(!isVisible ? 0 : 100), height: spring(!isVisible ? 0 : fullHeight) }}>
  7. {({ opacity, height }) =>
  8. (<div style={{ height: `${height}px`, overflow: 'hidden', opacity: opacity / 100, display: Math.floor(opacity) === 0 ? 'none' : 'block' }}>
  9. {children}
  10. </div>)
  11. }
  12. </Motion>
  13. );
  14. Collapsable.propTypes = {
  15. fullHeight: PropTypes.number.isRequired,
  16. isVisible: PropTypes.bool.isRequired,
  17. children: PropTypes.node.isRequired,
  18. };
  19. export default Collapsable;