Skip to content

Commit

Permalink
feat(useColorMode): new initialValue option
Browse files Browse the repository at this point in the history
close #1967, close #1969
  • Loading branch information
antfu committed Jul 24, 2022
1 parent 6a3414e commit fcaf950
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/core/useColorMode/index.ts
Expand Up @@ -25,6 +25,13 @@ export interface UseColorModeOptions<T extends string = BasicColorSchema> extend
*/
attribute?: string

/**
* The initial color mode
*
* @default 'auto'
*/
initialValue?: T | BasicColorSchema

/**
* Prefix when adding value to the attribute
*/
Expand Down Expand Up @@ -82,6 +89,7 @@ export function useColorMode<T extends string = BasicColorSchema>(options: UseCo
const {
selector = 'html',
attribute = 'class',
initialValue = 'auto',
window = defaultWindow,
storage,
storageKey = 'vueuse-color-scheme',
Expand All @@ -101,8 +109,8 @@ export function useColorMode<T extends string = BasicColorSchema>(options: UseCo
const preferredMode = computed(() => preferredDark.value ? 'dark' : 'light')

const store = storageRef || (storageKey == null
? ref('auto') as Ref<T | BasicColorSchema>
: useStorage<T | BasicColorSchema>(storageKey, 'auto', storage, { window, listenToStorageChanges }))
? ref(initialValue) as Ref<T | BasicColorSchema>
: useStorage<T | BasicColorSchema>(storageKey, initialValue as BasicColorSchema, storage, { window, listenToStorageChanges }))

const state = computed<T | BasicColorSchema>({
get() {
Expand Down

0 comments on commit fcaf950

Please sign in to comment.