From 630a8268e32e54e222ca496d8a4e1943ce1bacaa Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Tue, 28 Jul 2026 17:45:00 +0200 Subject: [PATCH] feat(color-scheme): set color scheme on body The color scheme is now set on the document body. The reactivity is ensured by a watcher on the color scheme ref. The color CSS variables are now set on the body. --- src/App.vue | 27 +++++++++++++++++++-------- src/styles/common.css | 2 ++ src/styles/variables/colors.css | 6 +++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/App.vue b/src/App.vue index 5044bf4..f40f23a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -24,15 +24,28 @@ import { ref, provide, watch } from 'vue'; const { getColorScheme, updateColorScheme } = useColorScheme(); const colorScheme = ref(getColorScheme()); provide('colorScheme', colorScheme); -watch(colorScheme, val => updateColorScheme(val)) +watch(colorScheme, (newValue) => { + updateColorScheme(newValue); + document.body.style.setProperty(colorScheme, { + auto: 'normal', + dark: 'dark', + light: 'light' + }); + if (newValue === 'dark') { + document.body.classList.add('dark'); + } else { + document.body.classList.remove('dark'); + } + if (newValue === 'auto') { + document.body.classList.add('color-scheme-auto'); + } else { + document.body.classList.remove('color-scheme-auto'); + } +});