-
Notifications
You must be signed in to change notification settings - Fork 844
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 #662 from AllanLimaAngelo/master
Feat: Darkmode
- Loading branch information
Showing
7 changed files
with
112 additions
and
63 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
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 @@ | ||
import React, { createContext, useState, useContext, useMemo } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { createMuiTheme, ThemeProvider as MUIThemeProvider } from "@material-ui/core/styles"; | ||
import { CssBaseline } from "@material-ui/core"; | ||
|
||
const ThemeContext = createContext(); | ||
|
||
export const ThemeProvider = ({ children }) => { | ||
const [darkMode, setDarkMode] = useState(false); | ||
|
||
const toggleTheme = () => { | ||
setDarkMode((prevMode) => !prevMode); | ||
}; | ||
|
||
const theme = useMemo( | ||
() => | ||
createMuiTheme({ | ||
palette: { | ||
type: darkMode ? "dark" : "light", | ||
}, | ||
}), | ||
[darkMode] | ||
); | ||
|
||
const contextValue = useMemo(() => ({ darkMode, toggleTheme }), [darkMode]); | ||
|
||
return ( | ||
<ThemeContext.Provider value={contextValue}> | ||
<MUIThemeProvider theme={theme}> | ||
<CssBaseline /> | ||
{children} | ||
</MUIThemeProvider> | ||
</ThemeContext.Provider> | ||
); | ||
}; | ||
ThemeProvider.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
export const useThemeContext = () => useContext(ThemeContext); |
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
Oops, something went wrong.