X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fcomponents%2FDarkMode.vue;h=80491fafae8d2dc9fb6f467146cac0e7db8495a8;hb=7596bc527f5b995bedd6a77ed71b6e1feba1364d;hp=02450d9f900552eff6550a16d0ebcf5b5694190b;hpb=4a1e8717e90d1b0b516da2cbc1d16ff906d7fbdf;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/src/components/DarkMode.vue b/src/components/DarkMode.vue index 02450d9..80491fa 100644 --- a/src/components/DarkMode.vue +++ b/src/components/DarkMode.vue @@ -4,7 +4,11 @@ aria-label="Toggle dark mode" class="navbar-item is-inline-block-mobile" > - + @@ -15,11 +19,13 @@ export default { return { isDark: null, faClasses: null, + titles: null, mode: null, }; }, created: function () { this.faClasses = ["fas fa-adjust", "fas fa-circle", "far fa-circle"]; + this.titles = ["Auto-switch", "Light theme", "Dark theme"]; this.mode = 0; if ("overrideDark" in localStorage) { // Light theme is 1 and Dark theme is 2 @@ -30,33 +36,37 @@ export default { }, methods: { toggleTheme: function () { - this.mode = (this.mode + 1) % 3 - switch(this.mode) { + this.mode = (this.mode + 1) % 3; + switch (this.mode) { // Default behavior case 0: localStorage.removeItem("overrideDark"); - break + break; // Force light theme case 1: localStorage.overrideDark = false; - break + break; // Force dark theme case 2: localStorage.overrideDark = true; - break + break; default: // Should be unreachable - break + break; } this.isDark = this.getIsDark(); this.$emit("updated", this.isDark); }, - getIsDark: function() { - const values = [matchMedia("(prefers-color-scheme: dark)").matches, false, true]; + getIsDark: function () { + const values = [ + matchMedia("(prefers-color-scheme: dark)").matches, + false, + true, + ]; return values[this.mode]; - } + }, }, };