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.
65 lines
1.6 KiB
65 lines
1.6 KiB
8 years ago
|
import React from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
4 years ago
|
import { supportsPassiveEvents } from 'detect-passive-events';
|
||
2 years ago
|
import { scrollTop } from '../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,
|
||
6 years ago
|
label: PropTypes.string,
|
||
5 years ago
|
bindToDocument: PropTypes.bool,
|
||
8 years ago
|
};
|
||
|
|
||
|
scrollTop () {
|
||
5 years ago
|
const scrollable = this.props.bindToDocument ? document.scrollingElement : this.node.querySelector('.scrollable');
|
||
8 years ago
|
|
||
|
if (!scrollable) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
this._interruptScrollAnimation = scrollTop(scrollable);
|
||
|
}
|
||
|
|
||
|
handleWheel = () => {
|
||
|
if (typeof this._interruptScrollAnimation !== 'function') {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
this._interruptScrollAnimation();
|
||
2 years ago
|
};
|
||
8 years ago
|
|
||
|
setRef = c => {
|
||
|
this.node = c;
|
||
2 years ago
|
};
|
||
8 years ago
|
|
||
7 years ago
|
componentDidMount () {
|
||
5 years ago
|
if (this.props.bindToDocument) {
|
||
4 years ago
|
document.addEventListener('wheel', this.handleWheel, supportsPassiveEvents ? { passive: true } : false);
|
||
5 years ago
|
} else {
|
||
4 years ago
|
this.node.addEventListener('wheel', this.handleWheel, supportsPassiveEvents ? { passive: true } : false);
|
||
5 years ago
|
}
|
||
7 years ago
|
}
|
||
|
|
||
|
componentWillUnmount () {
|
||
5 years ago
|
if (this.props.bindToDocument) {
|
||
|
document.removeEventListener('wheel', this.handleWheel);
|
||
|
} else {
|
||
|
this.node.removeEventListener('wheel', this.handleWheel);
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
8 years ago
|
render () {
|
||
6 years ago
|
const { children, extraClasses, name, label } = this.props;
|
||
8 years ago
|
|
||
|
return (
|
||
6 years ago
|
<div role='region' aria-label={label} data-column={name} className={`column ${extraClasses || ''}`} ref={this.setRef}>
|
||
8 years ago
|
{children}
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|