2017-06-04 08:39:38 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-24 00:15:17 +09:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2020-11-05 02:21:05 +09:00
|
|
|
import { supportsPassiveEvents } from 'detect-passive-events';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
2017-08-05 01:57:46 +09:00
|
|
|
import { scrollTop } from '../scroll';
|
2017-06-04 08:39:38 +09:00
|
|
|
|
2023-05-22 22:48:01 +09:00
|
|
|
const listenerOptions = supportsPassiveEvents ? { passive: true } : false;
|
|
|
|
|
2023-05-23 17:52:27 +09:00
|
|
|
export default class Column extends PureComponent {
|
2017-06-04 08:39:38 +09:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
2018-08-24 00:26:21 +09:00
|
|
|
label: PropTypes.string,
|
2019-08-02 02:17:17 +09:00
|
|
|
bindToDocument: PropTypes.bool,
|
2017-06-04 08:39:38 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
scrollTop () {
|
2023-08-24 21:10:48 +09:00
|
|
|
let scrollable = null;
|
|
|
|
|
|
|
|
if (this.props.bindToDocument) {
|
|
|
|
scrollable = document.scrollingElement;
|
|
|
|
} else {
|
|
|
|
scrollable = this.node.querySelector('.scrollable');
|
2023-10-09 20:38:29 +09:00
|
|
|
}
|
2017-06-04 08:39:38 +09:00
|
|
|
|
|
|
|
if (!scrollable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._interruptScrollAnimation = scrollTop(scrollable);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleWheel = () => {
|
|
|
|
if (typeof this._interruptScrollAnimation !== 'function') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._interruptScrollAnimation();
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2017-06-04 08:39:38 +09:00
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.node = c;
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2017-06-04 08:39:38 +09:00
|
|
|
|
2017-07-25 08:05:51 +09:00
|
|
|
componentDidMount () {
|
2019-08-02 02:17:17 +09:00
|
|
|
if (this.props.bindToDocument) {
|
2023-05-22 22:48:01 +09:00
|
|
|
document.addEventListener('wheel', this.handleWheel, listenerOptions);
|
2019-08-02 02:17:17 +09:00
|
|
|
} else {
|
2023-05-22 22:48:01 +09:00
|
|
|
this.node.addEventListener('wheel', this.handleWheel, listenerOptions);
|
2019-08-02 02:17:17 +09:00
|
|
|
}
|
2017-07-25 08:05:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
2019-08-02 02:17:17 +09:00
|
|
|
if (this.props.bindToDocument) {
|
2023-05-22 22:48:01 +09:00
|
|
|
document.removeEventListener('wheel', this.handleWheel, listenerOptions);
|
2019-08-02 02:17:17 +09:00
|
|
|
} else {
|
2023-05-22 22:48:01 +09:00
|
|
|
this.node.removeEventListener('wheel', this.handleWheel, listenerOptions);
|
2019-08-02 02:17:17 +09:00
|
|
|
}
|
2017-07-25 08:05:51 +09:00
|
|
|
}
|
|
|
|
|
2017-06-04 08:39:38 +09:00
|
|
|
render () {
|
2018-08-24 00:26:21 +09:00
|
|
|
const { label, children } = this.props;
|
2017-06-04 08:39:38 +09:00
|
|
|
|
|
|
|
return (
|
2018-08-24 00:26:21 +09:00
|
|
|
<div role='region' aria-label={label} className='column' ref={this.setRef}>
|
2017-06-04 08:39:38 +09:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|