CustomScrollbar.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React, { PureComponent } from 'react';
  2. import Scrollbars from 'react-custom-scrollbars';
  3. interface Props {
  4. customClassName?: string;
  5. autoHide?: boolean;
  6. autoHideTimeout?: number;
  7. autoHideDuration?: number;
  8. hideTracksWhenNotNeeded?: boolean;
  9. }
  10. /**
  11. * Wraps component into <Scrollbars> component from `react-custom-scrollbars`
  12. */
  13. class CustomScrollbar extends PureComponent<Props> {
  14. static defaultProps: Partial<Props> = {
  15. customClassName: 'custom-scrollbars',
  16. autoHide: true,
  17. autoHideTimeout: 200,
  18. autoHideDuration: 200,
  19. hideTracksWhenNotNeeded: false,
  20. };
  21. render() {
  22. const { customClassName, children, ...scrollProps } = this.props;
  23. return (
  24. <Scrollbars
  25. className={customClassName}
  26. autoHeight={true}
  27. // These autoHeightMin & autoHeightMax options affect firefox and chrome differently.
  28. // Before these where set to inhert but that caused problems with cut of legends in firefox
  29. autoHeightMin={'0'}
  30. autoHeightMax={'100%'}
  31. renderTrackHorizontal={props => <div {...props} className="track-horizontal" />}
  32. renderTrackVertical={props => <div {...props} className="track-vertical" />}
  33. renderThumbHorizontal={props => <div {...props} className="thumb-horizontal" />}
  34. renderThumbVertical={props => <div {...props} className="thumb-vertical" />}
  35. renderView={props => <div {...props} className="view" />}
  36. {...scrollProps}
  37. >
  38. {children}
  39. </Scrollbars>
  40. );
  41. }
  42. }
  43. export default CustomScrollbar;