2017-05-03 00:04:16 +00:00
|
|
|
import React from 'react';
|
2017-02-05 00:58:25 +00:00
|
|
|
import ColumnHeader from './column_header';
|
2017-04-21 18:05:35 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2016-08-24 15:56:44 +00:00
|
|
|
|
2016-09-18 16:18:46 +00: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 14:18:32 +00:00
|
|
|
node.scrollTop = easingOutQuint(0, elapsed, offset, targetY, duration);
|
2016-09-18 16:18:46 +00:00
|
|
|
requestAnimationFrame(step);
|
|
|
|
};
|
|
|
|
|
|
|
|
step();
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
interrupt = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-04-21 18:05:35 +00:00
|
|
|
class Column extends React.PureComponent {
|
2016-08-31 14:15:12 +00:00
|
|
|
|
2017-04-21 18:05:35 +00:00
|
|
|
constructor (props, context) {
|
|
|
|
super(props, context);
|
|
|
|
this.handleHeaderClick = this.handleHeaderClick.bind(this);
|
|
|
|
this.handleWheel = this.handleWheel.bind(this);
|
2017-05-03 00:04:16 +00:00
|
|
|
this.setRef = this.setRef.bind(this);
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
2016-08-31 14:15:12 +00:00
|
|
|
|
2016-09-05 22:44:28 +00:00
|
|
|
handleHeaderClick () {
|
2017-05-03 00:04:16 +00:00
|
|
|
const scrollable = this.node.querySelector('.scrollable');
|
2017-04-11 19:58:28 +00:00
|
|
|
if (!scrollable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._interruptScrollAnimation = scrollTop(scrollable);
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
2016-09-18 16:18:46 +00:00
|
|
|
|
|
|
|
handleWheel () {
|
|
|
|
if (typeof this._interruptScrollAnimation !== 'undefined') {
|
|
|
|
this._interruptScrollAnimation();
|
|
|
|
}
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
2016-09-18 16:18:46 +00:00
|
|
|
|
2017-05-03 00:04:16 +00:00
|
|
|
setRef (c) {
|
|
|
|
this.node = c;
|
|
|
|
}
|
|
|
|
|
2016-08-31 14:15:12 +00:00
|
|
|
render () {
|
2017-04-21 16:17:55 +00:00
|
|
|
const { heading, icon, children, active, hideHeadingOnMobile } = this.props;
|
2017-02-05 00:58:25 +00:00
|
|
|
|
2017-04-22 15:30:35 +00:00
|
|
|
let columnHeaderId = null
|
2016-09-10 16:36:48 +00:00
|
|
|
let header = '';
|
|
|
|
|
2017-02-05 00:58:25 +00:00
|
|
|
if (heading) {
|
2017-04-22 15:30:35 +00:00
|
|
|
columnHeaderId = heading.replace(/ /g, '-')
|
|
|
|
header = <ColumnHeader icon={icon} active={active} type={heading} onClick={this.handleHeaderClick} hideOnMobile={hideHeadingOnMobile} columnHeaderId={columnHeaderId}/>;
|
2016-09-10 16:36:48 +00:00
|
|
|
}
|
2017-02-05 03:11:14 +00:00
|
|
|
return (
|
2017-05-03 00:04:16 +00:00
|
|
|
<div
|
|
|
|
ref={this.setRef}
|
|
|
|
role='region'
|
|
|
|
aria-labelledby={columnHeaderId}
|
|
|
|
className='column'
|
|
|
|
onWheel={this.handleWheel}>
|
2016-09-10 16:36:48 +00:00
|
|
|
{header}
|
2017-02-05 00:58:25 +00:00
|
|
|
{children}
|
2016-08-24 15:56:44 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-08-31 14:15:12 +00:00
|
|
|
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Column.propTypes = {
|
|
|
|
heading: PropTypes.string,
|
|
|
|
icon: PropTypes.string,
|
|
|
|
children: PropTypes.node,
|
|
|
|
active: PropTypes.bool,
|
|
|
|
hideHeadingOnMobile: PropTypes.bool
|
|
|
|
};
|
2016-08-24 15:56:44 +00:00
|
|
|
|
2017-02-05 03:11:14 +00:00
|
|
|
export default Column;
|