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