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.scrollTop = 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. children: React.PropTypes.node,
  29. active: React.PropTypes.bool
  30. },
  31. mixins: [PureRenderMixin],
  32. handleHeaderClick () {
  33. const scrollable = ReactDOM.findDOMNode(this).querySelector('.scrollable');
  34. if (!scrollable) {
  35. return;
  36. }
  37. this._interruptScrollAnimation = scrollTop(scrollable);
  38. },
  39. handleWheel () {
  40. if (typeof this._interruptScrollAnimation !== 'undefined') {
  41. this._interruptScrollAnimation();
  42. }
  43. },
  44. render () {
  45. const { heading, icon, children, active } = this.props;
  46. let header = '';
  47. if (heading) {
  48. header = <ColumnHeader icon={icon} active={active} type={heading} onClick={this.handleHeaderClick} />;
  49. }
  50. return (
  51. <div role='section' className='column' onWheel={this.handleWheel}>
  52. {header}
  53. {children}
  54. </div>
  55. );
  56. }
  57. });
  58. export default Column;