CustomScrollbar.tsx 1.6 KB

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