significant refactor
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Box, Container, useComputedColorScheme } from "@mantine/core";
|
||||
import { PropsWithChildren, useEffect } from "react";
|
||||
import { Drawer as VaulDrawer } from 'vaul';
|
||||
import { useMantineColorScheme } from '@mantine/core';
|
||||
import styles from './styles.module.css';
|
||||
import { Drawer as VaulDrawer } from "vaul";
|
||||
import { useMantineColorScheme } from "@mantine/core";
|
||||
import styles from "./styles.module.css";
|
||||
|
||||
interface DrawerProps extends PropsWithChildren {
|
||||
title?: string;
|
||||
@@ -10,44 +10,51 @@ interface DrawerProps extends PropsWithChildren {
|
||||
onChange: (next: boolean) => void;
|
||||
}
|
||||
|
||||
const Drawer: React.FC<DrawerProps> = ({ title, children, opened, onChange }) => {
|
||||
const colorScheme = useComputedColorScheme('light');
|
||||
const Drawer: React.FC<DrawerProps> = ({
|
||||
title,
|
||||
children,
|
||||
opened,
|
||||
onChange,
|
||||
}) => {
|
||||
const colorScheme = useComputedColorScheme("light");
|
||||
|
||||
useEffect(() => {
|
||||
const appElement = document.querySelector('.app') as HTMLElement;
|
||||
|
||||
const appElement = document.querySelector(".app") as HTMLElement;
|
||||
|
||||
if (!appElement) return;
|
||||
|
||||
let themeColorMeta = document.querySelector('meta[name="theme-color"]') as HTMLMetaElement;
|
||||
let themeColorMeta = document.querySelector(
|
||||
'meta[name="theme-color"]'
|
||||
) as HTMLMetaElement;
|
||||
if (!themeColorMeta) {
|
||||
themeColorMeta = document.createElement('meta');
|
||||
themeColorMeta.name = 'theme-color';
|
||||
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)'
|
||||
normal: "rgb(255,255,255)",
|
||||
overlay: "rgb(153,153,153)",
|
||||
},
|
||||
dark: {
|
||||
normal: 'rgb(36,36,36)',
|
||||
overlay: 'rgb(22,22,22)'
|
||||
}
|
||||
normal: "rgb(36,36,36)",
|
||||
overlay: "rgb(22,22,22)",
|
||||
},
|
||||
};
|
||||
|
||||
const currentColors = colors[colorScheme] || colors.light;
|
||||
|
||||
|
||||
if (opened) {
|
||||
appElement.classList.add('drawer-scaling');
|
||||
appElement.classList.add("drawer-scaling");
|
||||
themeColorMeta.content = currentColors.overlay;
|
||||
} else {
|
||||
appElement.classList.remove('drawer-scaling');
|
||||
appElement.classList.remove("drawer-scaling");
|
||||
themeColorMeta.content = currentColors.normal;
|
||||
}
|
||||
|
||||
return () => {
|
||||
appElement.classList.remove('drawer-scaling');
|
||||
appElement.classList.remove("drawer-scaling");
|
||||
themeColorMeta.content = currentColors.normal;
|
||||
};
|
||||
}, [opened, colorScheme]);
|
||||
@@ -57,9 +64,17 @@ const Drawer: React.FC<DrawerProps> = ({ title, children, opened, onChange }) =>
|
||||
<VaulDrawer.Portal>
|
||||
<VaulDrawer.Overlay className={styles.drawerOverlay} />
|
||||
<VaulDrawer.Content className={styles.drawerContent}>
|
||||
<Container flex={1} p='md'>
|
||||
<Box mb='sm' bg='var(--mantine-color-gray-4)' w='3rem' h='0.375rem' ml='auto' mr='auto' style={{ borderRadius: '9999px' }} />
|
||||
<Container mah='fit-content' mx='auto' maw='28rem' px={0}>
|
||||
<Container flex={1} p="md">
|
||||
<Box
|
||||
mb="sm"
|
||||
bg="var(--mantine-color-gray-4)"
|
||||
w="3rem"
|
||||
h="0.375rem"
|
||||
ml="auto"
|
||||
mr="auto"
|
||||
style={{ borderRadius: "9999px" }}
|
||||
/>
|
||||
<Container mah="fit-content" mx="auto" maw="28rem" px={0}>
|
||||
<VaulDrawer.Title>{title}</VaulDrawer.Title>
|
||||
{children}
|
||||
</Container>
|
||||
@@ -67,7 +82,7 @@ const Drawer: React.FC<DrawerProps> = ({ title, children, opened, onChange }) =>
|
||||
</VaulDrawer.Content>
|
||||
</VaulDrawer.Portal>
|
||||
</VaulDrawer.Root>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default Drawer;
|
||||
|
||||
Reference in New Issue
Block a user