feat(frontend): add light/dark theme switcher
Add persisted theme mode (light, dark, system) with a header menu. Rework the light and dark palettes for stronger contrast and drop the high-contrast theme.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { computed, watch } from 'vue'
|
||||
import { usePreferredDark, useStorage } from '@vueuse/core'
|
||||
import { useTheme } from 'vuetify'
|
||||
|
||||
export type ThemeMode = 'light' | 'dark' | 'system'
|
||||
export type ResolvedTheme = 'light' | 'dark'
|
||||
|
||||
export interface ThemeOption {
|
||||
value: ThemeMode
|
||||
title: string
|
||||
icon: string
|
||||
}
|
||||
|
||||
export const themeOptions: ThemeOption[] = [
|
||||
{ value: 'light', title: 'Jasny', icon: 'mdi-white-balance-sunny' },
|
||||
{ value: 'dark', title: 'Ciemny', icon: 'mdi-weather-night' },
|
||||
{ value: 'system', title: 'Systemowy', icon: 'mdi-theme-light-dark' },
|
||||
]
|
||||
|
||||
export function useThemeMode() {
|
||||
const theme = useTheme()
|
||||
const preferredDark = usePreferredDark()
|
||||
const mode = useStorage<ThemeMode>('tarninahub-theme', 'system')
|
||||
|
||||
const resolved = computed<ResolvedTheme>(() =>
|
||||
mode.value === 'system' ? (preferredDark.value ? 'dark' : 'light') : mode.value,
|
||||
)
|
||||
|
||||
watch(resolved, (value) => theme.change(value), { immediate: true })
|
||||
|
||||
return { mode, resolved, preferredDark, themeOptions }
|
||||
}
|
||||
Reference in New Issue
Block a user