mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-09 07:35:01 -04:00
Use prefers-color-scheme
This commit is contained in:
parent
1e2a35b892
commit
7952709892
3 changed files with 12 additions and 7 deletions
|
@ -9,8 +9,7 @@ const { isDarkTheme } = toRefs(styleStore);
|
||||||
const themeStore = useThemeStore();
|
const themeStore = useThemeStore();
|
||||||
|
|
||||||
function toggleDarkTheme() {
|
function toggleDarkTheme() {
|
||||||
isDarkTheme.value = !isDarkTheme.value;
|
styleStore.toggleDark();
|
||||||
|
|
||||||
themeStore.toggleTheme();
|
themeStore.toggleTheme();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { useMediaQuery, useStorage } from '@vueuse/core';
|
import { useDark, useMediaQuery, useStorage, useToggle } from '@vueuse/core';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { type Ref, watch } from 'vue';
|
import { type Ref, watch } from 'vue';
|
||||||
|
|
||||||
export const useStyleStore = defineStore('style', {
|
export const useStyleStore = defineStore('style', {
|
||||||
state: () => {
|
state: () => {
|
||||||
const isDarkTheme = useStorage('isDarkTheme', true) as Ref<boolean>;
|
const isDarkTheme = useDark();
|
||||||
|
const toggleDark = useToggle(isDarkTheme);
|
||||||
const isSmallScreen = useMediaQuery('(max-width: 700px)');
|
const isSmallScreen = useMediaQuery('(max-width: 700px)');
|
||||||
const isMenuCollapsed = useStorage('isMenuCollapsed', isSmallScreen.value) as Ref<boolean>;
|
const isMenuCollapsed = useStorage('isMenuCollapsed', isSmallScreen.value) as Ref<boolean>;
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ export const useStyleStore = defineStore('style', {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isDarkTheme,
|
isDarkTheme,
|
||||||
|
toggleDark,
|
||||||
isMenuCollapsed,
|
isMenuCollapsed,
|
||||||
isSmallScreen,
|
isSmallScreen,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
import { useStyleStore } from '@/stores/style.store';
|
||||||
|
|
||||||
export const useThemeStore = defineStore('ui-theme', {
|
export const useThemeStore = defineStore('ui-theme', {
|
||||||
state: () => ({
|
state: () => {
|
||||||
themeType: useStorage<'dark' | 'light'>('ui-store:theme-type', 'dark') as Ref<'dark' | 'light'>,
|
const styleStore = useStyleStore();
|
||||||
}),
|
return {
|
||||||
|
themeType: styleStore.isDarkTheme ? 'dark' : 'light',
|
||||||
|
};
|
||||||
|
},
|
||||||
getters: {
|
getters: {
|
||||||
isDarkTheme(): boolean {
|
isDarkTheme(): boolean {
|
||||||
return this.themeType === 'dark';
|
return this.themeType === 'dark';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue