elk/composables/fontSize.ts

22 lines
494 B
TypeScript
Raw Normal View History

2022-12-23 22:47:13 +00:00
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])
}