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.

54 lines
1.2 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import detectPassiveEvents from 'detect-passive-events';
  4. import { scrollTop } from 'flavours/glitch/util/scroll';
  5. export default class Column extends React.PureComponent {
  6. static propTypes = {
  7. children: PropTypes.node,
  8. extraClasses: PropTypes.string,
  9. name: PropTypes.string,
  10. };
  11. scrollTop () {
  12. const scrollable = this.node.querySelector('.scrollable');
  13. if (!scrollable) {
  14. return;
  15. }
  16. this._interruptScrollAnimation = scrollTop(scrollable);
  17. }
  18. handleWheel = () => {
  19. if (typeof this._interruptScrollAnimation !== 'function') {
  20. return;
  21. }
  22. this._interruptScrollAnimation();
  23. }
  24. setRef = c => {
  25. this.node = c;
  26. }
  27. componentDidMount () {
  28. this.node.addEventListener('wheel', this.handleWheel, detectPassiveEvents.hasSupport ? { passive: true } : false);
  29. }
  30. componentWillUnmount () {
  31. this.node.removeEventListener('wheel', this.handleWheel);
  32. }
  33. render () {
  34. const { children, extraClasses, name } = this.props;
  35. return (
  36. <div role='region' data-column={name} className={`column ${extraClasses || ''}`} ref={this.setRef}>
  37. {children}
  38. </div>
  39. );
  40. }
  41. }