You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.2 KiB
55 lines
1.2 KiB
8 years ago
|
import React from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
8 years ago
|
import detectPassiveEvents from 'detect-passive-events';
|
||
7 years ago
|
import { scrollTop } from 'flavours/glitch/util/scroll';
|
||
8 years ago
|
|
||
8 years ago
|
export default class Column extends React.PureComponent {
|
||
8 years ago
|
|
||
|
static propTypes = {
|
||
|
children: PropTypes.node,
|
||
7 years ago
|
extraClasses: PropTypes.string,
|
||
7 years ago
|
name: PropTypes.string,
|
||
8 years ago
|
};
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
8 years ago
|
componentDidMount () {
|
||
7 years ago
|
this.node.addEventListener('wheel', this.handleWheel, detectPassiveEvents.hasSupport ? { passive: true } : false);
|
||
8 years ago
|
}
|
||
|
|
||
|
componentWillUnmount () {
|
||
|
this.node.removeEventListener('wheel', this.handleWheel);
|
||
|
}
|
||
|
|
||
8 years ago
|
render () {
|
||
7 years ago
|
const { children, extraClasses, name } = this.props;
|
||
8 years ago
|
|
||
|
return (
|
||
7 years ago
|
<div role='region' data-column={name} className={`column ${extraClasses || ''}`} ref={this.setRef}>
|
||
8 years ago
|
{children}
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|