generated from iits-consulting/helm-chart-repo-gh-pages-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from iits-consulting/admin-dashboard-dark-mode
iits-admin-dashboard: improvements
- Loading branch information
Showing
5 changed files
with
221 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const Themes = Object.freeze({ | ||
light: "light", | ||
dark: "dark" | ||
}); | ||
const data_key = 'iits-theme'; | ||
|
||
//determines if the user has a set theme | ||
function detectColorScheme() { | ||
let theme = Themes.light; //default to light | ||
|
||
//local storage is used to override OS theme settings | ||
if (localStorage.getItem(data_key)) { | ||
if (localStorage.getItem(data_key) === Themes.dark) { | ||
theme = Themes.dark; | ||
} | ||
} else if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||
//OS theme setting detected as dark | ||
theme = Themes.dark; | ||
} | ||
|
||
localStorage.setItem(data_key, theme); | ||
document.documentElement.setAttribute("data-theme", theme); | ||
return theme | ||
} | ||
|
||
//function that changes the theme, and sets a localStorage variable to track the theme between page loads | ||
function switchTheme(e) { | ||
let toggleSwitch = document.querySelector('input'); | ||
let newTheme = e.target.checked ? Themes.dark : Themes.light; | ||
localStorage.setItem(data_key, newTheme); | ||
document.documentElement.setAttribute('data-theme', newTheme); | ||
toggleSwitch.checked = e.target.checked; | ||
} | ||
|
||
const initialTheme = detectColorScheme(); | ||
|
||
function init() { | ||
//identify the toggle switch HTML element | ||
const toggleSwitch = document.querySelector('input'); | ||
|
||
//listener for changing themes | ||
toggleSwitch.addEventListener('change', switchTheme, false); | ||
|
||
//pre-check the dark-theme checkbox if dark-theme is set | ||
if (initialTheme === Themes.dark) { | ||
toggleSwitch.checked = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters