Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
if (theme !== 'light' && theme !== 'dark') {
theme = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
}
document.documentElement.style.colorScheme = theme;
document.documentElement.dataset.theme = theme;
})();
</script>
%sveltekit.head%
Expand Down
9 changes: 5 additions & 4 deletions src/lib/theme.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ const createTheme = () => {

/** Adopts whatever the bootstrap script in app.html resolved before paint. */
hydrate() {
current = document.documentElement.style.colorScheme === 'light' ? 'light' : 'dark';
current = document.documentElement.dataset.theme === 'light' ? 'light' : 'dark';
},

toggle() {
current = current === 'dark' ? 'light' : 'dark';

// Every colour in the stylesheet is a light-dark() pair, so setting the
// scheme on :root is the whole theme switch.
document.documentElement.style.colorScheme = current;
// Every colour in the stylesheet is a light-dark() pair resolved against
// the color-scheme layout.css binds to this attribute, so flipping it is
// the whole theme switch.
document.documentElement.dataset.theme = current;

try {
localStorage.setItem(THEME_KEY, current);
Expand Down
8 changes: 8 additions & 0 deletions src/routes/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@
--sdp-line-height: 24px;
}

:root[data-theme='light'] {
color-scheme: light;
}

:root[data-theme='dark'] {
color-scheme: dark;
}

body {
background-color: var(--color-background);
color: var(--color-text);
Expand Down
Loading