闭社主体 forked from https://github.com/tootsuite/mastodon
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.

72 lines
1.7 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. import { isMobile } from '../../../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. };
  15. handleHeaderClick = () => {
  16. const scrollable = this.node.querySelector('.scrollable');
  17. if (!scrollable) {
  18. return;
  19. }
  20. this._interruptScrollAnimation = scrollTop(scrollable);
  21. }
  22. scrollTop () {
  23. const scrollable = this.node.querySelector('.scrollable');
  24. if (!scrollable) {
  25. return;
  26. }
  27. this._interruptScrollAnimation = scrollTop(scrollable);
  28. }
  29. handleScroll = debounce(() => {
  30. if (typeof this._interruptScrollAnimation !== 'undefined') {
  31. this._interruptScrollAnimation();
  32. }
  33. }, 200)
  34. setRef = (c) => {
  35. this.node = c;
  36. }
  37. render () {
  38. const { heading, icon, children, active, hideHeadingOnMobile } = this.props;
  39. const showHeading = heading && (!hideHeadingOnMobile || (hideHeadingOnMobile && !isMobile(window.innerWidth)));
  40. const columnHeaderId = showHeading && heading.replace(/ /g, '-');
  41. const header = showHeading && (
  42. <ColumnHeader icon={icon} active={active} type={heading} onClick={this.handleHeaderClick} columnHeaderId={columnHeaderId} />
  43. );
  44. return (
  45. <div
  46. ref={this.setRef}
  47. role='region'
  48. aria-labelledby={columnHeaderId}
  49. className='column'
  50. onScroll={this.handleScroll}
  51. >
  52. {header}
  53. {children}
  54. </div>
  55. );
  56. }
  57. }