mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
refactor not done
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
interface UsePreventScrollOptions {
|
||||
enabled?: boolean;
|
||||
element?: HTMLElement;
|
||||
}
|
||||
|
||||
export function usePreventScroll({ enabled = true, element }: UsePreventScrollOptions = {}) {
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
|
||||
const targetElement = element || document.body;
|
||||
const originalOverflow = targetElement.style.overflow;
|
||||
const originalPaddingRight = targetElement.style.paddingRight;
|
||||
|
||||
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
||||
|
||||
targetElement.style.overflow = 'hidden';
|
||||
if (scrollbarWidth > 0) {
|
||||
targetElement.style.paddingRight = `${scrollbarWidth}px`;
|
||||
}
|
||||
|
||||
return () => {
|
||||
targetElement.style.overflow = originalOverflow;
|
||||
targetElement.style.paddingRight = originalPaddingRight;
|
||||
};
|
||||
}, [enabled, element]);
|
||||
}
|
||||
Reference in New Issue
Block a user