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