2021-06-15 03:57:50 -07:00
|
|
|
<template>
|
2022-01-18 11:26:21 -08:00
|
|
|
<div class="btn-group" role="group">
|
|
|
|
<button v-for="(buttonIcon, buttonMode) in modes" type="button"
|
|
|
|
:class="['btn', 'btn-sm', mode === buttonMode ? 'btn-primary' : 'btn-outline-primary']"
|
|
|
|
@click="mode = buttonMode"
|
|
|
|
>
|
|
|
|
<Icon :v="buttonIcon"/>
|
|
|
|
<T>mode.{{ buttonMode }}</T>
|
|
|
|
</button>
|
2021-06-15 03:57:50 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import dark from "../plugins/dark";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
mixins: [dark],
|
|
|
|
data() {
|
|
|
|
return {
|
2022-01-18 11:26:21 -08:00
|
|
|
mode: 'automatic',
|
2021-06-15 03:57:50 -07:00
|
|
|
isDark: false,
|
2022-01-18 11:26:21 -08:00
|
|
|
modes: {
|
|
|
|
light: 'sun',
|
|
|
|
automatic: 'eclipse',
|
|
|
|
dark: 'moon',
|
|
|
|
}
|
2021-06-15 03:57:50 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (!process.client) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-01-18 11:26:21 -08:00
|
|
|
this.mode = this.getMode();
|
2021-06-15 03:57:50 -07:00
|
|
|
this.isDark = this.detectDark();
|
2021-07-24 02:36:59 -07:00
|
|
|
|
2022-01-18 11:26:21 -08:00
|
|
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => this.isDark = this.detectDark());
|
|
|
|
|
|
|
|
this.$eventHub.$on('mode-changed', mode => {
|
|
|
|
if (mode !== this.mode) {
|
|
|
|
this.mode = mode;
|
2021-07-24 02:36:59 -07:00
|
|
|
}
|
|
|
|
})
|
2021-06-15 03:57:50 -07:00
|
|
|
},
|
|
|
|
watch: {
|
2022-01-18 11:26:21 -08:00
|
|
|
mode() {
|
|
|
|
this.$eventHub.$emit('mode-changed', this.mode);
|
|
|
|
this.setMode(this.mode);
|
|
|
|
this.isDark = this.detectDark();
|
|
|
|
},
|
|
|
|
isDark() {
|
|
|
|
this.setIsDark(this.isDark);
|
|
|
|
this.$store.commit('setDarkMode', this.isDark);
|
2021-06-15 03:57:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|