8000 fix(useDark): In Vue 2.6 mode.system is undefined by Teaghy · Pull Request #3562 · vueuse/vueuse · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(useDark): In Vue 2.6 mode.system is undefined #3562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/core/useDark/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { computed } from 'vue-demi'
import { defaultWindow } from '../_configurable'
import { usePreferredDark } from '../usePreferredDark'
import { useColorMode } from '../useColorMode'
import type { BasicColorSchema, UseColorModeOptions } from '../useColorMode'

Expand Down Expand Up @@ -36,6 +38,7 @@ export function useDark(options: UseDarkOptions = {}) {
const {
valueDark = 'dark',
valueLight = '',
window = defaultWindow,
} = options

const mode = useColorMode({
Expand All @@ -52,13 +55,24 @@ export function useDark(options: UseDarkOptions = {}) {
},
})

const system = computed(() => {
if (mode.system) {
return mode.system.value
}
else {
// In Vue 2.6, ref not be extensible, mode.system is undefined
const preferredDark = usePreferredDark({ window })
return preferredDark.value ? 'dark' : 'light'
}
})

const isDark = computed<boolean>({
get() {
return mode.value === 'dark'
},
set(v) {
const modeVal = v ? 'dark' : 'light'
if (mode.system.value === modeVal)
if (system.value === modeVal)
mode.value = 'auto'
else
mode.value = modeVal
Expand Down
0