UNPKG

@chief-editor/ui

Version:

UI Component for chief editor

1 lines 1.14 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var dom_1=require("@co-hooks/dom"),react_1=require("react"),lockCount=0,locked=!1,documentBodyStyle={},scrollbarWidth=dom_1.getScrollbarWidth();function useLockScreen(){return{lockScreen:react_1.useCallback((function(){if(lockCount++,!locked&&(locked=!0,dom_1.isClient())){documentBodyStyle={overflow:document.body.style.getPropertyValue("overflow"),position:document.body.style.getPropertyValue("position"),width:document.body.style.getPropertyValue("width")};var e={overflow:"hidden"};if(document.body.clientWidth<window.innerWidth&&scrollbarWidth){["fixed","absolute"].indexOf(documentBodyStyle.position||"")>=0?e.position=documentBodyStyle.position:e.position="relative";var o=documentBodyStyle.width?getComputedStyle(document.body).getPropertyValue("width"):"100%";e.width="calc("+o+" - "+scrollbarWidth+"px)"}Object.assign(document.body.style,e)}}),[]),unlockScreen:react_1.useCallback((function(){locked&&lockCount--,!lockCount&&locked&&(locked=!1,dom_1.isClient()&&Object.assign(document.body.style,documentBodyStyle))}),[])}}exports.useLockScreen=useLockScreen;