-
Notifications
You must be signed in to change notification settings - Fork 46
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
06074f0
commit 585b929
Showing
13 changed files
with
276 additions
and
40 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,21 @@ | ||
import React from "react"; | ||
import Toggle from "./Toggle"; | ||
import useDarkMode from "use-dark-mode"; | ||
|
||
const DarkModeToggle = () => { | ||
const darkMode = useDarkMode(false); | ||
|
||
return ( | ||
<div className="dark-mode-toggle"> | ||
<button type="button" onClick={darkMode.disable}> | ||
☀ | ||
</button> | ||
<Toggle checked={darkMode.value} onChange={darkMode.toggle} /> | ||
<button type="button" onClick={darkMode.enable}> | ||
☽ | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DarkModeToggle; |
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,14 @@ | ||
import React from "react"; | ||
import styles from "./Footer.module.css"; | ||
|
||
const footerYear = new Date().getFullYear(); | ||
|
||
const Footer = () => { | ||
return ( | ||
<footer className={styles.footer}> | ||
© Bolaji Ayodeji | 2019 - {footerYear}. | ||
</footer> | ||
); | ||
}; | ||
|
||
export default Footer; |
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,8 @@ | ||
.footer { | ||
width: 100%; | ||
height: 100px; | ||
border-top: 2px solid var(--primaryMainColor); | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} |
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,16 @@ | ||
import React from "react"; | ||
|
||
const Toggle = ({ checked, onChange }) => ( | ||
<span className="toggle-control"> | ||
<input | ||
className="dmcheck" | ||
type="checkbox" | ||
checked={checked} | ||
onChange={onChange} | ||
id="dmcheck" | ||
/> | ||
<label htmlFor="dmcheck" /> | ||
</span> | ||
); | ||
|
||
export default Toggle; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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,40 @@ | ||
// Insert this script in your index.html right after the <body> tag. | ||
// This will help to prevent a flash if dark mode is the default. | ||
|
||
(function() { | ||
// Change these if you use something different in your hook. | ||
var storageKey = 'darkMode'; | ||
var classNameDark = 'dark-mode'; | ||
var classNameLight = 'light-mode'; | ||
|
||
function setClassOnDocumentBody(darkMode) { | ||
document.body.classList.add(darkMode ? classNameDark : classNameLight); | ||
document.body.classList.remove(darkMode ? classNameLight : classNameDark); | ||
} | ||
|
||
var preferDarkQuery = '(prefers-color-scheme: dark)'; | ||
var mql = window.matchMedia(preferDarkQuery); | ||
var supportsColorSchemeQuery = mql.media === preferDarkQuery; | ||
var localStorageTheme = null; | ||
try { | ||
localStorageTheme = localStorage.getItem(storageKey); | ||
} catch (err) {} | ||
var localStorageExists = localStorageTheme !== null; | ||
if (localStorageExists) { | ||
localStorageTheme = JSON.parse(localStorageTheme); | ||
} | ||
|
||
// Determine the source of truth | ||
if (localStorageExists) { | ||
// source of truth from localStorage | ||
setClassOnDocumentBody(localStorageTheme); | ||
} else if (supportsColorSchemeQuery) { | ||
// source of truth from system | ||
setClassOnDocumentBody(mql.matches); | ||
localStorage.setItem(storageKey, mql.matches); | ||
} else { | ||
// source of truth from document.body | ||
var isDarkMode = document.body.classList.contains(classNameDark); | ||
localStorage.setItem(storageKey, JSON.stringify(isDarkMode)); | ||
} | ||
})(); |
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
Oops, something went wrong.