feat: range of font size (#1376)
This commit is contained in:
parent
85be61a316
commit
1a577343da
20 changed files with 86 additions and 102 deletions
|
@ -1,6 +1,10 @@
|
|||
import { DEFAULT_FONT_SIZE } from '~/constants'
|
||||
|
||||
export type FontSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
||||
export type FontSize = `${number}px`
|
||||
|
||||
// Temporary type for backward compatibility
|
||||
export type OldFontSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
||||
|
||||
export type ColorMode = 'light' | 'dark' | 'system'
|
||||
|
||||
export interface PreferencesSettings {
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
import type { Ref } from 'vue'
|
||||
import type { VueI18n } from 'vue-i18n'
|
||||
import type { LocaleObject } from 'vue-i18n-routing'
|
||||
import type { PreferencesSettings, UserSettings } from './definition'
|
||||
import type { FontSize, OldFontSize, PreferencesSettings, UserSettings } from './definition'
|
||||
import { STORAGE_KEY_SETTINGS } from '~/constants'
|
||||
import { oldFontSizeMap } from '~~/constants/options'
|
||||
|
||||
export function useUserSettings() {
|
||||
const i18n = useNuxtApp().vueApp.config.globalProperties.$i18n as VueI18n
|
||||
const { locales } = i18n
|
||||
const supportLanguages = (locales as LocaleObject[]).map(locale => locale.code)
|
||||
return useUserLocalStorage<UserSettings>(STORAGE_KEY_SETTINGS, () => getDefaultUserSettings(supportLanguages))
|
||||
const settingsStorage = useUserLocalStorage<UserSettings>(STORAGE_KEY_SETTINGS, () => getDefaultUserSettings(supportLanguages))
|
||||
|
||||
// Backward compatibility, font size was xs, sm, md, lg, xl before
|
||||
if (settingsStorage.value.fontSize && !settingsStorage.value.fontSize.includes('px'))
|
||||
settingsStorage.value.fontSize = oldFontSizeMap[settingsStorage.value.fontSize as OldFontSize] as FontSize
|
||||
|
||||
return settingsStorage
|
||||
}
|
||||
|
||||
// TODO: refactor & simplify this
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue