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