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
5 changes: 3 additions & 2 deletions apps/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
try {
var t = localStorage.getItem("corbits-theme:last");
var r = document.documentElement;
if (t === "dark" || t === "canvas") r.setAttribute("data-theme", t);
if (t === "dark") r.classList.add("dark");
if (t !== "dark" && t !== "canvas") t = "light";
r.setAttribute("data-theme", t);
r.classList.add(t === "dark" ? "dark" : "light");
r.style.colorScheme = t === "dark" ? "dark" : "light";
} catch (e) {}
</script>
Expand Down
9 changes: 5 additions & 4 deletions apps/web/src/theme-store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// The theme lives outside React: `data-theme` on <html> is the one switch,
// and this store is its only writer. Light is the absence of the attribute.
// and this store is its only writer. Light is explicit too: react-ui's
// `prefers-color-scheme: dark` block only skips roots carrying `.light`.

import { reportError } from "@corbits/error-sink";
import { useSyncExternalStore } from "react";
Expand Down Expand Up @@ -31,10 +32,10 @@ function readStored(key: string): Theme {

function apply(theme: Theme) {
const root = document.documentElement;
if (theme === "light") root.removeAttribute("data-theme");
else root.setAttribute("data-theme", theme);
// react-ui's `dark:` variant keys off the class.
root.setAttribute("data-theme", theme);
// react-ui's `dark:` variant keys off `.dark`; its OS-dark block excludes `.light`.
root.classList.toggle("dark", theme === "dark");
root.classList.toggle("light", theme !== "dark");
root.style.colorScheme = theme === "dark" ? "dark" : "light";
}

Expand Down
Loading