-
-
Notifications
You must be signed in to change notification settings - Fork 391
/
ThemeSettingsCard.vue
97 lines (84 loc) · 2.22 KB
/
ThemeSettingsCard.vue
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<template>
<collapsable-card
title="Theme"
subTitle="Define a primary color, and whether to show in dark mode or not."
cardKey="ThemeSettings"
icon="$cogs">
<v-card-text>
<!-- <pre>{{ $vuetify.theme.themes.dark }}</pre> -->
<!-- <pre>{{ color }}</pre> -->
<v-color-picker
:value="theme.colors.primary"
@update:color="handlePrimaryColorChange"
mode="hexa"
hide-mode-switch
canvas-height="100"
dot-size="25"
>
</v-color-picker>
<v-switch
@click.native.stop
label="Dark Mode"
v-model="theme.darkMode"
@change="handleDarkModeChange"
hide-details
class="mb-5"
></v-switch>
<v-btn
color="secondary"
@click="handleReset"
>
Reset to default
</v-btn>
</v-card-text>
</collapsable-card>
</template>
<script lang="ts">
import { Component, Mixins } from 'vue-property-decorator'
import { debounce } from 'lodash-es'
import UtilsMixin from '@/mixins/utils'
import { ThemeConfig } from '@/store/config/types'
@Component({
components: {}
})
export default class ThemeSettingsCard extends Mixins(UtilsMixin) {
get theme () {
return this.$store.getters['config/getTheme']
}
setTheme (value: ThemeConfig) {
this.$vuetify.theme.dark = value.darkMode
this.$vuetify.theme.currentTheme.primary = value.colors.primary
}
handlePrimaryColorChange = debounce((value: { hex: string }) => {
this.setTheme({
darkMode: this.theme.darkMode,
colors: {
primary: value.hex
}
})
this.$store.dispatch('config/saveGeneric', { key: 'uiSettings.theme.colors.primary', value: value.hex })
}, 500)
handleDarkModeChange (value: boolean) {
this.setTheme({
darkMode: value,
colors: {
primary: this.theme.colors.primary
}
})
this.$store.dispatch('config/saveGeneric', { key: 'uiSettings.theme.darkMode', value })
}
handleReset () {
const theme: ThemeConfig = {
darkMode: true,
colors: {
primary: '#2196F3'
}
}
this.setTheme(theme)
this.$store.dispatch('config/saveGeneric', {
key: 'uiSettings.theme',
value: theme
})
}
}
</script>