style upgrades
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
import {
|
||||
Box,
|
||||
Container,
|
||||
Title,
|
||||
useComputedColorScheme,
|
||||
} from "@mantine/core";
|
||||
import { Box, Container, Title, useComputedColorScheme } from "@mantine/core";
|
||||
import { PropsWithChildren, useEffect, useRef } from "react";
|
||||
import { Drawer as VaulDrawer } from "vaul";
|
||||
import { CHROME_COLORS, setThemeColorMeta } from "@/lib/mantine/theme-colors";
|
||||
import styles from "./styles.module.css";
|
||||
|
||||
interface DrawerProps extends PropsWithChildren {
|
||||
title?: string;
|
||||
opened: boolean;
|
||||
onChange: (next: boolean) => void;
|
||||
onClose?: () => void;
|
||||
onExited?: () => void;
|
||||
}
|
||||
|
||||
const Drawer: React.FC<DrawerProps> = ({
|
||||
@@ -19,55 +17,25 @@ const Drawer: React.FC<DrawerProps> = ({
|
||||
children,
|
||||
opened,
|
||||
onChange,
|
||||
onExited,
|
||||
}) => {
|
||||
const colorScheme = useComputedColorScheme("light");
|
||||
const contentRef = useRef<HTMLDivElement>(null);
|
||||
const openedRef = useRef(opened);
|
||||
|
||||
useEffect(() => {
|
||||
openedRef.current = opened;
|
||||
}, [opened]);
|
||||
if (!opened) return;
|
||||
|
||||
useEffect(() => {
|
||||
const appElement = document.querySelector(".app") as HTMLElement;
|
||||
const appElement = document.querySelector<HTMLElement>(".app");
|
||||
const colors = CHROME_COLORS[colorScheme];
|
||||
|
||||
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;
|
||||
}
|
||||
appElement?.classList.add("drawer-scaling");
|
||||
setThemeColorMeta(colors.dimmed);
|
||||
|
||||
return () => {
|
||||
appElement.classList.remove("drawer-scaling");
|
||||
themeColorMeta.content = currentColors.normal;
|
||||
appElement?.classList.remove("drawer-scaling");
|
||||
setThemeColorMeta(colors.base);
|
||||
};
|
||||
}, [opened]);
|
||||
}, [opened, colorScheme]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!opened || !contentRef.current) return;
|
||||
@@ -109,6 +77,9 @@ const Drawer: React.FC<DrawerProps> = ({
|
||||
repositionInputs={false}
|
||||
open={opened}
|
||||
onOpenChange={onChange}
|
||||
onAnimationEnd={(open) => {
|
||||
if (!open) onExited?.();
|
||||
}}
|
||||
>
|
||||
<VaulDrawer.Portal>
|
||||
<VaulDrawer.Overlay className={styles.drawerOverlay} />
|
||||
|
||||
Reference in New Issue
Block a user