diff options
author | Jan-Olof Eriksson <jan-olof.eriksson@iki.fi> | 2024-02-21 13:22:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-21 13:22:13 +0200 |
commit | 38fd4282f88ac020ee72d5a6324191ee80798450 (patch) | |
tree | 18f713fed78387f1cb83ac0818b4f1333fad6db8 /src/alf/util/useColorModeTheme.ts | |
parent | 1269e76071ea7c79b93d1a58e80b74746c71ecd9 (diff) | |
parent | f88b16525498584f81ea7f594a63623fc5dc7ce9 (diff) | |
download | voidsky-38fd4282f88ac020ee72d5a6324191ee80798450.tar.zst |
Merge branch 'bluesky-social:main' into main
Diffstat (limited to 'src/alf/util/useColorModeTheme.ts')
-rw-r--r-- | src/alf/util/useColorModeTheme.ts | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/alf/util/useColorModeTheme.ts b/src/alf/util/useColorModeTheme.ts index 48cf904fe..4f8921bf9 100644 --- a/src/alf/util/useColorModeTheme.ts +++ b/src/alf/util/useColorModeTheme.ts @@ -13,7 +13,7 @@ export function useColorModeTheme(): ThemeName { React.useLayoutEffect(() => { const theme = getThemeName(colorScheme, colorMode, darkTheme) updateDocument(theme) - updateSystemBackground(theme) + SystemUI.setBackgroundColorAsync(getBackgroundColor(theme)) }, [colorMode, colorScheme, darkTheme]) return React.useMemo( @@ -42,23 +42,24 @@ function updateDocument(theme: ThemeName) { if (isWeb && typeof window !== 'undefined') { // @ts-ignore web only const html = window.document.documentElement + // @ts-ignore web only + const meta = window.document.querySelector('meta[name="theme-color"]') + // remove any other color mode classes html.className = html.className.replace(/(theme)--\w+/g, '') - html.classList.add(`theme--${theme}`) + // set color to 'theme-color' meta tag + meta?.setAttribute('content', getBackgroundColor(theme)) } } -function updateSystemBackground(theme: ThemeName) { +function getBackgroundColor(theme: ThemeName): string { switch (theme) { case 'light': - SystemUI.setBackgroundColorAsync(light.atoms.bg.backgroundColor) - break + return light.atoms.bg.backgroundColor case 'dark': - SystemUI.setBackgroundColorAsync(dark.atoms.bg.backgroundColor) - break + return dark.atoms.bg.backgroundColor case 'dim': - SystemUI.setBackgroundColorAsync(dim.atoms.bg.backgroundColor) - break + return dim.atoms.bg.backgroundColor } } |