From e5f70c3891a4a80017a372a10d3176d182341b4f Mon Sep 17 00:00:00 2001 From: Nitheesh T Ganesh Date: Tue, 6 Aug 2024 16:59:08 -0600 Subject: [PATCH] Show menu drawer on app menu hover when its on collapsed state --- .../src/components/Shared/CopyButton.tsx | 4 +- .../Shared/SideNav/MenuItemIconsList.tsx | 79 ++++++++++++------- .../components/Shared/SideNav/SideNavBar.tsx | 3 +- compliance-web/src/routes/__root.tsx | 13 +-- compliance-web/src/store/menuStore.tsx | 8 ++ compliance-web/src/utils/constants.ts | 3 + 6 files changed, 73 insertions(+), 37 deletions(-) diff --git a/compliance-web/src/components/Shared/CopyButton.tsx b/compliance-web/src/components/Shared/CopyButton.tsx index 05fbbae3..057c9e8e 100644 --- a/compliance-web/src/components/Shared/CopyButton.tsx +++ b/compliance-web/src/components/Shared/CopyButton.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import { useState } from "react"; import { IconButton } from "@mui/material"; import { FileCopy, FileCopyOutlined } from "@mui/icons-material"; import { BCPalette } from "epic.theme"; @@ -13,7 +13,7 @@ const CopyButton = ({ ...props }) => { navigator.clipboard.writeText(text); }; - const [hover, setHover] = React.useState(false); + const [hover, setHover] = useState(false); return ( (false); const renderMenuIcons = () => { - return routeMenuItems.map((route) => { - return ( - - toggleMenu(route.routeName)} - disablePadding - sx={{ cursor: "pointer" }} - > - - {route.icon ?? route.icon} - - - - ); - }); + return routeMenuItems.map((route) => ( + setHoverMenu(true)} + disablePadding + sx={{ cursor: "pointer" }} + > + + {route.icon ?? route.icon} + + + )); }; - return {renderMenuIcons()}; + return ( + <> + {renderMenuIcons()} + setHoverMenu(false)} + sx={{ + flexShrink: 0, + [`& .MuiDrawer-paper`]: { + width: APP_SIDE_NAV_WIDTH, + boxSizing: "border-box", + background: theme.palette.primary.main, + height: `calc(100vh - ${appHeaderHeight}px)`, + top: appHeaderHeight, + }, + }} + > + + + + ); } diff --git a/compliance-web/src/components/Shared/SideNav/SideNavBar.tsx b/compliance-web/src/components/Shared/SideNav/SideNavBar.tsx index 0d8f9760..f81793ea 100644 --- a/compliance-web/src/components/Shared/SideNav/SideNavBar.tsx +++ b/compliance-web/src/components/Shared/SideNav/SideNavBar.tsx @@ -5,6 +5,7 @@ import ExpandMenuButton from "./ExpandMenuButton"; import MenuItemsList from "./MenuItemsList"; import { AppConfig } from "@/utils/config"; import MenuItemIconsList from "./MenuItemIconsList"; +import { APP_SIDE_NAV_WIDTH, APP_SIDE_NAV_WIDTH_COLLAPSED } from "@/utils/constants"; export default function SideNavBar() { const { expandMenu } = useMenuStore(); @@ -16,7 +17,7 @@ export default function SideNavBar() { ()({ }); function Layout() { - const [headerHeight, setHeaderHeight] = useState(0); + const { appHeaderHeight, setAppHeaderHeight } = + useMenuStore(); + const appBarRef = useRef(null); useEffect(() => { if (appBarRef.current) { - setHeaderHeight(appBarRef.current.offsetHeight); + setAppHeaderHeight(appBarRef.current.offsetHeight); } - }, []); + }, [setAppHeaderHeight]); return ( <> @@ -33,7 +36,7 @@ function Layout() { sx={{ display: "flex", overflow: "hidden", - height: `calc(100vh - ${headerHeight}px)`, + height: `calc(100vh - ${appHeaderHeight}px)`, }} > diff --git a/compliance-web/src/store/menuStore.tsx b/compliance-web/src/store/menuStore.tsx index ff22f9f3..f8eb7219 100644 --- a/compliance-web/src/store/menuStore.tsx +++ b/compliance-web/src/store/menuStore.tsx @@ -4,8 +4,10 @@ import { persist } from "zustand/middleware"; interface MenuState { openMenus: { [key: string]: boolean }; expandMenu: boolean; + appHeaderHeight: number; toggleMenu: (routeName: string) => void; toggleExpandMenu: () => void; + setAppHeaderHeight: (height: number) => void; } export const useMenuStore = create()( @@ -13,6 +15,7 @@ export const useMenuStore = create()( (set) => ({ openMenus: {}, expandMenu: true, + appHeaderHeight: 0, toggleMenu: (routeName: string) => { set((state) => ({ openMenus: { @@ -26,6 +29,11 @@ export const useMenuStore = create()( expandMenu: !state.expandMenu, })); }, + setAppHeaderHeight: (height: number) => { + set(() => ({ + appHeaderHeight: height, + })); + } }), { name: "menu-storage", // name of the item in the storage diff --git a/compliance-web/src/utils/constants.ts b/compliance-web/src/utils/constants.ts index 8350dcb2..b69abaaf 100644 --- a/compliance-web/src/utils/constants.ts +++ b/compliance-web/src/utils/constants.ts @@ -1 +1,4 @@ // App Constants should go here + +export const APP_SIDE_NAV_WIDTH = 260; +export const APP_SIDE_NAV_WIDTH_COLLAPSED = 68;