de15f8e2d3
* feat(embed): Support dark mode (wip) * finishing up the implementation * fix tailwind color selector * tweak design * refactor: unify types * fix * fix english grammar * refactor: unify types * tweak design * remove the customization part
18 lines
468 B
TypeScript
18 lines
468 B
TypeScript
export function applyTheme(theme: 'light' | 'dark') {
|
|
document.documentElement.classList.remove('light', 'dark')
|
|
document.documentElement.classList.add(theme)
|
|
}
|
|
|
|
export function initColorMode() {
|
|
applyTheme(
|
|
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
? 'dark'
|
|
: 'light',
|
|
)
|
|
window
|
|
.matchMedia('(prefers-color-scheme: dark)')
|
|
.addEventListener('change', mql => {
|
|
applyTheme(mql.matches ? 'dark' : 'light')
|
|
})
|
|
}
|