From a28caa38cd78460feb13cdb1442dcb84b2abf6b2 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Mon, 19 Aug 2024 14:01:26 -0400 Subject: [PATCH] Added nested button menu popup --- Client/src/Components/Sidebar/index.css | 32 +++++++++- Client/src/Components/Sidebar/index.jsx | 79 +++++++++++++++++++++---- 2 files changed, 99 insertions(+), 12 deletions(-) diff --git a/Client/src/Components/Sidebar/index.css b/Client/src/Components/Sidebar/index.css index d41778624..68e1988b0 100644 --- a/Client/src/Components/Sidebar/index.css +++ b/Client/src/Components/Sidebar/index.css @@ -1,4 +1,5 @@ aside .selected-path, +.sidebar-popup .selected-path, aside .MuiListItemButton-root:hover { background-color: var(--env-var-color-13); } @@ -88,4 +89,33 @@ aside { } aside .MuiList-root { transition: padding 100ms ease; -} \ No newline at end of file +} + +.sidebar-popup .MuiPaper-root { + box-shadow: var(--env-var-shadow-1); + border: solid 1px var(--env-var-color-6); + border-radius: var(--env-var-radius-1); + gap: 1px; +} +.sidebar-popup .MuiList-root { + padding: 6px 8px; + min-width: 100px; +} +.sidebar-popup li.MuiButtonBase-root { + font-size: var(--env-var-font-size-medium); + color: var(--env-var-color-5); + padding: 5px 8px; + border-radius: var(--env-var-radius-1); +} +.sidebar-popup li.MuiButtonBase-root:hover{ + background-color: var(--env-var-color-13); +} +.sidebar-popup .MuiModal-root p.MuiTypography-root { + font-size: var(--env-var-font-size-medium); + color: var(--env-var-color-2); +} +.sidebar-popup svg{ + width: 16px; + height: 16px; + opacity: 0.9; +} diff --git a/Client/src/Components/Sidebar/index.jsx b/Client/src/Components/Sidebar/index.jsx index 74e868aa8..dd7d07bd7 100644 --- a/Client/src/Components/Sidebar/index.jsx +++ b/Client/src/Components/Sidebar/index.jsx @@ -9,6 +9,8 @@ import { ListItemIcon, ListItemText, ListSubheader, + Menu, + MenuItem, Stack, Tooltip, Typography, @@ -85,6 +87,16 @@ function Sidebar() { const authState = useSelector((state) => state.auth); const [open, setOpen] = useState({ Dashboard: false, Account: false }); const [collapsed, setCollapsed] = useState(false); + const [anchorEl, setAnchorEl] = useState(null); + const [popup, setPopup] = useState(); + + const openPopup = (event, id) => { + setAnchorEl(event.currentTarget); + setPopup(id); + }; + const closePopup = () => { + setAnchorEl(null); + }; /** * Handles logging out the user @@ -183,17 +195,62 @@ function Sidebar() { {!collapsed && {item.name}} ) : collapsed ? ( - - {item.icon} - {!collapsed && {item.name}} - + + openPopup(event, item.name)} + sx={{ + position: "relative", + gap: theme.gap.medium, + borderRadius: `${theme.shape.borderRadius}px`, + justifyContent: collapsed ? "center" : "flex-start", + }} + > + {item.icon} + {!collapsed && {item.name}} + + + {item.nested.map((child) => { + if ( + child.name === "Team" && + authState.user?.role && + !authState.user.role.includes("admin") + ) { + return null; + } + + return ( + navigate(`/${child.path}`)} + sx={{ + gap: theme.gap.small, + borderRadius: `${theme.shape.borderRadius}px`, + pl: theme.gap.small, + }} + > + {child.icon} + {child.name} + + ); + })} + + ) : (