diff --git a/src/components/Navbar/Navbar.js b/src/components/Navbar/Navbar.js index af7f79f25..b0289fdc3 100644 --- a/src/components/Navbar/Navbar.js +++ b/src/components/Navbar/Navbar.js @@ -9,15 +9,69 @@ import { FaUser, FaFolderOpen } from 'react-icons/fa'; import { makeStyles } from '@material-ui/core/styles'; import Drawer from '@material-ui/core/Drawer'; import CloseIcon from '@material-ui/icons/Close'; +import BrightnessHighIcon from '@material-ui/icons/BrightnessHigh'; +import Brightness4Icon from '@material-ui/icons/Brightness4'; import './Navbar.css'; import { headerData } from '../../data/headerData'; import { ThemeContext } from '../../contexts/ThemeContext'; +import { useEffect } from 'react'; +import { + greenThemeLight, + greenThemeDark, + bwThemeLight, + bwThemeDark, + blueThemeLight, + blueThemeDark, + redThemeLight, + redThemeDark, + orangeThemeLight, + orangeThemeDark, + purpleThemeLight, + purpleThemeDark, + pinkThemeLight, + pinkThemeDark, + yellowThemeLight, + yellowThemeDark, +} from '../../theme/theme'; +import { Menu, MenuItem, IconButton } from '@material-ui/core'; -function Navbar() { - const { theme, setHandleDrawer } = useContext(ThemeContext); +const type = { + light: { + greenThemeLight, + bwThemeLight, + blueThemeLight, + redThemeLight, + orangeThemeLight, + purpleThemeLight, + pinkThemeLight, + yellowThemeLight, + }, + dark: { + greenThemeDark, + bwThemeDark, + blueThemeDark, + redThemeDark, + orangeThemeDark, + purpleThemeDark, + pinkThemeDark, + yellowThemeDark, + }, +}; +function Navbar() { const [open, setOpen] = useState(false); + const { theme, setHandleDrawer, setTheme, themeType, setThemeType } = useContext(ThemeContext); + const [themes, setThemes] = useState(type[themeType]); + const [anchorEl, setAnchorEl] = React.useState(null); + + const handleClick = (event) => { + setAnchorEl(event.currentTarget); + }; + + const handleClose = () => { + setAnchorEl(null); + }; const handleDrawerOpen = () => { setOpen(true); @@ -29,6 +83,23 @@ function Navbar() { setHandleDrawer(); }; + const handleSetTheme = (theme, e) => { + setTheme(themes[theme]); + handleClick(e); + }; + + useEffect(() => { + if (themeType === 'dark') { + setThemes(type['dark']); + const find = Object.keys(type.dark).filter((item) => type.dark[item].primary === theme.primary); + setTheme(type.dark[find]); + } else { + setThemes(type['light']); + const find = Object.keys(type.light).filter((item) => type.light[item].primary === theme.primary); + setTheme(type.light[find]); + } + }, [themeType]); + const useStyles = makeStyles((t) => ({ navMenu: { fontSize: '2.5rem', @@ -118,6 +189,20 @@ function Navbar() { fontSize: '1.385rem', }, }, + toggleThemeIconButton: { + height: '30px', + width: '30px', + borderRadius: '50%', + transform: 'translateY(-10px)', + marginRight: 10, + overflow: 'hidden', + backgroundColor: theme.primary, + border: `2px solid ${themeType === 'light' ? 'black' : 'white'}`, + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + padding: 0, + }, })); const classes = useStyles(); @@ -133,15 +218,52 @@ function Navbar() { return (