2017-06-04 08:39:38 +09:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-07-25 08:05:51 +09:00
|
|
|
import detectPassiveEvents from 'detect-passive-events';
|
2017-12-04 16:26:40 +09:00
|
|
|
import { scrollTop } from 'flavours/glitch/util/scroll';
|
2017-06-04 08:39:38 +09:00
|
|
|
|
2017-06-24 02:36:54 +09:00
|
|
|
export default class Column extends React.PureComponent {
|
2017-06-04 08:39:38 +09:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
2017-07-31 01:36:28 +09:00
|
|
|
extraClasses: PropTypes.string,
|
2017-08-07 04:27:47 +09:00
|
|
|
name: PropTypes.string,
|
2018-08-28 19:01:04 +09:00
|
|
|
label: PropTypes.string,
|
2017-06-04 08:39:38 +09: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 08:05:51 +09:00
|
|
|
componentDidMount () {
|
2017-08-31 18:20:54 +09:00
|
|
|
this.node.addEventListener('wheel', this.handleWheel, detectPassiveEvents.hasSupport ? { passive: true } : false);
|
2017-07-25 08:05:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
this.node.removeEventListener('wheel', this.handleWheel);
|
|
|
|
}
|
|
|
|
|
2017-06-04 08:39:38 +09:00
|
|
|
render () {
|
2018-08-28 19:01:04 +09:00
|
|
|
const { children, extraClasses, name, label } = this.props;
|
2017-06-04 08:39:38 +09:00
|
|
|
|
|
|
|
return (
|
2018-08-28 19:01:04 +09:00
|
|
|
<div role='region' aria-label={label} data-column={name} className={`column ${extraClasses || ''}`} ref={this.setRef}>
|
2017-06-04 08:39:38 +09:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|