-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Showing
5 changed files
with
103 additions
and
42 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 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 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,26 @@ | ||
import { useCallback, useState } from 'react' | ||
|
||
const preference = | ||
typeof window !== 'undefined' && | ||
window.matchMedia && | ||
window.matchMedia('(prefers-color-scheme: dark)').matches | ||
? 'dark' | ||
: 'light' | ||
|
||
const saved = | ||
typeof window !== 'undefined' && window.localStorage.getItem('theme') | ||
|
||
export const useDarkMode = () => { | ||
const [theme, setTheme] = useState(saved ? saved : preference) | ||
|
||
const themeToggler = useCallback(() => { | ||
setTheme(theme => { | ||
const newTheme = theme === 'light' ? 'dark' : 'light' | ||
typeof window !== 'undefined' && | ||
window.localStorage.setItem('theme', newTheme) | ||
return newTheme | ||
}) | ||
}, []) | ||
|
||
return [theme, themeToggler] | ||
} |
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,16 +1,48 @@ | ||
import React from 'react' | ||
import { ThemeProvider } from 'styled-components' | ||
import { useDarkMode } from '../helpers/use-dark-mode' | ||
import AppStyles, { GlobalStyle } from '../helpers/styles' | ||
import Nav from '../components/Nav' | ||
|
||
const App = ({ Component, pageProps }) => ( | ||
<> | ||
<GlobalStyle /> | ||
<AppStyles> | ||
<Nav /> | ||
<Component {...pageProps} /> | ||
</AppStyles> | ||
<div id="modal-root"></div> | ||
</> | ||
) | ||
const lightTheme = { | ||
variables: ` | ||
--nc-tx-1: rgb(40, 40, 40); | ||
--nc-tx-2: rgb(66, 78, 88); | ||
--nc-lk-1: rgb(155, 77, 202); | ||
--nc-lk-2: rgb(96, 108, 118); | ||
--nc-bg-1: #FFFFFF; | ||
--nc-bg-2: #F8F8F8; | ||
--nc-bg-3: #e8e8e8; | ||
--custom-bk-code: #f0f0f0 | ||
`, | ||
} | ||
|
||
const darkTheme = { | ||
variables: ` | ||
--nc-tx-1: #e8e8e8; | ||
--nc-tx-2: #ccc; | ||
--nc-bg-1: #111111; | ||
--nc-bg-2: #181818; | ||
--nc-bg-3: #3a3a3a; | ||
--nc-lk-1: #99BFFF; | ||
--nc-lk-2: rgb(176, 188, 198); | ||
--custom-bk-code: #ccc; | ||
`, | ||
} | ||
|
||
const App = ({ Component, pageProps }) => { | ||
const [theme, themeToggler] = useDarkMode() | ||
|
||
return ( | ||
<ThemeProvider theme={theme === 'light' ? lightTheme : darkTheme}> | ||
<GlobalStyle /> | ||
<AppStyles> | ||
<Nav themeToggler={themeToggler} /> | ||
<Component {...pageProps} /> | ||
</AppStyles> | ||
<div id="modal-root"></div> | ||
</ThemeProvider> | ||
) | ||
} | ||
|
||
export default App |
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