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.

74 lines
1.8 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 'flavours/glitch/util/scroll';
  6. import { isMobile } from 'flavours/glitch/util/is_mobile';
  7. export default class Column extends React.PureComponent {
  8. static propTypes = {
  9. heading: PropTypes.string,
  10. icon: PropTypes.string,
  11. children: PropTypes.node,
  12. active: PropTypes.bool,
  13. hideHeadingOnMobile: PropTypes.bool,
  14. name: PropTypes.string,
  15. };
  16. handleHeaderClick = () => {
  17. const scrollable = this.node.querySelector('.scrollable');
  18. if (!scrollable) {
  19. return;
  20. }
  21. this._interruptScrollAnimation = scrollTop(scrollable);
  22. }
  23. scrollTop () {
  24. const scrollable = this.node.querySelector('.scrollable');
  25. if (!scrollable) {
  26. return;
  27. }
  28. this._interruptScrollAnimation = scrollTop(scrollable);
  29. }
  30. handleScroll = debounce(() => {
  31. if (typeof this._interruptScrollAnimation !== 'undefined') {
  32. this._interruptScrollAnimation();
  33. }
  34. }, 200)
  35. setRef = (c) => {
  36. this.node = c;
  37. }
  38. render () {
  39. const { heading, icon, children, active, hideHeadingOnMobile, name } = this.props;
  40. const showHeading = heading && (!hideHeadingOnMobile || (hideHeadingOnMobile && !isMobile(window.innerWidth)));
  41. const columnHeaderId = showHeading && heading.replace(/ /g, '-');
  42. const header = showHeading && (
  43. <ColumnHeader icon={icon} active={active} type={heading} onClick={this.handleHeaderClick} columnHeaderId={columnHeaderId} />
  44. );
  45. return (
  46. <div
  47. ref={this.setRef}
  48. role='region'
  49. data-column={name}
  50. aria-labelledby={columnHeaderId}
  51. className='column'
  52. onScroll={this.handleScroll}
  53. >
  54. {header}
  55. {children}
  56. </div>
  57. );
  58. }
  59. }