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
3 years ago
|
import type { MaybeRef } from '@vueuse/core'
|
||
3 years ago
|
import { computed, effectScope, tryOnScopeDispose, unref, watch, watchEffect } from '#build/imports'
|
||
3 years ago
|
import { useNuxtApp } from '#app'
|
||
2 years ago
|
import { theme } from '~/utils'
|
||
3 years ago
|
|
||
2 years ago
|
export function useColors(darkMode?: MaybeRef<boolean>) {
|
||
3 years ago
|
const scope = effectScope()
|
||
|
|
||
3 years ago
|
let mode = $ref(unref(darkMode))
|
||
|
const { $state } = useNuxtApp()
|
||
|
|
||
2 years ago
|
if (typeof mode === 'undefined') mode = $state.darkMode.value
|
||
3 years ago
|
|
||
3 years ago
|
scope.run(() => {
|
||
3 years ago
|
watch($state.darkMode, (newMode) => {
|
||
2 years ago
|
if (typeof mode === 'undefined') mode = newMode
|
||
3 years ago
|
})
|
||
3 years ago
|
|
||
3 years ago
|
watchEffect(() => {
|
||
|
const newMode = unref(darkMode)
|
||
|
if (newMode) mode = newMode
|
||
|
})
|
||
3 years ago
|
})
|
||
|
|
||
3 years ago
|
tryOnScopeDispose(() => scope.stop())
|
||
|
|
||
3 years ago
|
const colors = computed(() => (mode ? theme.dark : theme.light))
|
||
|
|
||
|
return { colors, getColorByIndex: (i: number) => colors.value[i % colors.value.length] }
|
||
|
}
|