Переписал на vue3

This commit is contained in:
Ilia Miheev
2026-06-20 12:42:44 +03:00
parent f593d8223b
commit a90db0d7dc
17 changed files with 1994 additions and 255 deletions
+30
View File
@@ -0,0 +1,30 @@
import { ref, computed, onMounted } from 'vue'
export function useTheme() {
const theme = ref('dark')
const isLightTheme = computed(() => theme.value === 'light')
function applyTheme(name) {
theme.value = name
document.documentElement.className = name
localStorage.setItem('theme', name)
}
function toggleTheme() {
applyTheme(theme.value === 'dark' ? 'light' : 'dark')
}
onMounted(() => {
const saved = localStorage.getItem('theme')
if (saved === 'dark' || saved === 'light') {
applyTheme(saved)
return
}
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
applyTheme(prefersDark ? 'dark' : 'light')
})
return { theme, isLightTheme, toggleTheme }
}