From 205d3f0117ee21c7a92bc6e30bf586c391a418aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Mur=C3=A7a?= Date: Mon, 4 Jul 2022 21:17:23 -0300 Subject: [PATCH] Refactor MainMenu --- .../{MainMenu.js => MainMenu/index.js} | 52 +++----------- src/components/MainMenu/styles.js | 67 +++++++++++++++++++ 2 files changed, 78 insertions(+), 41 deletions(-) rename src/components/{MainMenu.js => MainMenu/index.js} (65%) create mode 100644 src/components/MainMenu/styles.js diff --git a/src/components/MainMenu.js b/src/components/MainMenu/index.js similarity index 65% rename from src/components/MainMenu.js rename to src/components/MainMenu/index.js index 33540a9..b6ac820 100644 --- a/src/components/MainMenu.js +++ b/src/components/MainMenu/index.js @@ -1,3 +1,4 @@ +import { useState } from 'react'; import { BottomNavigation, BottomNavigationAction, @@ -10,11 +11,12 @@ import { ListItemText, Toolbar, } from '@mui/material'; -import { useState } from 'react'; import { NavLink, useNavigate } from 'react-router-dom'; -import logoImage from '../assets/if-salas-logo.svg'; +import logoImage from '../../assets/if-salas-logo.svg'; +import styles from './styles'; function MainMenu({ options, layoutType }) { + const { menuContainer, navigator, item, itemIcon } = styles[layoutType]; const navigate = useNavigate(); const [selectedOption, setSelectedOption] = useState( options.find(option => option.isActive) @@ -22,16 +24,16 @@ function MainMenu({ options, layoutType }) { if (layoutType === 'desktop') { return ( - - + + Logotipo {options.map(option => ( - + - + {option.unselectedIcon} @@ -44,18 +46,20 @@ function MainMenu({ options, layoutType }) { ); } else if (layoutType === 'mobile') { return ( - + { const newOption = options.find(option => option.id === newValue); setSelectedOption(newOption); navigate(newOption.pathname, { replace: true }); }} + sx={navigator} showLabels value={selectedOption.id} > {options.map(option => ( a': { - width: drawerWidth, - textDecoration: 'none', - color: 'white', - height: 'inherit', - }, - '.Mui-selected': { - backgroundColor: '#003708', - borderLeft: '4px solid #ffffff', - }, -}; - -const listItemIcon = { - color: 'white', -}; - export default MainMenu; diff --git a/src/components/MainMenu/styles.js b/src/components/MainMenu/styles.js new file mode 100644 index 0000000..5ba666e --- /dev/null +++ b/src/components/MainMenu/styles.js @@ -0,0 +1,67 @@ +// ========== Desktop ========== +const drawerWidth = 230; +const desktopMenuContainer = { + width: drawerWidth, + flexShrink: 0, + '& .MuiDrawer-paper': { + width: drawerWidth, + boxSizing: 'border-box', + backgroundColor: 'secondary.main', + }, +}; + +const desktopToolbar = { + display: 'flex', + justifyContent: 'center', + padding: '20px 0', +}; + +const desktopListItem = { + '> a': { + width: drawerWidth, + textDecoration: 'none', + color: 'white', + height: 'inherit', + }, + '.Mui-selected': { + backgroundColor: '#003708', + borderLeft: '4px solid #ffffff', + }, +}; + +const desktopListItemIcon = { + color: 'white', +}; + +const desktop = { + menuContainer: desktopMenuContainer, + navigator: desktopToolbar, + item: desktopListItem, + itemIcon: desktopListItemIcon, +}; + +// ========== Mobile ========== +const mobileMenuContainer = { + width: '100%', + position: 'fixed', + bottom: 0, + zIndex: 2, +}; + +const mobile = { + menuContainer: mobileMenuContainer, + navigator: null, + item: null, + itemIcon: null, +}; + +// ========== Unset ========== +const unset = { + menuContainer: null, + navigator: null, + item: null, + itemIcon: null, +}; + +const styles = { desktop, mobile, unset }; +export default styles;