The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

53 regels
1.0 KiB

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