config.js
1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { storeToRefs } from 'pinia'
import { useTheme } from 'vuetify'
import { cookieRef, useLayoutConfigStore } from '@layouts/stores/config'
import { themeConfig } from '@themeConfig'
// SECTION Store
export const useConfigStore = defineStore('config', () => {
// 👉 Theme
const userPreferredColorScheme = usePreferredColorScheme()
const cookieColorScheme = cookieRef('color-scheme', 'light')
watch(userPreferredColorScheme, val => {
if (val !== 'no-preference')
cookieColorScheme.value = val
}, { immediate: true })
const theme = cookieRef('theme', themeConfig.app.theme)
// 👉 isVerticalNavSemiDark
const isVerticalNavSemiDark = cookieRef('isVerticalNavSemiDark', themeConfig.verticalNav.isVerticalNavSemiDark)
// 👉 isVerticalNavSemiDark
const skin = cookieRef('skin', themeConfig.app.skin)
// ℹ️ We need to use `storeToRefs` to forward the state
const { isLessThanOverlayNavBreakpoint, appContentWidth, navbarType, isNavbarBlurEnabled, appContentLayoutNav, isVerticalNavCollapsed, footerType, isAppRTL } = storeToRefs(useLayoutConfigStore())
return {
theme,
isVerticalNavSemiDark,
skin,
// @layouts exports
isLessThanOverlayNavBreakpoint,
appContentWidth,
navbarType,
isNavbarBlurEnabled,
appContentLayoutNav,
isVerticalNavCollapsed,
footerType,
isAppRTL,
}
})
// !SECTION
// SECTION Init
export const initConfigStore = () => {
const userPreferredColorScheme = usePreferredColorScheme()
const vuetifyTheme = useTheme()
const configStore = useConfigStore()
watch([() => configStore.theme, userPreferredColorScheme], () => {
vuetifyTheme.global.name.value = configStore.theme === 'system'
? userPreferredColorScheme.value === 'dark'
? 'dark'
: 'light'
: configStore.theme
})
onMounted(() => {
if (configStore.theme === 'system')
vuetifyTheme.global.name.value = userPreferredColorScheme.value
})
}
// !SECTION