generated from Luis/nextjs-python-web-template
[Layout] Modify the Entities to be in a collapsible submenu
- implemented collapsible submenu for Entities
This commit is contained in:
@@ -11,6 +11,7 @@ import Image from "next/image";
|
|||||||
import React, {ReactNode} from "react";
|
import React, {ReactNode} from "react";
|
||||||
|
|
||||||
import {tw} from "@/utils/tailwind";
|
import {tw} from "@/utils/tailwind";
|
||||||
|
import Collapse from '@mui/material/Collapse';
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import ChevronLeftIcon from "@mui/icons-material/ChevronLeft";
|
import ChevronLeftIcon from "@mui/icons-material/ChevronLeft";
|
||||||
import HomeIcon from "@mui/icons-material/Home";
|
import HomeIcon from "@mui/icons-material/Home";
|
||||||
@@ -18,6 +19,8 @@ import HubIcon from "@mui/icons-material/Hub";
|
|||||||
import PersonIcon from "@mui/icons-material/Person";
|
import PersonIcon from "@mui/icons-material/Person";
|
||||||
import RouterIcon from "@mui/icons-material/Router";
|
import RouterIcon from "@mui/icons-material/Router";
|
||||||
import StorageIcon from "@mui/icons-material/Storage";
|
import StorageIcon from "@mui/icons-material/Storage";
|
||||||
|
import ExpandLess from '@mui/icons-material/ExpandLess';
|
||||||
|
import ExpandMore from '@mui/icons-material/ExpandMore';
|
||||||
|
|
||||||
type MenuEntry = {
|
type MenuEntry = {
|
||||||
icon: ReactNode;
|
icon: ReactNode;
|
||||||
@@ -28,6 +31,21 @@ type MenuEntry = {
|
|||||||
subMenuEntries?: MenuEntry[];
|
subMenuEntries?: MenuEntry[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const menuEntityEntries: MenuEntry[] = [
|
||||||
|
{
|
||||||
|
icon: <PersonIcon/>,
|
||||||
|
label: "C1",
|
||||||
|
to: "/client-1",
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: <PersonIcon/>,
|
||||||
|
label: "C2",
|
||||||
|
to: "/client-2",
|
||||||
|
disabled: false,
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
const menuEntries: MenuEntry[] = [
|
const menuEntries: MenuEntry[] = [
|
||||||
{
|
{
|
||||||
icon: <HomeIcon/>,
|
icon: <HomeIcon/>,
|
||||||
@@ -39,18 +57,6 @@ const menuEntries: MenuEntry[] = [
|
|||||||
icon: <HubIcon/>,
|
icon: <HubIcon/>,
|
||||||
label: "Entities",
|
label: "Entities",
|
||||||
to: "/entities",
|
to: "/entities",
|
||||||
disabled: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <PersonIcon />,
|
|
||||||
label: "C1",
|
|
||||||
to: "/client-1",
|
|
||||||
disabled: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <PersonIcon />,
|
|
||||||
label: "C2",
|
|
||||||
to: "/client-2",
|
|
||||||
disabled: false,
|
disabled: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -74,10 +80,15 @@ interface SidebarProps {
|
|||||||
show: boolean;
|
show: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Sidebar(props: SidebarProps) {
|
export function Sidebar(props: SidebarProps) {
|
||||||
const {show, onClose} = props;
|
const {show, onClose} = props;
|
||||||
|
|
||||||
const [activeMenuItem, setActiveMenuItem] = React.useState("/");
|
const [activeMenuItem, setActiveMenuItem] = React.useState("/");
|
||||||
|
const [collapseMenuOpen, setCollapseMenuOpen] = React.useState(true);
|
||||||
|
|
||||||
|
const handleCollapseClick = () => {
|
||||||
|
setCollapseMenuOpen(!collapseMenuOpen);
|
||||||
|
};
|
||||||
|
|
||||||
const handleMenuItemClick = (path: string) => {
|
const handleMenuItemClick = (path: string) => {
|
||||||
setActiveMenuItem(path);
|
setActiveMenuItem(path);
|
||||||
@@ -119,6 +130,7 @@ export function Sidebar(props: SidebarProps) {
|
|||||||
disablePadding
|
disablePadding
|
||||||
className="!overflow-hidden py-2"
|
className="!overflow-hidden py-2"
|
||||||
>
|
>
|
||||||
|
{menuEntry.label !== "Entities" ?
|
||||||
<ListItemButton
|
<ListItemButton
|
||||||
className="justify-center lg:justify-normal"
|
className="justify-center lg:justify-normal"
|
||||||
LinkComponent={Link}
|
LinkComponent={Link}
|
||||||
@@ -141,6 +153,58 @@ export function Sidebar(props: SidebarProps) {
|
|||||||
className="hidden lg:block"
|
className="hidden lg:block"
|
||||||
/>
|
/>
|
||||||
</ListItemButton>
|
</ListItemButton>
|
||||||
|
:
|
||||||
|
<div>
|
||||||
|
<ListItemButton
|
||||||
|
className="justify-center lg:justify-normal"
|
||||||
|
disabled={menuEntry.disabled}
|
||||||
|
selected={activeMenuItem === menuEntry.to}
|
||||||
|
onClick={handleCollapseClick}>
|
||||||
|
<ListItemIcon
|
||||||
|
color="inherit"
|
||||||
|
className="justify-center overflow-hidden text-white lg:justify-normal"
|
||||||
|
>
|
||||||
|
{menuEntry.icon}
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText
|
||||||
|
primary={menuEntry.label}
|
||||||
|
primaryTypographyProps={{
|
||||||
|
color: "inherit",
|
||||||
|
}}
|
||||||
|
className="hidden lg:block"
|
||||||
|
/>
|
||||||
|
{collapseMenuOpen ? <ExpandLess/> : <ExpandMore/>}
|
||||||
|
</ListItemButton>
|
||||||
|
<Collapse in={collapseMenuOpen} timeout="auto" unmountOnExit>
|
||||||
|
<List component="div" disablePadding>
|
||||||
|
{menuEntityEntries.map((menuEntry, idx) => (
|
||||||
|
<ListItemButton key={idx} sx={{pl: 4}}
|
||||||
|
className="justify-center lg:justify-normal"
|
||||||
|
LinkComponent={Link}
|
||||||
|
href={menuEntry.to}
|
||||||
|
disabled={menuEntry.disabled}
|
||||||
|
selected={activeMenuItem === menuEntry.to}
|
||||||
|
onClick={() => handleMenuItemClick(menuEntry.to)}
|
||||||
|
>
|
||||||
|
<ListItemIcon
|
||||||
|
color="inherit"
|
||||||
|
className="justify-center overflow-hidden text-white lg:justify-normal"
|
||||||
|
>
|
||||||
|
{menuEntry.icon}
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText
|
||||||
|
primary={menuEntry.label}
|
||||||
|
primaryTypographyProps={{
|
||||||
|
color: "inherit",
|
||||||
|
}}
|
||||||
|
className="hidden lg:block"
|
||||||
|
/>
|
||||||
|
</ListItemButton>
|
||||||
|
))}
|
||||||
|
</List>
|
||||||
|
</Collapse>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</ListItem>
|
</ListItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
Reference in New Issue
Block a user