docs: Fix dark mode logos in API reference (#1504)
This commit is contained in:
@@ -8,19 +8,40 @@ import { useColorMode } from 'theme-ui'
|
||||
|
||||
export default function ColorModeToggler () {
|
||||
const [, setColorMode] = useColorMode()
|
||||
|
||||
function checkLocalStorage (currentTheme, toggleTheme) {
|
||||
//check that theme local storage values are set correctly
|
||||
let themeUiColorMode = window.localStorage.getItem('theme-ui-color-mode');
|
||||
let theme = window.localStorage.getItem('theme')
|
||||
if (!themeUiColorMode) {
|
||||
themeUiColorMode = theme || currentTheme
|
||||
window.localStorage.setItem('theme-ui-color-mode', themeUiColorMode);
|
||||
setColorMode(themeUiColorMode);
|
||||
}
|
||||
if (!theme) {
|
||||
theme = themeUiColorMode || currentTheme
|
||||
window.localStorage.setItem('theme', theme);
|
||||
toggleTheme(theme)
|
||||
}
|
||||
|
||||
return theme || themeUiColorMode || currentTheme;
|
||||
}
|
||||
|
||||
return (
|
||||
<ThemeToggler>
|
||||
{({ theme, toggleTheme }) => (
|
||||
<button onClick={() => {
|
||||
const mode = theme === 'dark' ? 'light' : 'dark';
|
||||
toggleTheme(mode);
|
||||
setColorMode(mode);
|
||||
}} className="dark-mode-toggler">
|
||||
{theme === "light" && <LightMode />}
|
||||
{theme === "dark" && <DarkMode />}
|
||||
</button>
|
||||
)}
|
||||
{({ theme, toggleTheme }) => {
|
||||
const currentTheme = checkLocalStorage(theme, toggleTheme);
|
||||
return (
|
||||
<button onClick={() => {
|
||||
const mode = currentTheme === 'dark' ? 'light' : 'dark';
|
||||
toggleTheme(mode);
|
||||
setColorMode(mode);
|
||||
}} className="dark-mode-toggler">
|
||||
{currentTheme === "light" && <LightMode />}
|
||||
{currentTheme === "dark" && <DarkMode />}
|
||||
</button>
|
||||
);
|
||||
}}
|
||||
</ThemeToggler>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user