You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

  1. import React from 'react';
  2. import ColumnHeader from './column_header';
  3. import PropTypes from 'prop-types';
  4. import { debounce } from 'lodash';
  5. import scrollTop from '../../../scroll';
  6. class Column extends React.PureComponent {
  7. static propTypes = {
  8. heading: PropTypes.string,
  9. icon: PropTypes.string,
  10. children: PropTypes.node,
  11. active: PropTypes.bool,
  12. hideHeadingOnMobile: PropTypes.bool,
  13. };
  14. handleHeaderClick = () => {
  15. const scrollable = this.node.querySelector('.scrollable');
  16. if (!scrollable) {
  17. return;
  18. }
  19. this._interruptScrollAnimation = scrollTop(scrollable);
  20. }
  21. handleScroll = debounce(() => {
  22. if (typeof this._interruptScrollAnimation !== 'undefined') {
  23. this._interruptScrollAnimation();
  24. }
  25. }, 200)
  26. setRef = (c) => {
  27. this.node = c;
  28. }
  29. render () {
  30. const { heading, icon, children, active, hideHeadingOnMobile } = this.props;
  31. let columnHeaderId = null;
  32. let header = '';
  33. if (heading) {
  34. columnHeaderId = heading.replace(/ /g, '-');
  35. header = <ColumnHeader icon={icon} active={active} type={heading} onClick={this.handleHeaderClick} hideOnMobile={hideHeadingOnMobile} columnHeaderId={columnHeaderId}/>;
  36. }
  37. return (
  38. <div
  39. ref={this.setRef}
  40. role='region'
  41. aria-labelledby={columnHeaderId}
  42. className='column'
  43. onScroll={this.handleScroll}>
  44. {header}
  45. {children}
  46. </div>
  47. );
  48. }
  49. }
  50. export default Column;