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.

76 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.scrollTo(0, easingOutQuint(0, elapsed, offset, targetY, duration));
  17. requestAnimationFrame(step);
  18. };
  19. step();
  20. return () => {
  21. interrupt = true;
  22. };
  23. };
  24. const Column = React.createClass({
  25. propTypes: {
  26. heading: React.PropTypes.string,
  27. icon: React.PropTypes.string
  28. },
  29. mixins: [PureRenderMixin],
  30. handleHeaderClick () {
  31. let node = ReactDOM.findDOMNode(this);
  32. this._interruptScrollAnimation = scrollTop(node.querySelector('.scrollable'));
  33. },
  34. handleWheel () {
  35. if (typeof this._interruptScrollAnimation !== 'undefined') {
  36. this._interruptScrollAnimation();
  37. }
  38. },
  39. handleScroll () {
  40. // todo
  41. },
  42. render () {
  43. let header = '';
  44. if (this.props.heading) {
  45. header = <ColumnHeader icon={this.props.icon} type={this.props.heading} onClick={this.handleHeaderClick} />;
  46. }
  47. const style = { width: '350px', flex: '0 0 auto', background: '#282c37', margin: '10px', marginRight: '0', display: 'flex', flexDirection: 'column' };
  48. return (
  49. <div style={style} onWheel={this.handleWheel} onScroll={this.handleScroll}>
  50. {header}
  51. {this.props.children}
  52. </div>
  53. );
  54. }
  55. });
  56. export default Column;