Skip to content

Commit

Permalink
refactor(theme): switch theme detection to use class
Browse files Browse the repository at this point in the history
  • Loading branch information
iCrawl committed Jul 18, 2022
1 parent b5d4b2d commit 70dd757
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 11 additions & 0 deletions packages/website/src/root.tsx
Expand Up @@ -24,6 +24,17 @@ export default function App() {
<Links />
</head>
<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 />
<ScrollRestoration />
<Scripts />
Expand Down
4 changes: 1 addition & 3 deletions packages/website/unocss.config.ts
Expand Up @@ -8,9 +8,7 @@ export default defineConfig({
},
},
presets: [
presetUno({
dark: 'media',
}),
presetUno({ dark: 'class' }),
presetWebFonts({
provider: 'google',
fonts: {
Expand Down

1 comment on commit 70dd757

@vercel
Copy link

@vercel vercel bot commented on 70dd757 Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.