UI.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import * as React from 'react';
  2. import { fullWidthClassName, zeroRightClassName } from 'react-remove-scroll-bar/constants';
  3. import { useMergeRefs } from 'use-callback-ref';
  4. import { effectCar } from './medium';
  5. const nothing = () => {
  6. return;
  7. };
  8. /**
  9. * Removes scrollbar from the page and contain the scroll within the Lock
  10. */
  11. const RemoveScroll = React.forwardRef((props, parentRef) => {
  12. const ref = React.useRef(null);
  13. const [callbacks, setCallbacks] = React.useState({
  14. onScrollCapture: nothing,
  15. onWheelCapture: nothing,
  16. onTouchMoveCapture: nothing,
  17. });
  18. const { forwardProps, children, className, removeScrollBar, enabled, shards, sideCar, noIsolation, inert, allowPinchZoom, as: Container = 'div', ...rest } = props;
  19. const SideCar = sideCar;
  20. const containerRef = useMergeRefs([ref, parentRef]);
  21. const containerProps = {
  22. ...rest,
  23. ...callbacks,
  24. };
  25. return (React.createElement(React.Fragment, null,
  26. enabled && (React.createElement(SideCar, { sideCar: effectCar, removeScrollBar: removeScrollBar, shards: shards, noIsolation: noIsolation, inert: inert, setCallbacks: setCallbacks, allowPinchZoom: !!allowPinchZoom, lockRef: ref })),
  27. forwardProps ? (React.cloneElement(React.Children.only(children), {
  28. ...containerProps,
  29. ref: containerRef,
  30. })) : (React.createElement(Container, { ...containerProps, className: className, ref: containerRef }, children))));
  31. });
  32. RemoveScroll.defaultProps = {
  33. enabled: true,
  34. removeScrollBar: true,
  35. inert: false,
  36. };
  37. RemoveScroll.classNames = {
  38. fullWidth: fullWidthClassName,
  39. zeroRight: zeroRightClassName,
  40. };
  41. export { RemoveScroll };