diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-02-13 17:20:18 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-02-13 17:20:18 +0100 |
commit | 677e95031e179ccdd69162002ccbfb482f396e4e (patch) | |
tree | 1b7b02b4335772e54f412eecc11e8ef56a1286e3 /app/assets/javascripts/components/components/collapsable.jsx | |
parent | 2d8a4c4390acba310972d7dac21b93c4e2ac9f4e (diff) |
Clean up collapsible components
Diffstat (limited to 'app/assets/javascripts/components/components/collapsable.jsx')
-rw-r--r-- | app/assets/javascripts/components/components/collapsable.jsx | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/assets/javascripts/components/components/collapsable.jsx b/app/assets/javascripts/components/components/collapsable.jsx new file mode 100644 index 000000000..aeebb4b0f --- /dev/null +++ b/app/assets/javascripts/components/components/collapsable.jsx @@ -0,0 +1,19 @@ +import { Motion, spring } from 'react-motion'; + +const Collapsable = ({ fullHeight, isVisible, children }) => ( + <Motion defaultStyle={{ opacity: !isVisible ? 0 : 100, height: isVisible ? fullHeight : 0 }} style={{ opacity: spring(!isVisible ? 0 : 100), height: spring(!isVisible ? 0 : fullHeight) }}> + {({ opacity, height }) => + <div style={{ height: `${height}px`, overflow: 'hidden', opacity: opacity / 100, display: Math.floor(opacity) === 0 ? 'none' : 'block' }}> + {children} + </div> + } + </Motion> +); + +Collapsable.propTypes = { + fullHeight: React.PropTypes.number.isRequired, + isVisible: React.PropTypes.bool.isRequired, + children: React.PropTypes.node.isRequired +}; + +export default Collapsable; |