UI.js 2.1 KB

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