From fcaf95091f4b238ec141cfea43021867d671bd52 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 24 Jul 2022 16:50:12 +0800 Subject: [PATCH] feat(useColorMode): new `initialValue` option close #1967, close #1969 --- packages/core/useColorMode/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core/useColorMode/index.ts b/packages/core/useColorMode/index.ts index c937425dfbe..f8b9f7f040f 100644 --- a/packages/core/useColorMode/index.ts +++ b/packages/core/useColorMode/index.ts @@ -25,6 +25,13 @@ export interface UseColorModeOptions extend */ attribute?: string + /** + * The initial color mode + * + * @default 'auto' + */ + initialValue?: T | BasicColorSchema + /** * Prefix when adding value to the attribute */ @@ -82,6 +89,7 @@ export function useColorMode(options: UseCo const { selector = 'html', attribute = 'class', + initialValue = 'auto', window = defaultWindow, storage, storageKey = 'vueuse-color-scheme', @@ -101,8 +109,8 @@ export function useColorMode(options: UseCo const preferredMode = computed(() => preferredDark.value ? 'dark' : 'light') const store = storageRef || (storageKey == null - ? ref('auto') as Ref - : useStorage(storageKey, 'auto', storage, { window, listenToStorageChanges })) + ? ref(initialValue) as Ref + : useStorage(storageKey, initialValue as BasicColorSchema, storage, { window, listenToStorageChanges })) const state = computed({ get() {