feat: font size preference

This commit is contained in:
patak 2022-12-23 23:47:13 +01:00
parent 99abb78ef1
commit 41ef187379
9 changed files with 65 additions and 1 deletions

21
composables/fontSize.ts Normal file
View file

@ -0,0 +1,21 @@
import { STORAGE_KEY_FONT_SIZE } from '~/constants'
export type FontSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
export const fontSize = useLocalStorage<FontSize>(STORAGE_KEY_FONT_SIZE, 'md')
export function setFontSize(size: FontSize) {
fontSize.value = size
}
export const fontSizeMap = {
xs: '13px',
sm: '14px',
md: '15px',
lg: '16px',
xl: '17px',
}
export function setFontSizeCSSVar() {
document.documentElement.style.setProperty('--font-size', fontSizeMap[fontSize.value])
}

View file

@ -66,3 +66,10 @@ export async function setupI18n() {
})
})
}
export async function setupFontSize() {
if (!process.server) {
setFontSizeCSSVar()
watch(fontSize, setFontSizeCSSVar)
}
}