File tree 1 file changed +15
-1
lines changed
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { computed } from 'vue-demi'
2
+ import { defaultWindow } from '../_configurable'
3
+ import { usePreferredDark } from '../usePreferredDark'
2
4
import { useColorMode } from '../useColorMode'
3
5
import type { BasicColorSchema , UseColorModeOptions } from '../useColorMode'
4
6
@@ -36,6 +38,7 @@ export function useDark(options: UseDarkOptions = {}) {
36
38
const {
37
39
valueDark = 'dark' ,
38
40
valueLight = '' ,
41
+ window = defaultWindow ,
39
42
} = options
40
43
41
44
const mode = useColorMode ( {
@@ -52,13 +55,24 @@ export function useDark(options: UseDarkOptions = {}) {
52
55
} ,
53
56
} )
54
57
58
+ const system = computed ( ( ) => {
59
+ if ( mode . system ) {
60
+ return mode . system . value
61
+ }
62
+ else {
63
+ // In Vue 2.6, ref not be extensible, mode.system is undefined
64
+ const preferredDark = usePreferredDark ( { window } )
65
+ return preferredDark . value ? 'dark' : 'light'
66
+ }
67
+ } )
68
+
55
69
const isDark = computed < boolean > ( {
56
70
get ( ) {
57
71
return mode . value === 'dark'
58
72
} ,
59
73
set ( v ) {
60
74
const modeVal = v ? 'dark' : 'light'
61
- if ( mode . system . value === modeVal )
75
+ if ( system . value === modeVal )
62
76
mode . value = 'auto'
63
77
else
64
78
mode . value = modeVal
You can’t perform that action at this time.
0 commit comments