Skip to content

Commit

Permalink
default dark
Browse files Browse the repository at this point in the history
  • Loading branch information
KishiTheMechanic committed Oct 27, 2024
1 parent 352c31a commit aaf1871
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elsoul/fresh-theme",
"version": "1.0.1",
"version": "1.0.2",
"description": "Theme Module for Fresh v2 App.",
"runtimes": ["deno", "browser"],
"exports": "./mod.ts",
Expand Down
16 changes: 12 additions & 4 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
*/
export const defaultDarkModeScript: string = `
function applyDefaultTheme(change) {
if (change === 'auto') delete localStorage.theme;
else if (change === 'on') localStorage.theme = 'dark';
else if (change === 'off') localStorage.theme = 'light';
if (!("theme" in localStorage)) {
localStorage.theme = 'dark'; // Ensure dark mode is set as default
}
if (change === 'auto') {
delete localStorage.theme;
} else if (change === 'on') {
localStorage.theme = 'dark';
} else if (change === 'off') {
localStorage.theme = 'light';
}
window.isDark = localStorage.theme === "dark" ||
(!("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches);
document.documentElement.classList[window.isDark ? 'add' : 'remove']("dark");
}
applyDefaultTheme();
Expand Down

0 comments on commit aaf1871

Please sign in to comment.