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