-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(settings): always start the dark mode switch in the correct posit…
…ion (#195)
- Loading branch information
Showing
3 changed files
with
26 additions
and
14 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,23 @@ | ||
import Switch from 'react-switch'; | ||
import useDarkMode from 'use-dark-mode'; | ||
import { appDefaultDarkMode } from '../state'; | ||
import { palette } from '../theme'; | ||
|
||
function DarkModeToggle(): JSX.Element | null { | ||
const darkMode = useDarkMode(appDefaultDarkMode); | ||
|
||
// defer rendering of the toggle until the client has been hydrated | ||
if (typeof window === 'undefined') return null; | ||
|
||
return ( | ||
<Switch | ||
id="dark-mode" | ||
aria-checked={darkMode.value} | ||
checked={darkMode.value} | ||
onChange={darkMode.toggle} | ||
onColor={palette.primary} | ||
/> | ||
); | ||
} | ||
|
||
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
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