Skip to content

Commit

Permalink
add dom
Browse files Browse the repository at this point in the history
  • Loading branch information
KishiTheMechanic committed Oct 27, 2024
1 parent aaf1871 commit 3cd7247
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 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.2",
"version": "1.0.3",
"description": "Theme Module for Fresh v2 App.",
"runtimes": ["deno", "browser"],
"exports": "./mod.ts",
Expand All @@ -16,5 +16,8 @@
"semiColons": false,
"singleQuote": true
}
},
"compilerOptions": {
"lib": ["dom", "deno.ns"]
}
}
5 changes: 5 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ export const defaultLightModeScript: string = `
*/
export function setTheme(newTheme: 'dark' | 'light'): void {
localStorage.setItem('theme', newTheme)
// If running in a client environment with document access
if (globalThis.document) {
// Apply or remove the 'dark' class on the <html> element
document.documentElement.classList.toggle('dark', newTheme === 'dark')
}
}

0 comments on commit 3cd7247

Please sign in to comment.