From bc878c85ae53e5c2b8a29bd77f28a68384f9682b Mon Sep 17 00:00:00 2001 From: Amit Amrutiya Date: Wed, 23 Oct 2024 15:09:32 +0530 Subject: [PATCH] feat: make navigation navbar more generic to use Signed-off-by: Amit Amrutiya --- .../NavigationNavbar/navigationNavbar.tsx | 98 ++++++++++--------- src/custom/NavigationNavbar/style.tsx | 7 +- 2 files changed, 56 insertions(+), 49 deletions(-) diff --git a/src/custom/NavigationNavbar/navigationNavbar.tsx b/src/custom/NavigationNavbar/navigationNavbar.tsx index 6d5f83df..2ae99e7f 100644 --- a/src/custom/NavigationNavbar/navigationNavbar.tsx +++ b/src/custom/NavigationNavbar/navigationNavbar.tsx @@ -1,5 +1,6 @@ import ExpandLessIcon from '@mui/icons-material/ExpandLess'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; +import { ListItemTextProps, MenuListProps } from '@mui/material'; import React, { MouseEvent, useState } from 'react'; import { Collapse, Divider, ListItemText, MenuItem } from '../../base'; import { IconWrapper, MenuItemList, MenuItemSubList, MenuListStyle, SubIconWrapper } from './style'; @@ -14,13 +15,18 @@ type NavigationItem = { addDivider?: boolean; }; -type NavigationNavbarProps = { +interface NavigationNavbarProps { navigationItems: NavigationItem[]; -}; + MenuListProps?: Omit; + ListItemTextProps?: Omit; +} -const NavigationNavbar: React.FC = ({ navigationItems }) => { +const NavigationNavbar: React.FC = ({ + navigationItems, + MenuListProps = {}, + ListItemTextProps = {} +}) => { const [openSectionId, setOpenSectionId] = useState(null); - const toggleSectionOpen = (sectionId: string, event: MouseEvent) => { event.stopPropagation(); setOpenSectionId((currentOpenSectionId) => @@ -28,50 +34,52 @@ const NavigationNavbar: React.FC = ({ navigationItems }) ); }; - const NavigationNavbarItems = () => { - return navigationItems.map((item) => { - const isOpen = openSectionId === item.id; - const permission = item.permission ?? true; - const addDivider = item.addDivider ?? false; + return ( + + {navigationItems.map((item) => { + const isOpen = openSectionId === item.id; + const permission = item.permission ?? true; + const addDivider = item.addDivider ?? false; - return ( - - - - {item.icon} - - + return ( + + + + {item.icon && {item.icon}} + + + {item.subItems && ( + + {isOpen ? ( + toggleSectionOpen(item.id, e)} /> + ) : ( + toggleSectionOpen(item.id, e)} /> + )} + + )} + {item.subItems && ( - - {isOpen ? ( - toggleSectionOpen(item.id, e)} /> - ) : ( - toggleSectionOpen(item.id, e)} /> - )} - + + {item.subItems.map((subItem) => ( + + + {subItem.icon && {subItem.icon}} + + + + ))} + )} - - - {item.subItems && ( - - {item.subItems.map((subItem) => ( - - - {subItem.icon} - - - - ))} - - )} - - {addDivider && } - - ); - }); - }; - - return {NavigationNavbarItems()}; + {addDivider && } + + ); + })} + + ); }; export default NavigationNavbar; diff --git a/src/custom/NavigationNavbar/style.tsx b/src/custom/NavigationNavbar/style.tsx index d6cd54f1..c7f0f699 100644 --- a/src/custom/NavigationNavbar/style.tsx +++ b/src/custom/NavigationNavbar/style.tsx @@ -7,8 +7,6 @@ export const ListItemStyle = styled('div')(({ theme }) => ({ })); export const MenuListStyle = styled(MenuList)({ - minHeight: '31rem', - width: '13rem', overflowY: 'auto', scrollbarWidth: 'none', '&::-webkit-scrollbar': { @@ -18,7 +16,7 @@ export const MenuListStyle = styled(MenuList)({ export const MenuItemList = styled(ListItem)(() => ({ pointerEvents: 'auto', - margin: '0.5rem 0rem 0.5rem 0.5rem', + margin: '0.5rem 0rem 0.5rem 0rem', fontSize: '0.1rem', padding: '0' })); @@ -30,7 +28,8 @@ export const MenuItemSubList = styled(ListItem)(() => ({ })); export const IconWrapper = styled('div')({ - marginRight: '0.75rem' + marginRight: '0.75rem', + marginLeft: '0.5rem' }); export const SubIconWrapper = styled('div')({