2023-05-28 15:18:23 +03:00
|
|
|
import { PureComponent } from 'react';
|
2017-02-05 02:58:25 +02:00
|
|
|
import ColumnHeader from './column_header';
|
2017-04-21 21:05:35 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-05-26 15:09:13 +03:00
|
|
|
import { debounce } from 'lodash';
|
2022-10-11 12:39:52 +03:00
|
|
|
import { scrollTop } from 'flavours/glitch/scroll';
|
|
|
|
import { isMobile } from 'flavours/glitch/is_mobile';
|
2016-09-18 19:18:46 +03:00
|
|
|
|
2023-05-28 15:18:23 +03:00
|
|
|
export default class Column extends PureComponent {
|
2016-08-31 17:15:12 +03:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
static propTypes = {
|
|
|
|
heading: PropTypes.string,
|
|
|
|
icon: PropTypes.string,
|
|
|
|
children: PropTypes.node,
|
|
|
|
active: PropTypes.bool,
|
2017-05-20 18:31:47 +03:00
|
|
|
hideHeadingOnMobile: PropTypes.bool,
|
2017-08-06 22:27:47 +03:00
|
|
|
name: PropTypes.string,
|
2022-10-03 10:40:30 +03:00
|
|
|
bindToDocument: PropTypes.bool,
|
2017-05-12 15:44:10 +03:00
|
|
|
};
|
2016-08-31 17:15:12 +03:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
handleHeaderClick = () => {
|
2022-10-03 10:40:30 +03:00
|
|
|
const scrollable = this.props.bindToDocument ? document.scrollingElement : this.node.querySelector('.scrollable');
|
2017-06-04 02:39:38 +03:00
|
|
|
|
2017-04-11 22:58:28 +03:00
|
|
|
if (!scrollable) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-04 02:39:38 +03:00
|
|
|
|
2017-04-11 22:58:28 +03:00
|
|
|
this._interruptScrollAnimation = scrollTop(scrollable);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2016-09-18 19:18:46 +03:00
|
|
|
|
2017-08-09 01:21:58 +03:00
|
|
|
scrollTop () {
|
2022-10-03 10:40:30 +03:00
|
|
|
const scrollable = this.props.bindToDocument ? document.scrollingElement : this.node.querySelector('.scrollable');
|
2017-08-09 01:21:58 +03:00
|
|
|
|
|
|
|
if (!scrollable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._interruptScrollAnimation = scrollTop(scrollable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-26 15:09:13 +03:00
|
|
|
handleScroll = debounce(() => {
|
2016-09-18 19:18:46 +03:00
|
|
|
if (typeof this._interruptScrollAnimation !== 'undefined') {
|
|
|
|
this._interruptScrollAnimation();
|
|
|
|
}
|
2023-02-03 21:52:07 +02:00
|
|
|
}, 200);
|
2016-09-18 19:18:46 +03:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
setRef = (c) => {
|
2017-05-03 03:04:16 +03:00
|
|
|
this.node = c;
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2017-05-03 03:04:16 +03:00
|
|
|
|
2016-08-31 17:15:12 +03:00
|
|
|
render () {
|
2017-08-06 22:27:47 +03:00
|
|
|
const { heading, icon, children, active, hideHeadingOnMobile, name } = this.props;
|
2017-02-05 02:58:25 +02:00
|
|
|
|
2017-07-26 16:03:23 +03:00
|
|
|
const showHeading = heading && (!hideHeadingOnMobile || (hideHeadingOnMobile && !isMobile(window.innerWidth)));
|
2016-09-10 19:36:48 +03:00
|
|
|
|
2017-07-26 14:46:53 +03:00
|
|
|
const columnHeaderId = showHeading && heading.replace(/ /g, '-');
|
|
|
|
const header = showHeading && (
|
|
|
|
<ColumnHeader icon={icon} active={active} type={heading} onClick={this.handleHeaderClick} columnHeaderId={columnHeaderId} />
|
|
|
|
);
|
2017-02-05 05:11:14 +02:00
|
|
|
return (
|
2017-05-03 03:04:16 +03:00
|
|
|
<div
|
|
|
|
ref={this.setRef}
|
|
|
|
role='region'
|
2017-08-06 22:27:47 +03:00
|
|
|
data-column={name}
|
2017-05-03 03:04:16 +03:00
|
|
|
aria-labelledby={columnHeaderId}
|
|
|
|
className='column'
|
2017-06-06 14:20:07 +03:00
|
|
|
onScroll={this.handleScroll}
|
|
|
|
>
|
2016-09-10 19:36:48 +03:00
|
|
|
{header}
|
2017-02-05 02:58:25 +02:00
|
|
|
{children}
|
2016-08-24 18:56:44 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-08-31 17:15:12 +03:00
|
|
|
|
2017-04-21 21:05:35 +03:00
|
|
|
}
|