-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththeme-custom.client.ts
More file actions
30 lines (26 loc) · 990 Bytes
/
theme-custom.client.ts
File metadata and controls
30 lines (26 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { useStorage } from '@vueuse/core'
import { CUSTOM_PRIMARY_PALETTES, paletteToPrimaryCssVars } from '~/config/theme'
const THEME_OVERRIDE_KEY = 'ngi-theme-override'
export default defineNuxtPlugin(() => {
const themeOverride = useStorage<{ primary: string | null, gray: string | null }>(THEME_OVERRIDE_KEY, {
primary: null,
gray: null
})
const styleEl = document.createElement('style')
styleEl.id = 'una-ui-theme-custom'
document.head.appendChild(styleEl)
watchEffect(() => {
const name = themeOverride.value.primary
const palette = name && name in CUSTOM_PRIMARY_PALETTES ? CUSTOM_PRIMARY_PALETTES[name as keyof typeof CUSTOM_PRIMARY_PALETTES] : null
if (palette) {
const vars = paletteToPrimaryCssVars(palette)
const declarations = Object.entries(vars)
.map(([k, v]) => `${k}: ${v};`)
.join('\n')
styleEl.textContent = `:root {\n${declarations}\n}`
}
else {
styleEl.textContent = ''
}
})
})