import { Box, Container, Flex, Loader, useComputedColorScheme } from "@mantine/core"; import { PropsWithChildren, Suspense, useEffect, useRef } from "react"; import { Drawer as VaulDrawer } from "vaul"; import styles from "./styles.module.css"; interface DrawerProps extends PropsWithChildren { title?: string; opened: boolean; onChange: (next: boolean) => void; } const Drawer: React.FC = ({ title, children, opened, onChange, }) => { const colorScheme = useComputedColorScheme("light"); const contentRef = useRef(null); useEffect(() => { const appElement = document.querySelector(".app") as HTMLElement; if (!appElement) return; let themeColorMeta = document.querySelector( 'meta[name="theme-color"]' ) as HTMLMetaElement; if (!themeColorMeta) { themeColorMeta = document.createElement("meta"); themeColorMeta.name = "theme-color"; document.head.appendChild(themeColorMeta); } const colors = { light: { normal: "rgb(255,255,255)", overlay: "rgb(153,153,153)", }, dark: { normal: "rgb(36,36,36)", overlay: "rgb(22,22,22)", }, }; const currentColors = colors[colorScheme] || colors.light; if (opened) { appElement.classList.add("drawer-scaling"); themeColorMeta.content = currentColors.overlay; } else { appElement.classList.remove("drawer-scaling"); themeColorMeta.content = currentColors.normal; } return () => { appElement.classList.remove("drawer-scaling"); themeColorMeta.content = currentColors.normal; }; }, [opened, colorScheme]); useEffect(() => { if (!opened || !contentRef.current) return; const resizeObserver = new ResizeObserver(() => { if (contentRef.current) { const drawerContent = contentRef.current.closest('[data-vaul-drawer-wrapper]'); if (drawerContent) { (drawerContent as HTMLElement).style.height = 'auto'; (drawerContent as HTMLElement).offsetHeight; } } }); resizeObserver.observe(contentRef.current); return () => { resizeObserver.disconnect(); }; }, [opened, children]); return ( {title} }> {children} ); }; export default Drawer;