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