Files
cmms/vue/components/theme.js
T
2026-09-11 13:30:02 +02:00

21 lines
571 B
JavaScript

import { ref } from 'vue';
const theme = ref(localStorage.getItem('theme') || 'auto');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
export function applyTheme() {
const resolved = theme.value === 'auto' ? (prefersDark.matches ? 'dark' : 'light') : theme.value;
document.documentElement.setAttribute('data-theme', resolved);
}
export function setTheme(value) {
theme.value = value;
localStorage.setItem('theme', value);
applyTheme();
}
prefersDark.addEventListener('change', () => {
if (theme.value === 'auto') applyTheme();
});