-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
636f063
commit 83ea987
Showing
4 changed files
with
38 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { captureException } from '@sentry/react' | ||
import { useValues } from 'kea' | ||
import { useEffect } from 'react' | ||
import { sceneLogic } from 'scenes/sceneLogic' | ||
|
||
import { themeLogic } from '~/layout/navigation-3000/themeLogic' | ||
|
||
export function useThemedHtml(): void { | ||
const { isDarkModeOn } = useValues(themeLogic) | ||
const { sceneConfig } = useValues(sceneLogic) | ||
|
||
useEffect(() => { | ||
document.body.setAttribute('theme', isDarkModeOn ? 'dark' : 'light') | ||
// overflow-hidden since each area handles scrolling individually (e.g. navbar, scene, side panel) | ||
document.body.classList.add('overflow-hidden') | ||
}, [isDarkModeOn]) | ||
|
||
useEffect(() => { | ||
// Add a theme-color meta tag to the head to change the address bar color on browsers that support it | ||
try { | ||
const root = document.documentElement | ||
const style = getComputedStyle(root) | ||
const backgroundColor = sceneConfig?.projectBased | ||
? style.getPropertyValue(isDarkModeOn ? '--accent-3000-dark' : '--accent-3000-light') | ||
: style.getPropertyValue('--bg-bridge') | ||
|
||
document.head.querySelector('meta[name="theme-color"]')?.remove() | ||
document.head.insertAdjacentHTML('beforeend', `<meta name="theme-color" content="${backgroundColor}">`) | ||
} catch (e) { | ||
console.warn('Failed to set theme-color meta tag. This could indicate the variables no longer exist', e) | ||
captureException(new Error('Failed to set theme-color meta tag'), { extra: { error: e } }) | ||
} | ||
}, [isDarkModeOn, sceneConfig?.projectBased]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters