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