52 lines
2.0 KiB
JavaScript
52 lines
2.0 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
Object.defineProperty(exports, "useDisableBodyScroll", {
|
||
|
enumerable: true,
|
||
|
get: function() {
|
||
|
return useDisableBodyScroll;
|
||
|
}
|
||
|
});
|
||
|
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
|
||
|
const _react = require("react");
|
||
|
const _useDisableBodyScrollstyles = require("./useDisableBodyScroll.styles");
|
||
|
function useDisableBodyScroll() {
|
||
|
const htmlNoScrollStyles = (0, _useDisableBodyScrollstyles.useHTMLNoScrollStyles)();
|
||
|
const bodyNoScrollStyles = (0, _useDisableBodyScrollstyles.useBodyNoScrollStyles)();
|
||
|
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
|
||
|
const disableBodyScroll = (0, _react.useCallback)(()=>{
|
||
|
var _targetDocument_defaultView;
|
||
|
if (!targetDocument) {
|
||
|
return;
|
||
|
}
|
||
|
var _targetDocument_defaultView_innerHeight;
|
||
|
const isHorizontalScrollbarVisible = targetDocument.body.clientHeight > ((_targetDocument_defaultView_innerHeight = (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.innerHeight) !== null && _targetDocument_defaultView_innerHeight !== void 0 ? _targetDocument_defaultView_innerHeight : 0);
|
||
|
if (!isHorizontalScrollbarVisible) {
|
||
|
return;
|
||
|
}
|
||
|
targetDocument.documentElement.classList.add(htmlNoScrollStyles);
|
||
|
targetDocument.body.classList.add(bodyNoScrollStyles);
|
||
|
return;
|
||
|
}, [
|
||
|
targetDocument,
|
||
|
htmlNoScrollStyles,
|
||
|
bodyNoScrollStyles
|
||
|
]);
|
||
|
const enableBodyScroll = (0, _react.useCallback)(()=>{
|
||
|
if (!targetDocument) {
|
||
|
return;
|
||
|
}
|
||
|
targetDocument.documentElement.classList.remove(htmlNoScrollStyles);
|
||
|
targetDocument.body.classList.remove(bodyNoScrollStyles);
|
||
|
}, [
|
||
|
targetDocument,
|
||
|
htmlNoScrollStyles,
|
||
|
bodyNoScrollStyles
|
||
|
]);
|
||
|
return {
|
||
|
disableBodyScroll,
|
||
|
enableBodyScroll
|
||
|
};
|
||
|
}
|