@cullsin/lnc-menu 3.0.20 → 3.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/SideMenu.d.ts +3 -2
- package/dist/src/SideMenu.js +18 -15
- package/package.json +1 -1
package/dist/src/SideMenu.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { NavigateFunction } from "react-router-dom";
|
|
2
|
+
import { Location, NavigateFunction } from "react-router-dom";
|
|
3
3
|
interface SideMenuProps {
|
|
4
4
|
useDrawer: () => {
|
|
5
5
|
isDrawerOpen: boolean;
|
|
@@ -7,6 +7,7 @@ interface SideMenuProps {
|
|
|
7
7
|
};
|
|
8
8
|
SampleMgmtIcon: React.ElementType;
|
|
9
9
|
navigate: NavigateFunction;
|
|
10
|
+
location: Location;
|
|
10
11
|
}
|
|
11
|
-
declare function SideMenu({ useDrawer, SampleMgmtIcon }: SideMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
declare function SideMenu({ useDrawer, SampleMgmtIcon, location }: SideMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
12
13
|
export default SideMenu;
|
package/dist/src/SideMenu.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import ArticleOutlinedIcon from "@mui/icons-material/ArticleOutlined";
|
|
3
3
|
import DashboardOutlinedIcon from "@mui/icons-material/DashboardOutlined";
|
|
4
4
|
import RecentActorsOutlinedIcon from "@mui/icons-material/RecentActorsOutlined";
|
|
5
|
-
import GroupAddOutlinedIcon from
|
|
5
|
+
import GroupAddOutlinedIcon from "@mui/icons-material/GroupAddOutlined";
|
|
6
6
|
import AppBar from "@mui/material/AppBar";
|
|
7
7
|
import Box from "@mui/material/Box";
|
|
8
8
|
import Drawer from "@mui/material/Drawer";
|
|
@@ -14,14 +14,12 @@ import Menu from "@mui/material/Menu";
|
|
|
14
14
|
import MenuItem from "@mui/material/MenuItem";
|
|
15
15
|
import Tooltip from "@mui/material/Tooltip";
|
|
16
16
|
import * as React from "react";
|
|
17
|
-
|
|
18
|
-
function SideMenu({ useDrawer, SampleMgmtIcon }) {
|
|
17
|
+
function SideMenu({ useDrawer, SampleMgmtIcon, location }) {
|
|
19
18
|
const [selectedMainMenu, setSelectedMainMenu] = React.useState(null);
|
|
20
19
|
const [selectedSubMenuPath, setSelectedSubMenuPath] = React.useState(null);
|
|
21
20
|
const [openMenuIndex, setOpenMenuIndex] = React.useState(null);
|
|
22
21
|
const { isDrawerOpen, toggleDrawer } = useDrawer();
|
|
23
22
|
const [anchorEl, setAnchorEl] = React.useState(null);
|
|
24
|
-
const location = useLocation();
|
|
25
23
|
const menuItems = React.useMemo(() => [
|
|
26
24
|
{
|
|
27
25
|
text: "Home",
|
|
@@ -54,24 +52,29 @@ function SideMenu({ useDrawer, SampleMgmtIcon }) {
|
|
|
54
52
|
path: "/carrier-duo-trio/",
|
|
55
53
|
},
|
|
56
54
|
], [SampleMgmtIcon]);
|
|
57
|
-
//
|
|
55
|
+
// 🔁 Sync selection with current path
|
|
58
56
|
React.useEffect(() => {
|
|
59
57
|
const currentPath = location.pathname;
|
|
60
|
-
|
|
58
|
+
for (const mainItem of menuItems) {
|
|
61
59
|
if (mainItem.subMenu) {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
for (const sub of mainItem.subMenu) {
|
|
61
|
+
if (currentPath.startsWith(sub.path)) {
|
|
62
|
+
setSelectedMainMenu(mainItem.text);
|
|
63
|
+
setSelectedSubMenuPath(sub.path);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
else if (mainItem.path
|
|
68
|
+
else if (mainItem.path && currentPath.startsWith(mainItem.path)) {
|
|
69
69
|
setSelectedMainMenu(mainItem.text);
|
|
70
70
|
setSelectedSubMenuPath(null);
|
|
71
|
+
return;
|
|
71
72
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
}
|
|
74
|
+
setSelectedMainMenu(null);
|
|
75
|
+
setSelectedSubMenuPath(null);
|
|
76
|
+
handleMenuClose();
|
|
77
|
+
}, [location.pathname, menuItems]);
|
|
75
78
|
const handleMenuOpen = (event, index) => {
|
|
76
79
|
setAnchorEl(event.currentTarget);
|
|
77
80
|
setOpenMenuIndex(index);
|
|
@@ -86,7 +89,7 @@ function SideMenu({ useDrawer, SampleMgmtIcon }) {
|
|
|
86
89
|
handleMenuClose();
|
|
87
90
|
if (isDrawerOpen)
|
|
88
91
|
toggleDrawer();
|
|
89
|
-
window.location.href = path;
|
|
92
|
+
window.location.href = path;
|
|
90
93
|
};
|
|
91
94
|
return (_jsxs(Box, { sx: { flexGrow: 1 }, children: [_jsx(AppBar, { sx: { position: "fixed", top: 0 } }), _jsx(Drawer, { open: isDrawerOpen, variant: "permanent", className: "parent-container", sx: {
|
|
92
95
|
width: isDrawerOpen ? 230 : 64,
|