import { cn } from "@/lib/utils"; import React from "react"; import { createPortal } from "react-dom"; function Portal({ className, ...props }: React.ComponentProps<"div">) { const [mounted, setMounted] = React.useState(false); React.useEffect(() => { setMounted(true); const originalStyle = window.getComputedStyle(document.body).overflow; const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth; const originalPaddingRight = document.body.style.paddingRight; document.body.style.overflow = "hidden"; if (scrollbarWidth > 0) { document.body.style.paddingRight = `${scrollbarWidth}px`; } return () => { document.body.style.overflow = originalStyle; document.body.style.paddingRight = originalPaddingRight; }; }, []); if (!mounted) { return null; } return createPortal(
, document.body ); } function PortalBackdrop({ className, ...props }: React.ComponentProps<"div">) { return (
); } export { Portal, PortalBackdrop };