diff options
author | かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> | 2024-12-12 01:31:29 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-11 16:31:29 +0000 |
commit | de15f8e2d3264b9ffb18c3a089612ef604eb87b8 (patch) | |
tree | ae5419e798d55b978596ca7a396fdb395d2cf4fc /bskyembed/src/color-mode.ts | |
parent | 48c5341644935b103fa81c91b23391f7b7c8a572 (diff) | |
download | voidsky-de15f8e2d3264b9ffb18c3a089612ef604eb87b8.tar.zst |
feat(embed): Add support for dark mode (#6912)
* 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
Diffstat (limited to 'bskyembed/src/color-mode.ts')
-rw-r--r-- | bskyembed/src/color-mode.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/bskyembed/src/color-mode.ts b/bskyembed/src/color-mode.ts new file mode 100644 index 000000000..2b392c617 --- /dev/null +++ b/bskyembed/src/color-mode.ts @@ -0,0 +1,17 @@ +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') + }) +} |