nextload/src/utils/theme.ts
2024-06-24 00:05:41 +02:00

22 lines
644 B
TypeScript

export function switchTheme(themeClass: string): void {
const bodyElement = document.body
const classesToRemove = ['light', 'dark', 'autonomic']
bodyElement.classList.remove(...classesToRemove)
bodyElement.classList.add(themeClass)
}
export function handleThemeChange(event: Event): void {
const selectElement = event.target as HTMLSelectElement
const selectedTheme = selectElement.value
switchTheme(selectedTheme)
}
export function initializeThemeSelector(): void {
const themeSelector = document.getElementById('theme-selector')
if (themeSelector) {
themeSelector.addEventListener('change', handleThemeChange)
}
}