mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-03 04:27:53 +00:00
# Pull Request Template ## Description Replaces darkModeMixin with the new useDarkMode composable and replaces wll usages of mixin the the composable in components and pages Fixes https://linear.app/chatwoot/issue/CW-3474/rewrite-darkmodemixin-mixin-to-a-composable ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import { computed } from 'vue';
|
|
import { useMapGetter } from 'dashboard/composables/store';
|
|
|
|
const isDarkModeAuto = mode => mode === 'auto';
|
|
const isDarkMode = mode => mode === 'dark';
|
|
|
|
const getSystemPreference = () =>
|
|
window.matchMedia?.('(prefers-color-scheme: dark)').matches ?? false;
|
|
|
|
const calculatePrefersDarkMode = (mode, systemPreference) =>
|
|
isDarkModeAuto(mode) ? systemPreference : isDarkMode(mode);
|
|
|
|
const calculateThemeClass = (mode, light, dark) => {
|
|
if (isDarkModeAuto(mode)) return `${light} ${dark}`;
|
|
return isDarkMode(mode) ? dark : light;
|
|
};
|
|
|
|
/**
|
|
* Composable for handling dark mode.
|
|
* @returns {Object} An object containing computed properties and methods for dark mode.
|
|
*/
|
|
export function useDarkMode() {
|
|
const darkMode = useMapGetter('appConfig/darkMode');
|
|
|
|
const systemPreference = computed(getSystemPreference);
|
|
|
|
const prefersDarkMode = computed(() =>
|
|
calculatePrefersDarkMode(darkMode.value, systemPreference.value)
|
|
);
|
|
|
|
const getThemeClass = (light, dark) =>
|
|
calculateThemeClass(darkMode.value, light, dark);
|
|
|
|
return {
|
|
darkMode,
|
|
prefersDarkMode,
|
|
getThemeClass,
|
|
};
|
|
}
|