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