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