Mercury/ui/src/stores/theme.ts
Matthew L McPeak 05cb37730d
All checks were successful
ci / build-ui (push) Successful in 14s
ci / test (push) Successful in 3m1s
ci / publish (push) Successful in 2m38s
Initial Commit
2026-06-17 16:21:16 -04:00

24 lines
546 B
TypeScript

import { ref } from 'vue'
export type Theme = 'apollo' | 'hades'
const stored = localStorage.getItem('mercury-theme') as Theme | null
const theme = ref<Theme>(stored ?? 'apollo')
function applyTheme(t: Theme) {
theme.value = t
document.documentElement.setAttribute('data-theme', t)
localStorage.setItem('mercury-theme', t)
}
applyTheme(theme.value)
export function useTheme() {
return {
theme,
isDark: () => theme.value === 'hades',
toggle() {
applyTheme(theme.value === 'apollo' ? 'hades' : 'apollo')
},
}
}