This commit is contained in:
Lea 2024-01-16 20:13:49 +01:00
parent 86066e1d3e
commit 8eac71764a
Signed by: Lea
GPG key ID: 1BAFFE8347019C42

View file

@ -2,11 +2,34 @@
import '@radix-ui/themes/styles.css';
import { Theme } from "@radix-ui/themes";
import { useEffect, useState } from 'react';
export default function ThemeWrapper({
children,
}: {
children: React.ReactNode
}) {
return <Theme>{children}</Theme>;
}
const [dark, setDark] = useState(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches);
// Automatically respond to theme changes
useEffect(() => {
const onThemeChange = (event: MediaQueryListEvent) => {
setDark(event.matches);
};
let match = window.matchMedia('(prefers-color-scheme: dark)');
match.addEventListener('change', onThemeChange);
return () => match.removeEventListener('change', onThemeChange);
});
return <Theme
accentColor='ruby'
grayColor='mauve'
radius='large'
scaling='95%'
appearance={dark ? 'dark' : 'light'}
>
{children}
</Theme>;
};