Toggle dark mode when `prefers-color-scheme` changes

pull/649/head
Gabe Cook 2023-05-10 02:38:51 -05:00 committed by Bastien Wirtz
parent f0f9f0a017
commit 6cfa1643b4
1 changed files with 8 additions and 0 deletions

View File

@ -47,6 +47,7 @@ export default {
}
this.isDark = this.getIsDark();
this.$emit("updated", this.isDark);
this.watchIsDark();
},
methods: {
toggleTheme: function () {
@ -81,6 +82,13 @@ export default {
];
return values[this.mode];
},
watchIsDark: function () {
matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
this.isDark = this.getIsDark();
this.$emit("updated", this.isDark);
});
},
},
};
</script>