mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
872 B
31 lines
872 B
2 years ago
|
import type { MaybeRef } from '@vueuse/core'
|
||
2 years ago
|
import { computed, effectScope, tryOnScopeDispose, unref, watch, watchEffect } from '#build/imports'
|
||
2 years ago
|
import { useNuxtApp } from '#app'
|
||
2 years ago
|
import { theme } from '~/utils'
|
||
2 years ago
|
|
||
2 years ago
|
export function useColors(darkMode?: MaybeRef<boolean>) {
|
||
2 years ago
|
const scope = effectScope()
|
||
|
|
||
2 years ago
|
let mode = $ref(unref(darkMode))
|
||
|
const { $state } = useNuxtApp()
|
||
|
|
||
2 years ago
|
if (typeof mode === 'undefined') mode = $state.darkMode.value
|
||
2 years ago
|
|
||
2 years ago
|
scope.run(() => {
|
||
2 years ago
|
watch($state.darkMode, (newMode) => {
|
||
2 years ago
|
if (typeof mode === 'undefined') mode = newMode
|
||
2 years ago
|
})
|
||
2 years ago
|
|
||
2 years ago
|
watchEffect(() => {
|
||
|
const newMode = unref(darkMode)
|
||
|
if (newMode) mode = newMode
|
||
|
})
|
||
2 years ago
|
})
|
||
|
|
||
2 years ago
|
tryOnScopeDispose(() => scope.stop())
|
||
|
|
||
2 years ago
|
const colors = computed(() => (mode ? theme.dark : theme.light))
|
||
|
|
||
|
return { colors, getColorByIndex: (i: number) => colors.value[i % colors.value.length] }
|
||
|
}
|