mirror of
https://github.com/elk-zone/elk
synced 2024-11-30 15:58:06 +09:00
chore: clean up
This commit is contained in:
parent
b40832a7eb
commit
6c9908d030
@ -1,18 +1,16 @@
|
||||
import type { InjectionKey, Ref } from 'vue'
|
||||
import { STORAGE_KEY_FONT_SIZE } from '~/constants'
|
||||
|
||||
export type FontSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
||||
export const InjectionKeyFontSize = Symbol('fontSize') as InjectionKey<Ref<FontSize>>
|
||||
const InjectionKeyFontSize = Symbol('fontSize') as InjectionKey<Ref<FontSize>>
|
||||
const DEFAULT = 'md'
|
||||
|
||||
export function setFontSize(size: FontSize) {
|
||||
inject(InjectionKeyFontSize)!.value = size
|
||||
}
|
||||
export type FontSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
||||
|
||||
export function getFontSize() {
|
||||
return inject(InjectionKeyFontSize)!
|
||||
}
|
||||
|
||||
export const fontSizeMap = {
|
||||
const fontSizeMap = {
|
||||
xs: '13px',
|
||||
sm: '14px',
|
||||
md: '15px',
|
||||
@ -21,19 +19,19 @@ export const fontSizeMap = {
|
||||
}
|
||||
|
||||
export async function setupFontSize() {
|
||||
const fontSize = useCookie<FontSize>(STORAGE_KEY_FONT_SIZE, { default: () => 'md' })
|
||||
const fontSize = useCookie<FontSize>(STORAGE_KEY_FONT_SIZE, { default: () => DEFAULT })
|
||||
getCurrentInstance()?.appContext.app.provide(InjectionKeyFontSize, fontSize)
|
||||
|
||||
if (!process.server) {
|
||||
watchEffect(() => {
|
||||
document.documentElement.style.setProperty('--font-size', fontSizeMap[fontSize.value || 'md'])
|
||||
document.documentElement.style.setProperty('--font-size', fontSizeMap[fontSize.value || DEFAULT])
|
||||
})
|
||||
}
|
||||
else {
|
||||
useHead({
|
||||
style: [
|
||||
{
|
||||
innerHTML: `:root { --font-size: ${fontSizeMap[fontSize.value || 'md']}; }`,
|
||||
innerHTML: `:root { --font-size: ${fontSizeMap[fontSize.value || DEFAULT]}; }`,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user