2017-02-05 02:58:25 +02:00
|
|
|
import ColumnHeader from './column_header';
|
2016-09-10 19:36:48 +03:00
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
2016-08-24 18:56:44 +03:00
|
|
|
|
2016-09-18 19:18:46 +03:00
|
|
|
const easingOutQuint = (x, t, b, c, d) => c*((t=t/d-1)*t*t*t*t + 1) + b;
|
|
|
|
|
|
|
|
const scrollTop = (node) => {
|
|
|
|
const startTime = Date.now();
|
|
|
|
const offset = node.scrollTop;
|
|
|
|
const targetY = -offset;
|
|
|
|
const duration = 1000;
|
|
|
|
let interrupt = false;
|
|
|
|
|
|
|
|
const step = () => {
|
|
|
|
const elapsed = Date.now() - startTime;
|
|
|
|
const percentage = elapsed / duration;
|
|
|
|
|
|
|
|
if (percentage > 1 || interrupt) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-06 17:18:32 +03:00
|
|
|
node.scrollTop = easingOutQuint(0, elapsed, offset, targetY, duration);
|
2016-09-18 19:18:46 +03:00
|
|
|
requestAnimationFrame(step);
|
|
|
|
};
|
|
|
|
|
|
|
|
step();
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
interrupt = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-08-24 18:56:44 +03:00
|
|
|
const Column = React.createClass({
|
2016-08-31 17:15:12 +03:00
|
|
|
|
2016-08-24 18:56:44 +03:00
|
|
|
propTypes: {
|
2016-09-10 19:36:48 +03:00
|
|
|
heading: React.PropTypes.string,
|
2017-01-02 15:09:57 +02:00
|
|
|
icon: React.PropTypes.string,
|
2017-02-21 01:10:49 +02:00
|
|
|
children: React.PropTypes.node,
|
|
|
|
active: React.PropTypes.bool
|
2016-08-24 18:56:44 +03:00
|
|
|
},
|
|
|
|
|
2016-08-31 17:15:12 +03:00
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
2016-09-06 01:44:28 +03:00
|
|
|
handleHeaderClick () {
|
|
|
|
let node = ReactDOM.findDOMNode(this);
|
2016-09-18 19:18:46 +03:00
|
|
|
this._interruptScrollAnimation = scrollTop(node.querySelector('.scrollable'));
|
|
|
|
},
|
|
|
|
|
|
|
|
handleWheel () {
|
|
|
|
if (typeof this._interruptScrollAnimation !== 'undefined') {
|
|
|
|
this._interruptScrollAnimation();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-08-31 17:15:12 +03:00
|
|
|
render () {
|
2017-02-21 01:10:49 +02:00
|
|
|
const { heading, icon, children, active } = this.props;
|
2017-02-05 02:58:25 +02:00
|
|
|
|
2016-09-10 19:36:48 +03:00
|
|
|
let header = '';
|
|
|
|
|
2017-02-05 02:58:25 +02:00
|
|
|
if (heading) {
|
2017-02-21 01:10:49 +02:00
|
|
|
header = <ColumnHeader icon={icon} active={active} type={heading} onClick={this.handleHeaderClick} />;
|
2016-09-10 19:36:48 +03:00
|
|
|
}
|
|
|
|
|
2017-02-05 05:11:14 +02:00
|
|
|
return (
|
2017-02-09 02:20:09 +02:00
|
|
|
<div className='column' onWheel={this.handleWheel}>
|
2016-09-10 19:36:48 +03:00
|
|
|
{header}
|
2017-02-05 02:58:25 +02:00
|
|
|
{children}
|
2016-08-24 18:56:44 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-08-31 17:15:12 +03:00
|
|
|
|
2016-08-24 18:56:44 +03:00
|
|
|
});
|
|
|
|
|
2017-02-05 05:11:14 +02:00
|
|
|
export default Column;
|