The code powering m.abunchtell.com https://m.abunchtell.com
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

67 líneas
1.9 KiB

  1. import { Motion, spring } from 'react-motion';
  2. import PropTypes from 'prop-types';
  3. const iconStyle = {
  4. fontSize: '16px',
  5. padding: '15px',
  6. position: 'absolute',
  7. right: '0',
  8. top: '-48px',
  9. cursor: 'pointer',
  10. zIndex: '3'
  11. };
  12. class ColumnCollapsable extends React.PureComponent {
  13. constructor (props, context) {
  14. super(props, context);
  15. this.state = {
  16. collapsed: true
  17. };
  18. this.handleToggleCollapsed = this.handleToggleCollapsed.bind(this);
  19. }
  20. handleToggleCollapsed () {
  21. const currentState = this.state.collapsed;
  22. this.setState({ collapsed: !currentState });
  23. if (!currentState && this.props.onCollapse) {
  24. this.props.onCollapse();
  25. }
  26. }
  27. render () {
  28. const { icon, title, fullHeight, children } = this.props;
  29. const { collapsed } = this.state;
  30. const collapsedClassName = collapsed ? 'collapsable-collapsed' : 'collapsable';
  31. return (
  32. <div style={{ position: 'relative' }}>
  33. <div role='button' tabIndex='0' title={`${title}`} style={{...iconStyle }} className={`column-icon ${collapsedClassName}`} onClick={this.handleToggleCollapsed}>
  34. <i className={`fa fa-${icon}`} />
  35. </div>
  36. <Motion defaultStyle={{ opacity: 0, height: 0 }} style={{ opacity: spring(collapsed ? 0 : 100), height: spring(collapsed ? 0 : fullHeight, collapsed ? undefined : { stiffness: 150, damping: 9 }) }}>
  37. {({ opacity, height }) =>
  38. <div style={{ overflow: height === fullHeight ? 'auto' : 'hidden', height: `${height}px`, opacity: opacity / 100, maxHeight: '70vh' }}>
  39. {children}
  40. </div>
  41. }
  42. </Motion>
  43. </div>
  44. );
  45. }
  46. }
  47. ColumnCollapsable.propTypes = {
  48. icon: PropTypes.string.isRequired,
  49. title: PropTypes.string,
  50. fullHeight: PropTypes.number.isRequired,
  51. children: PropTypes.node,
  52. onCollapse: PropTypes.func
  53. };
  54. export default ColumnCollapsable;