|
66 | 66 | </v-app> |
67 | 67 | </template> |
68 | 68 |
|
69 | | -<script> |
70 | | -import { mapGetters, mapState } from 'vuex' |
| 69 | +<script setup> |
| 70 | +import { useTheme } from 'vuetify' |
| 71 | +
|
| 72 | +import { mapGetters, mapState, useStore} from 'vuex' |
71 | 73 |
|
72 | 74 | import { editMode, editPage } from '../EditTracking.js' |
73 | 75 |
|
74 | 76 | import Alerts from '../services/alerts' |
75 | 77 | import UINotification from '../widgets/ui-notification/UINotification.vue' |
76 | 78 |
|
| 79 | +const theme = useTheme() |
| 80 | +const store = useStore() |
| 81 | +
|
| 82 | +function toggleTheme () { |
| 83 | + if (theme.global.name.value === 'nrdbDark') { |
| 84 | + theme.global.name.value = 'nrdbLight' |
| 85 | + store.commit('ui/setDarkMode', false) |
| 86 | + localStorage.setItem('ndrb-theme-dark-mode', JSON.stringify(false)) |
| 87 | + } else { |
| 88 | + theme.global.name.value = 'nrdbDark' |
| 89 | + store.commit('ui/setDarkMode', true) |
| 90 | + localStorage.setItem('ndrb-theme-dark-mode', JSON.stringify(true)) |
| 91 | + } |
| 92 | +} |
| 93 | +
|
| 94 | +</script> |
| 95 | + |
| 96 | +<script> |
77 | 97 | /** |
78 | 98 | * Convert a hex to RGB color |
79 | 99 | * @param {String(hex)} hex |
@@ -126,7 +146,7 @@ export default { |
126 | 146 | } |
127 | 147 | }, |
128 | 148 | computed: { |
129 | | - ...mapState('ui', ['dashboards', 'pages', 'themes', 'pageData', 'widgets']), |
| 149 | + ...mapState('ui', ['dashboards', 'pages', 'themes', 'pageData', 'widgets', 'darkMode']), |
130 | 150 | ...mapGetters('ui', ['siteTemplates', 'pageTemplates']), |
131 | 151 | theme: function () { |
132 | 152 | const page = this.pages[this.$route.meta.id] |
@@ -275,22 +295,38 @@ export default { |
275 | 295 | }) |
276 | 296 | }, |
277 | 297 | updateTheme () { |
278 | | - const colors = this.$vuetify.theme.themes.nrdb.colors // Modify the Vuetify Theming |
| 298 | + const colorsLight = this.$vuetify.theme.themes.nrdbLight.colors // Modify the Vuetify Theming |
| 299 | + const colorsDark = this.$vuetify.theme.themes.nrdbDark.colors // Modify the Vuetify Theming |
279 | 300 | const sizes = this.customThemeDefinitions // Implement some of our own Theming |
280 | 301 | // convert NR Theming to Vuetify Theming |
281 | 302 | if (this.theme) { |
282 | | - colors['navigation-background'] = this.theme.colors.surface |
| 303 | + // light theme |
| 304 | + colorsLight['navigation-background'] = this.theme.colors.light.surface |
| 305 | + // primary bg |
| 306 | + colorsLight.primary = this.theme.colors.light.primary |
| 307 | + // primary font - auto calculated |
| 308 | + colorsLight['on-primary'] = getContrast(this.theme.colors.light.primary) |
| 309 | + // UI Background |
| 310 | + colorsLight.background = this.theme.colors.light.bgPage |
| 311 | + // Group Styling |
| 312 | + colorsLight['group-background'] = this.theme.colors.light.groupBg |
| 313 | + colorsLight['group-outline'] = this.theme.colors.light.groupOutline |
| 314 | + // widget background |
| 315 | + colorsLight.surface = this.theme.colors.light.groupBg |
| 316 | +
|
| 317 | + // dark theme |
| 318 | + colorsDark['navigation-background'] = this.theme.colors.dark.surface |
283 | 319 | // primary bg |
284 | | - colors.primary = this.theme.colors.primary |
| 320 | + colorsDark.primary = this.theme.colors.dark.primary |
285 | 321 | // primary font - auto calculated |
286 | | - colors['on-primary'] = getContrast(this.theme.colors.primary) |
| 322 | + colorsDark['on-primary'] = getContrast(this.theme.colors.dark.primary) |
287 | 323 | // UI Background |
288 | | - colors.background = this.theme.colors.bgPage |
| 324 | + colorsDark.background = this.theme.colors.dark.bgPage |
289 | 325 | // Group Styling |
290 | | - colors['group-background'] = this.theme.colors.groupBg |
291 | | - colors['group-outline'] = this.theme.colors.groupOutline |
| 326 | + colorsDark['group-background'] = this.theme.colors.dark.groupBg |
| 327 | + colorsDark['group-outline'] = this.theme.colors.dark.groupOutline |
292 | 328 | // widget background |
293 | | - colors.surface = this.theme.colors.groupBg |
| 329 | + colorsDark.surface = this.theme.colors.dark.groupBg |
294 | 330 |
|
295 | 331 | // sizes |
296 | 332 | sizes['--page-padding'] = this.theme.sizes.pagePadding |
|
0 commit comments