3 v-on:click="toggleTheme()"
4 aria-label="Toggle dark mode"
5 class="navbar-item is-inline-block-mobile"
7 <i :class="`${faClasses[mode]}`" class="fa-fw" :title="`${titles[mode]}`"></i>
22 created: function () {
23 this.faClasses = ["fas fa-adjust", "fas fa-circle", "far fa-circle"];
24 this.titles = ["Auto-switch", "Light theme", "Dark theme"]
26 if ("overrideDark" in localStorage) {
27 // Light theme is 1 and Dark theme is 2
28 this.mode = JSON.parse(localStorage.overrideDark) ? 2 : 1;
30 this.isDark = this.getIsDark();
31 this.$emit("updated", this.isDark);
34 toggleTheme: function () {
35 this.mode = (this.mode + 1) % 3
39 localStorage.removeItem("overrideDark");
43 localStorage.overrideDark = false;
47 localStorage.overrideDark = true;
50 // Should be unreachable
54 this.isDark = this.getIsDark();
55 this.$emit("updated", this.isDark);
58 getIsDark: function() {
59 const values = [matchMedia("(prefers-color-scheme: dark)").matches, false, true];
60 return values[this.mode];