Files
solidtime/resources/js/utils/theme.ts
Gregor Vostrak df2fe1da1e add light mode
2025-03-28 14:54:31 +01:00

26 lines
719 B
TypeScript

import { usePreferredColorScheme, useStorage } from "@vueuse/core";
import { computed, watch } from "vue";
type themeOption = "system" | "light" | "dark";
const themeSetting = useStorage<themeOption>("theme", "system");
// reload page when themeSettingChanges
watch(
themeSetting,
() => {
location.reload();
}
)
const preferredColor = usePreferredColorScheme();
const theme = computed(() => {
if(themeSetting.value === "system"){
console.log(preferredColor.value);
if (preferredColor.value === 'no-preference') {
return 'dark';
}
return preferredColor.value;
}
return themeSetting.value
});
export { type themeOption, themeSetting, theme };