Files
website/store/color.ts
Arthur DANJOU 5ca0137c4e Lint code
Signed-off-by: Arthur DANJOU <arthurdanjou@outlook.fr>
2024-04-20 01:33:40 +02:00

29 lines
598 B
TypeScript

import {defineStore} from 'pinia'
import {ColorsTheme} from '~~/types'
export const useColorStore = defineStore(
'color',
() => {
const colorCookie = useCookie('color', { path: '/', default: () => ColorsTheme.RED })
const appConfig = useAppConfig()
watch(colorCookie, (newColor) => {
appConfig.ui.primary = newColor
}, { immediate: true })
function setColor(color: string) {
colorCookie.value = color as ColorsTheme
}
const getColor = computed(() => colorCookie)
return {
getColor,
setColor,
}
},
{
persist: true,
},
)