-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathThemeSwitcher.vue
More file actions
39 lines (37 loc) · 1.01 KB
/
ThemeSwitcher.vue
File metadata and controls
39 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<script>
// Control to switch between light and dark mode
import ToggleButton from '../modulecore/ToggleButton.vue';
import { useColorTheme } from '@/composables/ColorTheme';
import { useTheme } from 'vuetify';
export default {
extends: ToggleButton,
name: 'wgu-themeswitcher',
setup () {
const theme = useTheme();
const { isDarkTheme, isPrimaryDark } = useColorTheme();
return { isDarkTheme, isPrimaryDark, theme };
},
watch: {
isDarkTheme: {
// When dark theme changes via Vuetify
handler: function (value) {
// update toggle state of this tool
if (value !== !!this.show) {
this.show = value;
}
},
immediate: true
},
show: {
// When dark theme changes via this tool
handler: function (value) {
// update Vuetify state
const wantedTheme = value ? 'dark' : 'light';
if (wantedTheme !== this.theme.global.name.value) {
this.theme.change(wantedTheme);
}
}
}
}
};
</script>