2017-06-04 01:39:38 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-07-25 01:05:51 +02:00
|
|
|
import detectPassiveEvents from 'detect-passive-events';
|
2017-11-18 04:11:18 +01:00
|
|
|
import { scrollTop } from 'themes/glitch/util/scroll';
|
2017-06-04 01:39:38 +02:00
|
|
|
|
2017-06-23 19:36:54 +02:00
|
|
|
export default class Column extends React.PureComponent {
|
2017-06-04 01:39:38 +02:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
2017-07-30 18:36:28 +02:00
|
|
|
extraClasses: PropTypes.string,
|
2017-08-06 21:27:47 +02:00
|
|
|
name: PropTypes.string,
|
2017-06-04 01:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
scrollTop () {
|
|
|
|
const scrollable = this.node.querySelector('.scrollable');
|
|
|
|
|
|
|
|
if (!scrollable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._interruptScrollAnimation = scrollTop(scrollable);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleWheel = () => {
|
|
|
|
if (typeof this._interruptScrollAnimation !== 'function') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._interruptScrollAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.node = c;
|
|
|
|
}
|
|
|
|
|
2017-07-25 01:05:51 +02:00
|
|
|
componentDidMount () {
|
2017-08-31 11:20:54 +02:00
|
|
|
this.node.addEventListener('wheel', this.handleWheel, detectPassiveEvents.hasSupport ? { passive: true } : false);
|
2017-07-25 01:05:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
this.node.removeEventListener('wheel', this.handleWheel);
|
|
|
|
}
|
|
|
|
|
2017-06-04 01:39:38 +02:00
|
|
|
render () {
|
2017-08-06 21:27:47 +02:00
|
|
|
const { children, extraClasses, name } = this.props;
|
2017-06-04 01:39:38 +02:00
|
|
|
|
|
|
|
return (
|
2017-08-06 21:27:47 +02:00
|
|
|
<div role='region' data-column={name} className={`column ${extraClasses || ''}`} ref={this.setRef}>
|
2017-06-04 01:39:38 +02:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|