The code powering m.abunchtell.com https://m.abunchtell.com
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
773 B

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