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.

47 lines
1.2 KiB

7 years ago
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. class ColumnCollapsable extends React.PureComponent {
  4. static propTypes = {
  5. icon: PropTypes.string.isRequired,
  6. title: PropTypes.string,
  7. fullHeight: PropTypes.number.isRequired,
  8. children: PropTypes.node,
  9. onCollapse: PropTypes.func,
  10. };
  11. state = {
  12. collapsed: true,
  13. };
  14. handleToggleCollapsed = () => {
  15. const currentState = this.state.collapsed;
  16. this.setState({ collapsed: !currentState });
  17. if (!currentState && this.props.onCollapse) {
  18. this.props.onCollapse();
  19. }
  20. }
  21. render () {
  22. const { icon, title, fullHeight, children } = this.props;
  23. const { collapsed } = this.state;
  24. return (
  25. <div className={`column-collapsable ${collapsed ? 'collapsed' : ''}`}>
  26. <div role='button' tabIndex='0' title={`${title}`} className='column-collapsable__button column-icon' onClick={this.handleToggleCollapsed}>
  27. <i className={`fa fa-${icon}`} />
  28. </div>
  29. <div className='column-collapsable__content' style={{ height: `${fullHeight}px` }}>
  30. {!collapsed && children}
  31. </div>
  32. </div>
  33. );
  34. }
  35. }
  36. export default ColumnCollapsable;