1 parent
c03f9826af
commit
1274dece67
4 files changed
+56
-14
No files matched your search
@@ -0,0 +1,21 @@
|
||||
export type ThemeMode = 'light' | 'dark' | 'system'
|
||||
|
||||
export const THEME_MODES: ThemeMode[] = ['light', 'dark', 'system']
|
||||
export const THEME_STORAGE_KEY = 'theme-mode'
|
||||
|
||||
export const THEME_ICONS: Record<ThemeMode, string> = {
|
||||
light: 'mdi-white-balance-sunny',
|
||||
dark: 'mdi-weather-night',
|
||||
system: 'mdi-theme-light-dark',
|
||||
}
|
||||
|
||||
export function isThemeMode(value: unknown): value is ThemeMode {
|
||||
return THEME_MODES.includes(value as ThemeMode)
|
||||
}
|
||||
|
||||
/** Read the persisted theme mode synchronously, before Vuetify is created, to avoid a flash of the wrong theme. */
|
||||
export function readStoredThemeMode(): ThemeMode {
|
||||
if (typeof localStorage === 'undefined') return 'system'
|
||||
const stored = localStorage.getItem(THEME_STORAGE_KEY)
|
||||
return isThemeMode(stored) ? stored : 'system'
|
||||
}
|
||||
Reference in new issue
Block a user