fix(client): use `usePreferredDark` with `appearance: "force-auto"` (#4263)

pull/4268/head
Mike Bostock 4 weeks ago committed by GitHub
parent 6ea60f5d0c
commit 3e8fc40c36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,5 +1,5 @@
import siteData from '@siteData' import siteData from '@siteData'
import { useDark } from '@vueuse/core' import { useDark, usePreferredDark } from '@vueuse/core'
import { import {
computed, computed,
inject, inject,
@ -79,13 +79,15 @@ export function initData(route: Route): VitePressData {
const isDark = const isDark =
appearance === 'force-dark' appearance === 'force-dark'
? ref(true) ? ref(true)
: appearance : appearance === 'force-auto'
? useDark({ ? usePreferredDark()
storageKey: APPEARANCE_KEY, : appearance
initialValue: () => (appearance === 'dark' ? 'dark' : 'auto'), ? useDark({
...(typeof appearance === 'object' ? appearance : {}) storageKey: APPEARANCE_KEY,
}) initialValue: () => (appearance === 'dark' ? 'dark' : 'auto'),
: ref(false) ...(typeof appearance === 'object' ? appearance : {})
})
: ref(false)
const hashRef = ref(inBrowser ? location.hash : '') const hashRef = ref(inBrowser ? location.hash : '')

Loading…
Cancel
Save