UNPKG

tdesign-react

Version:
64 lines (58 loc) 2.81 kB
/** * tdesign v1.15.1 * (c) 2025 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var React = require('react'); var getScrollbarWidth = require('../../_chunks/dep-b73b8db7.js'); var hooks_useLayoutEffect = require('../../hooks/useLayoutEffect.js'); require('../../_chunks/dep-002fcc1e.js'); require('../../_chunks/dep-e4e1901e.js'); require('../../_chunks/dep-00b49251.js'); require('../../_chunks/dep-2ffa3ff1.js'); require('../../_chunks/dep-25585736.js'); require('../../_chunks/dep-667ac7af.js'); require('../../_chunks/dep-62e73936.js'); require('../../_chunks/dep-381fa848.js'); require('../../_chunks/dep-4ed9eda4.js'); require('../../_chunks/dep-64577888.js'); var key = 1; function useDialogLockStyle(_ref) { var preventScrollThrough = _ref.preventScrollThrough, visible = _ref.visible, mode = _ref.mode, showInAttachedElement = _ref.showInAttachedElement; var lockStyleRef = React.useRef(null); var timerRef = React.useRef(null); var clearStyleFunc = React.useCallback(function () { clearTimeout(timerRef.current); timerRef.current = setTimeout(function () { var _lockStyleRef$current, _lockStyleRef$current2; (_lockStyleRef$current = lockStyleRef.current) === null || _lockStyleRef$current === void 0 || (_lockStyleRef$current = _lockStyleRef$current.parentNode) === null || _lockStyleRef$current === void 0 || (_lockStyleRef$current2 = _lockStyleRef$current.removeChild) === null || _lockStyleRef$current2 === void 0 || _lockStyleRef$current2.call(_lockStyleRef$current, lockStyleRef.current); }, 150); }, []); hooks_useLayoutEffect["default"](function () { if (typeof document === "undefined" || !visible) return; if (!lockStyleRef.current) { lockStyleRef.current = document.createElement("style"); } var hasScrollBar = document.documentElement.scrollHeight > document.documentElement.clientHeight; var scrollbarWidth = hasScrollBar ? getScrollbarWidth.getScrollbarWidth() : 0; lockStyleRef.current.dataset.id = "td_dialog_".concat(+new Date(), "_").concat(key += 1); lockStyleRef.current.innerHTML = "\n html body {\n overflow-y: hidden;\n width: calc(100% - ".concat(scrollbarWidth, "px);\n }\n "); return clearStyleFunc; }, [visible, clearStyleFunc]); hooks_useLayoutEffect["default"](function () { if (typeof document === "undefined") return; if (mode !== "modal" || !preventScrollThrough || showInAttachedElement) return; if (visible) { document.head.appendChild(lockStyleRef.current); } else { clearStyleFunc(); } }, [preventScrollThrough, visible, mode, showInAttachedElement, clearStyleFunc]); } exports["default"] = useDialogLockStyle; //# sourceMappingURL=useLockStyle.js.map