CustomScrollbar.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. autoHeightMin={'inherit'}
  28. autoHeightMax={'inherit'}
  29. renderTrackHorizontal={props => <div {...props} className="track-horizontal" />}
  30. renderTrackVertical={props => <div {...props} className="track-vertical" />}
  31. renderThumbHorizontal={props => <div {...props} className="thumb-horizontal" />}
  32. renderThumbVertical={props => <div {...props} className="thumb-vertical" />}
  33. renderView={props => <div {...props} className="view" />}
  34. {...scrollProps}
  35. >
  36. {children}
  37. </Scrollbars>
  38. );
  39. }
  40. }
  41. export default CustomScrollbar;