Initial commit
This commit is contained in:
commit
bcca176137
88 files changed
+8725
No files matched your search
@@ -0,0 +1,25 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
|
||||
type Options = {
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export function useToggleBodyOverflow(locked: boolean, options: Options = {}) {
|
||||
const { className = "has-menu-open" } = options;
|
||||
|
||||
useEffect(() => {
|
||||
const root = document.documentElement;
|
||||
|
||||
root.classList.toggle(className, locked);
|
||||
|
||||
const prevOverflow = document.body.style.overflow;
|
||||
document.body.style.overflow = locked ? "hidden" : "";
|
||||
|
||||
return () => {
|
||||
root.classList.remove(className);
|
||||
document.body.style.overflow = prevOverflow;
|
||||
};
|
||||
}, [locked, className]);
|
||||
}
|
||||
Reference in new issue
Block a user