mirror of
https://github.com/nocodb/nocodb.git
synced 2026-05-03 12:16:38 +00:00
* fix: get rid of barrel files * chore: get rid of explicit imports * fix: use explicit import for classes and enums * fix: use explicit import for enum & class & aliases * fix: build issues
29 lines
768 B
TypeScript
29 lines
768 B
TypeScript
import { ref } from 'vue'
|
|
import type { MaybeRef } from '@vueuse/core'
|
|
|
|
export function useColors(darkMode?: MaybeRef<boolean>) {
|
|
const scope = effectScope()
|
|
|
|
const mode = ref(unref(darkMode))
|
|
const { $state } = useNuxtApp()
|
|
|
|
if (typeof mode.value === 'undefined') mode.value = $state.darkMode.value
|
|
|
|
scope.run(() => {
|
|
watch($state.darkMode, (newMode) => {
|
|
if (typeof mode.value === 'undefined') mode.value = newMode
|
|
})
|
|
|
|
watchEffect(() => {
|
|
const newMode = unref(darkMode)
|
|
if (newMode) mode.value = newMode
|
|
})
|
|
})
|
|
|
|
tryOnScopeDispose(() => scope.stop())
|
|
|
|
const colors = computed(() => (mode.value ? theme.dark : theme.light))
|
|
|
|
return { colors, getColorByIndex: (i: number) => colors.value[i % colors.value.length] }
|
|
}
|