This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2021-06-15 03:57:50 -07:00
|
|
|
<template>
|
|
|
|
<div class="py-2 px-3">
|
|
|
|
<div class="form-check form-switch text-dark">
|
|
|
|
<label>
|
|
|
|
<input class="form-check-input" type="checkbox" v-model="isDark">
|
|
|
|
<Icon :v="isDark ? 'moon' : 'sun'"/>
|
2021-06-15 08:24:25 -07:00
|
|
|
{{ $t('mode.' + (isDark ? 'dark' : 'light')) }}
|
2021-06-15 03:57:50 -07:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import dark from "../plugins/dark";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
mixins: [dark],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isDark: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (!process.client) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isDark = this.detectDark();
|
|
|
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => this.isDark = e.matches);
|
2021-07-24 02:36:59 -07:00
|
|
|
|
|
|
|
this.$eventHub.$on('mode-changed', dark => {
|
|
|
|
if (dark !== this.isDark) {
|
|
|
|
this.isDark = dark;
|
|
|
|
}
|
|
|
|
})
|
2021-06-15 03:57:50 -07:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
isDark(dark) {
|
2021-07-24 02:36:59 -07:00
|
|
|
this.$eventHub.$emit('mode-changed', dark);
|
2021-06-15 03:57:50 -07:00
|
|
|
this.setMode(dark);
|
2021-10-26 11:13:42 -07:00
|
|
|
this.$store.commit('setDarkMode', dark);
|
2021-06-15 03:57:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|