refactor(theme): switch theme detection to use class

This commit is contained in:
iCrawl
2022-07-18 19:53:07 +02:00
parent b5d4b2d78b
commit 70dd757ec3
2 changed files with 12 additions and 3 deletions

View File

@@ -24,6 +24,17 @@ export default function App() {
<Links /> <Links />
</head> </head>
<body> <body>
<script
dangerouslySetInnerHTML={{
__html: `(() => {
const prefersDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
const persistedColorPreference = localStorage.getItem('theme') || 'auto';
if (persistedColorPreference === 'dark' || (prefersDarkMode && persistedColorPreference !== 'light')) {
document.documentElement.classList.toggle('dark', true);
}
})();`,
}}
/>
<Outlet /> <Outlet />
<ScrollRestoration /> <ScrollRestoration />
<Scripts /> <Scripts />

View File

@@ -8,9 +8,7 @@ export default defineConfig({
}, },
}, },
presets: [ presets: [
presetUno({ presetUno({ dark: 'class' }),
dark: 'media',
}),
presetWebFonts({ presetWebFonts({
provider: 'google', provider: 'google',
fonts: { fonts: {