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