Feat(color-scheme): set the color scheme on the document body #149

Merged
jakob.scheid merged 1 commits from feature/remove-top-offset-on-mobile into main 2026-07-28 19:47:48 +02:00
3 changed files with 24 additions and 9 deletions
Showing only changes of commit 2206b9952b - Show all commits
+19 -6
View File
@@ -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');
}
});
</script>
<template>
<div
:style="{ colorScheme: colorScheme === 'auto' ? 'normal' : (colorScheme === 'dark' ? 'dark' : 'light')}"
:class="{ dark: colorScheme === 'dark', 'color-scheme-auto': colorScheme === 'auto' }"
id="app-wrapper"
>
<div id="app-wrapper">
<Navbar />
<router-view class="main-content" />
+2
View File
@@ -15,6 +15,8 @@ limitations under the License.
*/
body {
background-color: var(--light-bg);
color: var(--dark);
margin: 0;
font-size: 16px;
}
+3 -3
View File
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
#app-wrapper {
body {
--primary-color-l-8: oklch(0.897 0.202 260);
--primary-color-l-7: oklch(0.847 0.202 260);
--primary-color-l-6: oklch(0.797 0.202 260);
@@ -87,7 +87,7 @@ limitations under the License.
}
@media (prefers-color-scheme: dark) {
#app-wrapper.color-scheme-auto {
body.color-scheme-auto {
--dark-l-8: var(--white-d-8);
--dark-l-7: var(--white-d-7);
--dark-l-6: var(--white-d-6);
@@ -121,7 +121,7 @@ limitations under the License.
}
}
#app-wrapper.dark {
body.dark {
--dark-l-8: var(--white-d-8);
--dark-l-7: var(--white-d-7);
--dark-l-6: var(--white-d-6);