chore: Replace multiple mixins to simgle use composables

This commit is contained in:
Fayaz Ahmed
2024-08-05 15:41:45 +05:30
parent b4b308336f
commit 0bd62cf33f
10 changed files with 488 additions and 0 deletions
@@ -0,0 +1,35 @@
import { computed } from 'vue';
import { useStore } from 'vuex';
/**
* Composable for handling dark mode preferences and utility functions.
* @returns {Object} An object containing computed properties and methods for dark mode management.
*/
export function useDarkMode() {
const store = useStore();
const darkMode = computed(() => store.getters['appConfig/darkMode']);
const prefersDarkMode = computed(() => {
const isOSOnDarkMode =
darkMode.value === 'auto' &&
window.matchMedia('(prefers-color-scheme: dark)').matches;
return isOSOnDarkMode || darkMode.value === 'dark';
});
const dm = (light, dark) => {
if (darkMode.value === 'light') {
return light;
}
if (darkMode.value === 'dark') {
return dark;
}
return `${light} ${dark}`;
};
return {
darkMode,
prefersDarkMode,
dm,
};
}