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-08-04 19:57:46 +03:00
|
|
|
import { scrollTop } from '../../../scroll';
|
2017-07-26 14:46:53 +03:00
|
|
|
import { isMobile } from '../../../is_mobile';
|
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);
|
2023-01-30 02:45:35 +02:00
|
|
|
};
|
2016-09-18 19:18:46 +03:00
|
|
|
|
2017-08-09 01:21:58 +03:00
|
|
|
scrollTop () {
|
|
|
|
const scrollable = this.node.querySelector('.scrollable');
|
|
|
|
|
|
|
|
if (!scrollable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._interruptScrollAnimation = scrollTop(scrollable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2023-01-30 02:45:35 +02: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;
|
2023-01-30 02:45:35 +02:00
|
|
|
};
|
2017-05-03 03:04:16 +03:00
|
|
|
|
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-07-26 16:03:23 +03:00
|
|
|
const showHeading = heading && (!hideHeadingOnMobile || (hideHeadingOnMobile && !isMobile(window.innerWidth)));
|
2016-09-10 19:36:48 +03:00
|
|
|
|
2017-07-26 14:46:53 +03: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 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
|
|
|
}
|