UNPKG

tdesign-react

Version:
59 lines (55 loc) 2.63 kB
/** * tdesign v1.15.1 * (c) 2025 tdesign * @license MIT */ import { useRef, useCallback } from 'react'; import { a as getScrollbarWidth } from '../../_chunks/dep-a3bde62f.js'; import useIsomorphicLayoutEffect from '../../hooks/useLayoutEffect.js'; import '../../_chunks/dep-1630b9b4.js'; import '../../_chunks/dep-87d110df.js'; import '../../_chunks/dep-026a4c6b.js'; import '../../_chunks/dep-6b660ef0.js'; import '../../_chunks/dep-48805ab8.js'; import '../../_chunks/dep-cb0a3966.js'; import '../../_chunks/dep-eca3a3de.js'; import 'lodash-es'; import '../../_chunks/dep-3a09424a.js'; var key = 1; function useDialogLockStyle(_ref) { var preventScrollThrough = _ref.preventScrollThrough, visible = _ref.visible, mode = _ref.mode, showInAttachedElement = _ref.showInAttachedElement; var lockStyleRef = useRef(null); var timerRef = useRef(null); var clearStyleFunc = 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); }, []); useIsomorphicLayoutEffect(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() : 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]); useIsomorphicLayoutEffect(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]); } export { useDialogLockStyle as default }; //# sourceMappingURL=useLockStyle.js.map