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.

55 lines
1.3 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. label: PropTypes.string,
  11. };
  12. scrollTop () {
  13. const scrollable = this.node.querySelector('.scrollable');
  14. if (!scrollable) {
  15. return;
  16. }
  17. this._interruptScrollAnimation = scrollTop(scrollable);
  18. }
  19. handleWheel = () => {
  20. if (typeof this._interruptScrollAnimation !== 'function') {
  21. return;
  22. }
  23. this._interruptScrollAnimation();
  24. }
  25. setRef = c => {
  26. this.node = c;
  27. }
  28. componentDidMount () {
  29. this.node.addEventListener('wheel', this.handleWheel, detectPassiveEvents.hasSupport ? { passive: true } : false);
  30. }
  31. componentWillUnmount () {
  32. this.node.removeEventListener('wheel', this.handleWheel);
  33. }
  34. render () {
  35. const { children, extraClasses, name, label } = this.props;
  36. return (
  37. <div role='region' aria-label={label} data-column={name} className={`column ${extraClasses || ''}`} ref={this.setRef}>
  38. {children}
  39. </div>
  40. );
  41. }
  42. }