@cullsin/lnc-menu 2.0.5 → 3.0.0
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 +1 -0
- package/dist/src/SideMenu.js +2 -0
- package/package.json +4 -2
- package/src/SideMenu.tsx +162 -0
- package/src/sidemenu.scss +119 -0
package/dist/src/SideMenu.d.ts
CHANGED
package/dist/src/SideMenu.js
CHANGED
|
@@ -13,6 +13,7 @@ import DashboardOutlinedIcon from "@mui/icons-material/DashboardOutlined";
|
|
|
13
13
|
import RecentActorsOutlinedIcon from "@mui/icons-material/RecentActorsOutlined";
|
|
14
14
|
import ArticleOutlinedIcon from "@mui/icons-material/ArticleOutlined";
|
|
15
15
|
import Tooltip from "@mui/material/Tooltip";
|
|
16
|
+
import './sidemenu.scss';
|
|
16
17
|
function SideMenu({ useDrawer, SampleMgmtIcon, navigate }) {
|
|
17
18
|
const [selectedMainMenu, setSelectedMainMenu] = React.useState(null); // Track selected main menu
|
|
18
19
|
const { isDrawerOpen, toggleDrawer } = useDrawer();
|
|
@@ -30,6 +31,7 @@ function SideMenu({ useDrawer, SampleMgmtIcon, navigate }) {
|
|
|
30
31
|
toggleDrawer();
|
|
31
32
|
}
|
|
32
33
|
console.log('redirecting', path);
|
|
34
|
+
console.log(navigate);
|
|
33
35
|
navigate(path);
|
|
34
36
|
};
|
|
35
37
|
const menuItems = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cullsin/lnc-menu",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Reusable SideMenu component for MedGenome LNC platform using MUI and React Router",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
-
"dist"
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"src/sidemenu.scss"
|
|
17
19
|
],
|
|
18
20
|
"scripts": {
|
|
19
21
|
"build": "tsc"
|
package/src/SideMenu.tsx
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import AppBar from "@mui/material/AppBar";
|
|
3
|
+
import Box from "@mui/material/Box";
|
|
4
|
+
import Drawer from "@mui/material/Drawer";
|
|
5
|
+
import List from "@mui/material/List";
|
|
6
|
+
import ListItem from "@mui/material/ListItem";
|
|
7
|
+
import ListItemIcon from "@mui/material/ListItemIcon";
|
|
8
|
+
import ListItemText from "@mui/material/ListItemText";
|
|
9
|
+
import Menu from "@mui/material/Menu";
|
|
10
|
+
import MenuItem from "@mui/material/MenuItem";
|
|
11
|
+
import DashboardOutlinedIcon from "@mui/icons-material/DashboardOutlined";
|
|
12
|
+
import RecentActorsOutlinedIcon from "@mui/icons-material/RecentActorsOutlined";
|
|
13
|
+
import ArticleOutlinedIcon from "@mui/icons-material/ArticleOutlined";
|
|
14
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
15
|
+
import { NavigateFunction } from "react-router-dom";
|
|
16
|
+
import './sidemenu.scss';
|
|
17
|
+
|
|
18
|
+
interface MenuItemType {
|
|
19
|
+
text: string;
|
|
20
|
+
icon: React.ReactNode;
|
|
21
|
+
subMenu?: { text: string; path: string }[]; // 'onClick' optional and add 'path'
|
|
22
|
+
onClick?: () => void; // 'onClick' optional as subMenu items will use 'path'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface SideMenuProps {
|
|
26
|
+
useDrawer: () => { isDrawerOpen: boolean; toggleDrawer: () => void };
|
|
27
|
+
SampleMgmtIcon: React.ElementType;
|
|
28
|
+
navigate: NavigateFunction
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function SideMenu({ useDrawer, SampleMgmtIcon, navigate }: SideMenuProps) {
|
|
32
|
+
const [selectedMainMenu, setSelectedMainMenu] = React.useState<string | null>(
|
|
33
|
+
null
|
|
34
|
+
); // Track selected main menu
|
|
35
|
+
const { isDrawerOpen, toggleDrawer } = useDrawer();
|
|
36
|
+
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
|
37
|
+
|
|
38
|
+
const handleMenuOpen = (
|
|
39
|
+
event: React.MouseEvent<HTMLElement>,
|
|
40
|
+
index: number
|
|
41
|
+
) => {
|
|
42
|
+
setAnchorEl(event.currentTarget);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const handleMenuClose = () => {
|
|
46
|
+
setAnchorEl(null);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleSubMenuItemClick = (path: string, parentText: string) => {
|
|
50
|
+
setSelectedMainMenu(parentText); // Set the main menu selected when a submenu item is clicked
|
|
51
|
+
handleMenuClose();
|
|
52
|
+
if (isDrawerOpen) {
|
|
53
|
+
toggleDrawer();
|
|
54
|
+
}
|
|
55
|
+
console.log('redirecting', path);
|
|
56
|
+
console.log(navigate);
|
|
57
|
+
navigate(path);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const menuItems: MenuItemType[] = [
|
|
61
|
+
{ text: "Dashboard", icon: <DashboardOutlinedIcon /> },
|
|
62
|
+
{
|
|
63
|
+
text: "Patient Management",
|
|
64
|
+
icon: <RecentActorsOutlinedIcon />,
|
|
65
|
+
subMenu: [
|
|
66
|
+
{ text: "Patient", path: "/patient/patient-listing" },
|
|
67
|
+
{ text: "Family", path: "/patient/family-listing" },
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
{ text: "Sample Management", icon: <SampleMgmtIcon /> },
|
|
71
|
+
{ text: "Reports", icon: <ArticleOutlinedIcon /> },
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<Box sx={{ flexGrow: 1 }}>
|
|
76
|
+
<AppBar sx={{ position: "fixed", top: 0 }} />
|
|
77
|
+
<Drawer
|
|
78
|
+
open={isDrawerOpen}
|
|
79
|
+
variant="permanent"
|
|
80
|
+
className="parent-container"
|
|
81
|
+
sx={{
|
|
82
|
+
width: isDrawerOpen ? 230 : 64,
|
|
83
|
+
flexShrink: 0,
|
|
84
|
+
"& .MuiDrawer-paper": {
|
|
85
|
+
width: isDrawerOpen ? 230 : 64,
|
|
86
|
+
transition: "width 0.3s ease",
|
|
87
|
+
top: "64px",
|
|
88
|
+
bottom: "0",
|
|
89
|
+
borderRight: "1px solid #B1BECB",
|
|
90
|
+
},
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
<List>
|
|
94
|
+
{menuItems.map((item, index) => (
|
|
95
|
+
<React.Fragment key={index}>
|
|
96
|
+
<Tooltip
|
|
97
|
+
title={item.text}
|
|
98
|
+
arrow
|
|
99
|
+
placement="bottom"
|
|
100
|
+
disableHoverListener={isDrawerOpen}
|
|
101
|
+
>
|
|
102
|
+
<ListItem
|
|
103
|
+
button
|
|
104
|
+
selected={selectedMainMenu === item.text} // Highlight the main menu item
|
|
105
|
+
className={selectedMainMenu === item.text ? "selected" : ""}
|
|
106
|
+
onClick={(event) => {
|
|
107
|
+
if (item.subMenu) {
|
|
108
|
+
handleMenuOpen(event, index);
|
|
109
|
+
setSelectedMainMenu(item.text); // Set selected when main menu is clicked
|
|
110
|
+
} else if (item.onClick) {
|
|
111
|
+
item.onClick();
|
|
112
|
+
setSelectedMainMenu(item.text); // Set selected when a menu is clicked
|
|
113
|
+
}
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
<ListItemIcon>{item.icon}</ListItemIcon>
|
|
117
|
+
{isDrawerOpen && <ListItemText primary={item.text} />}
|
|
118
|
+
</ListItem>
|
|
119
|
+
</Tooltip>
|
|
120
|
+
{item.subMenu && anchorEl && (
|
|
121
|
+
<Menu
|
|
122
|
+
anchorEl={anchorEl}
|
|
123
|
+
open={Boolean(anchorEl)}
|
|
124
|
+
onClose={handleMenuClose}
|
|
125
|
+
anchorOrigin={{
|
|
126
|
+
vertical: "top",
|
|
127
|
+
horizontal: "left",
|
|
128
|
+
}}
|
|
129
|
+
transformOrigin={{
|
|
130
|
+
vertical: "top",
|
|
131
|
+
horizontal: "left",
|
|
132
|
+
}}
|
|
133
|
+
PaperProps={{
|
|
134
|
+
style: {
|
|
135
|
+
marginLeft: isDrawerOpen ? 230 : 65,
|
|
136
|
+
},
|
|
137
|
+
}}
|
|
138
|
+
>
|
|
139
|
+
<span className="submenu-title">
|
|
140
|
+
{!isDrawerOpen ? item.text : ""}
|
|
141
|
+
</span>
|
|
142
|
+
{item.subMenu.map((subItem) => (
|
|
143
|
+
<MenuItem
|
|
144
|
+
key={subItem.text}
|
|
145
|
+
onClick={() =>
|
|
146
|
+
handleSubMenuItemClick(subItem.path, item.text)
|
|
147
|
+
}
|
|
148
|
+
>
|
|
149
|
+
{subItem.text}
|
|
150
|
+
</MenuItem>
|
|
151
|
+
))}
|
|
152
|
+
</Menu>
|
|
153
|
+
)}
|
|
154
|
+
</React.Fragment>
|
|
155
|
+
))}
|
|
156
|
+
</List>
|
|
157
|
+
</Drawer>
|
|
158
|
+
</Box>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export default SideMenu;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
//overwritten the default MUI css
|
|
2
|
+
|
|
3
|
+
.MuiBox-root .MuiList-root {
|
|
4
|
+
background: linear-gradient(to bottom, #1e2f97, #0b1659) !important;
|
|
5
|
+
color: #fff;
|
|
6
|
+
height: 100%;
|
|
7
|
+
bottom: 0; // Ensure drawer stretches till bottom
|
|
8
|
+
padding: 20px 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.MuiList-root {
|
|
12
|
+
&.MuiMenu-list {
|
|
13
|
+
background: linear-gradient(to bottom, #586d81, #3e4f60) !important;
|
|
14
|
+
color: #fff;
|
|
15
|
+
width: 175px;
|
|
16
|
+
padding: 10px;
|
|
17
|
+
position: relative;
|
|
18
|
+
overflow: visible;
|
|
19
|
+
|
|
20
|
+
.submenu-title {
|
|
21
|
+
text-transform: uppercase;
|
|
22
|
+
font: 12px / 18px "OpenSans-Regular";
|
|
23
|
+
color: #efffff;
|
|
24
|
+
padding: 0 0 5px 10px;
|
|
25
|
+
display: block;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.MuiMenuItem-root {
|
|
29
|
+
&.Mui-focusVisible {
|
|
30
|
+
background-color: transparent;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&:hover {
|
|
34
|
+
font: 16px/24px "OpenSans-SemiBold";
|
|
35
|
+
background: #374451;
|
|
36
|
+
border-radius: 6px;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.MuiListItem-root {
|
|
42
|
+
padding: 15px;
|
|
43
|
+
&.selected {
|
|
44
|
+
padding: 7px;
|
|
45
|
+
|
|
46
|
+
.MuiListItemIcon-root {
|
|
47
|
+
background: linear-gradient(to bottom, #7ad4f7, #20a9ef) !important;
|
|
48
|
+
color: #1e2f97;
|
|
49
|
+
padding: 10px;
|
|
50
|
+
min-width: 25px;
|
|
51
|
+
border-top-left-radius: 5px;
|
|
52
|
+
border-bottom-left-radius: 5px;
|
|
53
|
+
|
|
54
|
+
&:only-of-type {
|
|
55
|
+
border-top-right-radius: 5px;
|
|
56
|
+
border-bottom-right-radius: 5px;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.MuiListItemText-root {
|
|
61
|
+
span {
|
|
62
|
+
background: linear-gradient(to bottom, #7ad4f7, #20a9ef) !important;
|
|
63
|
+
color: #1e2f97;
|
|
64
|
+
padding: 10px 0;
|
|
65
|
+
min-width: 25px;
|
|
66
|
+
border-top-right-radius: 5px;
|
|
67
|
+
border-bottom-right-radius: 5px;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.MuiListItemIcon-root {
|
|
73
|
+
color: #fff;
|
|
74
|
+
min-width: 30px;
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.MuiListItemText-root {
|
|
79
|
+
margin-top: 0;
|
|
80
|
+
margin-bottom: 0;
|
|
81
|
+
.MuiTypography-root {
|
|
82
|
+
font: 14px/24px "OpenSans-SemiBold";
|
|
83
|
+
color: #fff;
|
|
84
|
+
cursor: pointer;
|
|
85
|
+
white-space: nowrap;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
ul.MuiList-root {
|
|
92
|
+
&:has(.submenu-title) {
|
|
93
|
+
&::before {
|
|
94
|
+
content: "";
|
|
95
|
+
position: absolute;
|
|
96
|
+
top: 15px;
|
|
97
|
+
left: -8px;
|
|
98
|
+
width: 0;
|
|
99
|
+
height: 0;
|
|
100
|
+
border-top: 8px solid transparent;
|
|
101
|
+
border-bottom: 8px solid transparent;
|
|
102
|
+
border-right: 8px solid #516578;
|
|
103
|
+
z-index: 2;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.MuiPopover-root {
|
|
109
|
+
.MuiPaper-root {
|
|
110
|
+
overflow: visible;
|
|
111
|
+
position: relative;
|
|
112
|
+
width: max-content;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.MuiList-root.MuiMenu-list {
|
|
117
|
+
border-radius: 5px;
|
|
118
|
+
}
|
|
119
|
+
|