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