From 0c1cf0b756b748e23204b75d92c6c11dd69642ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Thu, 28 Mar 2024 12:51:28 +0100 Subject: [PATCH] =?UTF-8?q?Implement=20Vuetify=20themes=20=E2=80=93=20firs?= =?UTF-8?q?t=20tryout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/renderer/plugins/vuetify.ts | 82 +++++++++++++++++++++++- frontend/src/components/menu/TopMenu.vue | 16 ++++- frontend/src/locales/de.json | 6 +- frontend/src/locales/en.json | 7 +- 4 files changed, 107 insertions(+), 4 deletions(-) diff --git a/frontend/renderer/plugins/vuetify.ts b/frontend/renderer/plugins/vuetify.ts index b983d5e55..9fc6dc1b9 100644 --- a/frontend/renderer/plugins/vuetify.ts +++ b/frontend/renderer/plugins/vuetify.ts @@ -3,9 +3,81 @@ import '@mdi/font/css/materialdesignicons.css' // eslint-disable-next-line import/no-unassigned-import import 'vuetify/styles' import { I18n, useI18n } from 'vue-i18n' -import { createVuetify } from 'vuetify' +import { createVuetify, ThemeDefinition } from 'vuetify' import { createVueI18nAdapter } from 'vuetify/locale/adapters/vue-i18n' +const ocelotStandardLightTheme: ThemeDefinition = { + dark: false, + colors: { + background: 'rgb(255, 255, 255)', + surface: 'rgb(255, 255, 255)', + // primary: rgbToHex(23, 181, 63, '#'), + primary: 'rgb(23, 181, 63)', + // 'primary-darken-1': rgbToHex(25, 122, 49, '#'), + 'primary-darken-1': 'rgb(25, 122, 49)', + secondary: 'rgb(0, 142, 230)', + // 'secondary-darken-1': '#018786', + error: 'rgb(219, 57, 36)', + // info: '#2196F3', + success: 'rgb(23, 181, 63)', + warning: 'rgb(230, 121, 25)', + }, + variables: { + 'border-color': '#000000', + 'border-opacity': 0.12, + 'high-emphasis-opacity': 0.87, + 'medium-emphasis-opacity': 0.6, + 'disabled-opacity': 0.38, + 'idle-opacity': 0.04, + 'hover-opacity': 0.04, + 'focus-opacity': 0.12, + 'selected-opacity': 0.08, + 'activated-opacity': 0.12, + 'pressed-opacity': 0.12, + 'dragged-opacity': 0.08, + 'theme-kbd': '#0000FF', + 'theme-on-kbd': '#FFFFFF', + 'theme-code': '#F5F5F5', + 'theme-on-code': '#000000', + }, +} + +const ocelotStandardDarkTheme: ThemeDefinition = { + dark: true, + colors: { + background: 'rgb(0, 0, 0)', + surface: 'rgb(14, 17, 23)', + // primary: rgbToHex(23, 181, 63, '#'), + primary: 'rgb(23, 181, 63)', + // 'primary-darken-1': rgbToHex(25, 122, 49, '#'), + 'primary-darken-1': 'rgb(25, 122, 49)', + secondary: 'rgb(0, 142, 230)', + // 'secondary-darken-1': '#018786', + error: 'rgb(219, 57, 36)', + // info: '#2196F3', + success: 'rgb(23, 181, 63)', + warning: 'rgb(230, 121, 25)', + }, + variables: { + 'border-color': '#000000', + 'border-opacity': 0.12, + 'high-emphasis-opacity': 0.87, + 'medium-emphasis-opacity': 0.6, + 'disabled-opacity': 0.38, + 'idle-opacity': 0.04, + 'hover-opacity': 0.04, + 'focus-opacity': 0.12, + 'selected-opacity': 0.08, + 'activated-opacity': 0.12, + 'pressed-opacity': 0.12, + 'dragged-opacity': 0.08, + 'theme-kbd': '#0000FF', + 'theme-on-kbd': '#FFFFFF', + 'theme-code': '#F5F5F5', + 'theme-on-code': '#000000', + }, +} + // eslint-disable-next-line @typescript-eslint/no-explicit-any export default (i18n: I18n, NonNullable, string, false>) => createVuetify({ @@ -13,4 +85,12 @@ export default (i18n: I18n, NonNullable, stri adapter: createVueI18nAdapter({ i18n, useI18n }), }, ssr: true, + theme: { + defaultTheme: 'ocelotStandardLightTheme', + // defaultTheme: 'ocelotStandardDarkTheme', + themes: { + ocelotStandardLightTheme, + ocelotStandardDarkTheme, + }, + }, }) diff --git a/frontend/src/components/menu/TopMenu.vue b/frontend/src/components/menu/TopMenu.vue index 2789e4104..63dca3d42 100644 --- a/frontend/src/components/menu/TopMenu.vue +++ b/frontend/src/components/menu/TopMenu.vue @@ -9,6 +9,13 @@ {{ $t('menu.app') }} {{ $t('menu.about') }} + + {{ + theme.global.current.value.dark + ? $t('menu.theme.switchToLight') + : $t('menu.theme.switchToDark') + }} + import { ref } from 'vue' -import { useLocale } from 'vuetify' +import { useLocale, useTheme } from 'vuetify' import VikeBtn from '#components/VikeBtn.vue' import LogoAvatar from './LogoAvatar.vue' +const theme = useTheme() +function toggleTheme() { + theme.global.name.value = theme.global.current.value.dark + ? 'ocelotStandardLightTheme' + : 'ocelotStandardDarkTheme' +} + const { current: locale } = useLocale() const isEnabled = ref(locale.value === 'de') const onChange = () => { diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 94e55fc13..987b424e8 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -48,6 +48,10 @@ "menu": { "about": "Über", "app": "Anwendung", - "home": "Daheim" + "home": "Daheim", + "theme": { + "switchToDark": "Dunkel", + "switchToLight": "Hell" + } } } diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index ac930f13d..8b990522e 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -48,6 +48,11 @@ "menu": { "about": "About", "app": "App", - "home": "Home" + "home": "Home", + "theme": { + "switchToDark": "Dark", + "switchToLight": "Light" + } + } }