Files
speckle-server/packages/frontend-2/lib/core/composables/theme.ts
T
Kristaps Fabians Geikins b02a07e2b6 feat: Frontend 2.0 MVP
2023-05-08 10:47:01 +03:00

26 lines
666 B
TypeScript

import { Optional } from '@speckle/shared'
import { useSynchronizedCookie } from '~~/lib/common/composables/reactiveCookie'
import { CookieKeys } from '~~/lib/common/helpers/constants'
export enum AppTheme {
Light = 'light',
Dark = 'dark'
}
/**
* Use this to read & write theme
*/
export function useTheme() {
const themeCookie = useSynchronizedCookie<Optional<AppTheme>>(CookieKeys.Theme)
const isDarkTheme = computed(() => themeCookie.value === AppTheme.Dark)
const isLightTheme = computed(() => !isDarkTheme.value)
return {
setTheme: (newTheme: AppTheme) => {
themeCookie.value = newTheme
},
isDarkTheme,
isLightTheme
}
}