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