Skip to content

Commit

Permalink
fix: theme body class (#50)
Browse files Browse the repository at this point in the history
fix: sync theme class to body
  • Loading branch information
jrasm91 authored Dec 23, 2024
1 parent 962fa9e commit d9be624
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@
--immich-gray: 33 33 33;
}
}

body.dark {
color-scheme: dark;
}

body:not(.dark) {
color-scheme: light;
}
2 changes: 1 addition & 1 deletion src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<body data-sveltekit-preload-data="hover" class="dark bg-light text-dark">
<div>%sveltekit.body%</div>
</body>
</html>
13 changes: 13 additions & 0 deletions src/lib/services/theme.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import { Theme } from '$docs/constants.js';

export const theme = $state<{ value: Theme }>({ value: Theme.Dark });

export const syncToDom = () => {
switch (theme.value) {
case Theme.Dark: {
document.body.classList.add('dark');
break;
}

default: {
document.body.classList.remove('dark');
}
}
};
8 changes: 6 additions & 2 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Navbar from '$docs/components/Navbar.svelte';
import { componentGroups, Theme } from '$docs/constants.js';
import { asComponentHref } from '$docs/utilities.js';
import { theme } from '$lib/services/theme.svelte.js';
import { syncToDom, theme } from '$lib/services/theme.svelte.js';
import {
AppShell,
AppShellHeader,
Expand All @@ -22,9 +22,13 @@
const themeIcon = $derived(theme.value === Theme.Light ? mdiWeatherSunny : mdiWeatherNight);
const isActive = (path: string) => path === page.url.pathname;
$effect(() => {
syncToDom();
});
</script>

<AppShell class="{theme.value} bg-light text-dark">
<AppShell>
<AppShellHeader>
<Navbar theme={theme.value}>
<IconButton
Expand Down

0 comments on commit d9be624

Please sign in to comment.