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.

79 lines
1.7 KiB

  1. import ColumnHeader from './column_header';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. const easingOutQuint = (x, t, b, c, d) => c*((t=t/d-1)*t*t*t*t + 1) + b;
  4. const scrollTop = (node) => {
  5. const startTime = Date.now();
  6. const offset = node.scrollTop;
  7. const targetY = -offset;
  8. const duration = 1000;
  9. let interrupt = false;
  10. const step = () => {
  11. const elapsed = Date.now() - startTime;
  12. const percentage = elapsed / duration;
  13. if (percentage > 1 || interrupt) {
  14. return;
  15. }
  16. node.scrollTop = easingOutQuint(0, elapsed, offset, targetY, duration);
  17. requestAnimationFrame(step);
  18. };
  19. step();
  20. return () => {
  21. interrupt = true;
  22. };
  23. };
  24. const style = {
  25. boxSizing: 'border-box',
  26. background: '#282c37',
  27. display: 'flex',
  28. flexDirection: 'column'
  29. };
  30. const Column = React.createClass({
  31. propTypes: {
  32. heading: React.PropTypes.string,
  33. icon: React.PropTypes.string,
  34. children: React.PropTypes.node
  35. },
  36. mixins: [PureRenderMixin],
  37. handleHeaderClick () {
  38. let node = ReactDOM.findDOMNode(this);
  39. this._interruptScrollAnimation = scrollTop(node.querySelector('.scrollable'));
  40. },
  41. handleWheel () {
  42. if (typeof this._interruptScrollAnimation !== 'undefined') {
  43. this._interruptScrollAnimation();
  44. }
  45. },
  46. render () {
  47. const { heading, icon, children } = this.props;
  48. let header = '';
  49. if (heading) {
  50. header = <ColumnHeader icon={icon} type={heading} onClick={this.handleHeaderClick} />;
  51. }
  52. return (
  53. <div className='column' style={style} onWheel={this.handleWheel}>
  54. {header}
  55. {children}
  56. </div>
  57. );
  58. }
  59. });
  60. export default Column;