-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #410 from brianlovin/fix-dark-mode
Fix dark mode
- Loading branch information
Showing
3 changed files
with
21 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as React from 'react' | ||
import useDarkMode from 'use-dark-mode' | ||
import { ThemeProvider } from 'styled-components'; | ||
import { light, dark } from '~/components/Theme'; | ||
|
||
export default function DarkMode({ children }) { | ||
const darkMode = useDarkMode(false); | ||
const [theme, setTheme] = React.useState(light); | ||
|
||
React.useEffect(() => { | ||
setTheme(darkMode.value ? dark : light); | ||
}, [darkMode, darkMode.value]); | ||
|
||
return <ThemeProvider theme={theme}>{children}</ThemeProvider>; | ||
}; |
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 |
---|---|---|
@@ -1,41 +1,22 @@ | ||
import * as React from 'react' | ||
import { ThemeProvider } from 'styled-components'; | ||
import useDarkMode from 'use-dark-mode' | ||
import GlobalStyles from '~/components/GlobalStyles'; | ||
import { light, dark } from '~/components/Theme'; | ||
import FathomProvider from './Fathom' | ||
import SEO from './SEO' | ||
import DarkMode from './DarkMode'; | ||
|
||
interface Props { | ||
children?: any; | ||
} | ||
|
||
export default ({ children }: Props) => { | ||
const { value } = useDarkMode(false, { storageKey: null, onChange: null }) | ||
const theme = value ? dark : light | ||
|
||
const [mounted, setMounted] = React.useState(false) | ||
|
||
React.useEffect(() => { | ||
setMounted(true) | ||
}, []) | ||
|
||
const body = | ||
return ( | ||
<FathomProvider> | ||
<SEO /> | ||
|
||
<ThemeProvider theme={theme}> | ||
<DarkMode> | ||
<GlobalStyles.ResetStyles /> | ||
{children} | ||
</ThemeProvider> | ||
</DarkMode> | ||
</FathomProvider> | ||
|
||
// prevents ssr flash for mismatched dark mode | ||
if (!mounted) { | ||
return ( | ||
<div style={{ visibility: 'hidden' }}>{body}</div> | ||
) | ||
} | ||
|
||
return body | ||
) | ||
} |
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