闭社主体 forked from https://github.com/tootsuite/mastodon
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.

52 lines
1.4 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. animating: false,
  14. };
  15. handleToggleCollapsed = () => {
  16. const currentState = this.state.collapsed;
  17. this.setState({ collapsed: !currentState, animating: true });
  18. if (!currentState && this.props.onCollapse) {
  19. this.props.onCollapse();
  20. }
  21. }
  22. handleTransitionEnd = () => {
  23. this.setState({ animating: false });
  24. }
  25. render () {
  26. const { icon, title, fullHeight, children } = this.props;
  27. const { collapsed, animating } = this.state;
  28. return (
  29. <div className={`column-collapsable ${collapsed ? 'collapsed' : ''}`} onTransitionEnd={this.handleTransitionEnd}>
  30. <div role='button' tabIndex='0' title={`${title}`} className='column-collapsable__button column-icon' onClick={this.handleToggleCollapsed}>
  31. <i className={`fa fa-${icon}`} />
  32. </div>
  33. <div className='column-collapsable__content' style={{ height: `${fullHeight}px` }}>
  34. {(!collapsed || animating) && children}
  35. </div>
  36. </div>
  37. );
  38. }
  39. }
  40. export default ColumnCollapsable;