@bitrix24/b24ui-nuxt
Version:
Bitrix24 UI-Kit for developing web applications REST API for NUXT & VUE
31 lines (30 loc) • 783 B
JavaScript
import { useColorMode as useColorModeVueUse } from "@vueuse/core";
import appConfig from "#build/app.config";
export const useColorMode = () => {
if (!appConfig.colorMode) {
return {
forced: true
};
}
const { store, system } = useColorModeVueUse({
attribute: "class",
initialValue: appConfig?.colorModeTypeLight || "light",
modes: {
auto: "auto",
light: appConfig?.colorModeTypeLight || "light",
dark: "dark"
}
});
return {
get preference() {
return store.value === "auto" ? "system" : store.value;
},
set preference(value) {
store.value = value === "system" ? "auto" : value;
},
get value() {
return store.value === "auto" ? system.value : store.value;
},
forced: false
};
};