Skip to content

Commit 1dc2abf

Browse files
committed
Add dark mode theme to Baseline
1 parent db4718c commit 1dc2abf

1 file changed

Lines changed: 47 additions & 11 deletions

File tree

ui/src/layouts/Baseline.vue

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,34 @@
6666
</v-app>
6767
</template>
6868

69-
<script>
70-
import { mapGetters, mapState } from 'vuex'
69+
<script setup>
70+
import { useTheme } from 'vuetify'
71+
72+
import { mapGetters, mapState, useStore} from 'vuex'
7173
7274
import { editMode, editPage } from '../EditTracking.js'
7375
7476
import Alerts from '../services/alerts'
7577
import UINotification from '../widgets/ui-notification/UINotification.vue'
7678
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>
7797
/**
7898
* Convert a hex to RGB color
7999
* @param {String(hex)} hex
@@ -126,7 +146,7 @@ export default {
126146
}
127147
},
128148
computed: {
129-
...mapState('ui', ['dashboards', 'pages', 'themes', 'pageData', 'widgets']),
149+
...mapState('ui', ['dashboards', 'pages', 'themes', 'pageData', 'widgets', 'darkMode']),
130150
...mapGetters('ui', ['siteTemplates', 'pageTemplates']),
131151
theme: function () {
132152
const page = this.pages[this.$route.meta.id]
@@ -275,22 +295,38 @@ export default {
275295
})
276296
},
277297
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
279300
const sizes = this.customThemeDefinitions // Implement some of our own Theming
280301
// convert NR Theming to Vuetify Theming
281302
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
283319
// primary bg
284-
colors.primary = this.theme.colors.primary
320+
colorsDark.primary = this.theme.colors.dark.primary
285321
// primary font - auto calculated
286-
colors['on-primary'] = getContrast(this.theme.colors.primary)
322+
colorsDark['on-primary'] = getContrast(this.theme.colors.dark.primary)
287323
// UI Background
288-
colors.background = this.theme.colors.bgPage
324+
colorsDark.background = this.theme.colors.dark.bgPage
289325
// 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
292328
// widget background
293-
colors.surface = this.theme.colors.groupBg
329+
colorsDark.surface = this.theme.colors.dark.groupBg
294330
295331
// sizes
296332
sizes['--page-padding'] = this.theme.sizes.pagePadding

0 commit comments

Comments
 (0)