From 21e71c4ec2b1598180cfb7ae881cbd71e4d07a49 Mon Sep 17 00:00:00 2001 From: Onur Arslan Date: Thu, 23 Nov 2023 21:36:13 +0100 Subject: [PATCH] [Layout] Modify the Entities to be in a collapsible submenu - implemented collapsible submenu for Entities --- pkgs/ui/src/components/sidebar/index.tsx | 308 ++++++++++++++--------- 1 file changed, 186 insertions(+), 122 deletions(-) diff --git a/pkgs/ui/src/components/sidebar/index.tsx b/pkgs/ui/src/components/sidebar/index.tsx index 50eaf33..fd1cf76 100644 --- a/pkgs/ui/src/components/sidebar/index.tsx +++ b/pkgs/ui/src/components/sidebar/index.tsx @@ -1,16 +1,17 @@ import { - Divider, - IconButton, - List, - ListItem, - ListItemButton, - ListItemIcon, - ListItemText, + Divider, + IconButton, + List, + ListItem, + ListItemButton, + ListItemIcon, + ListItemText, } from "@mui/material"; 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 ChevronLeftIcon from "@mui/icons-material/ChevronLeft"; import HomeIcon from "@mui/icons-material/Home"; @@ -18,134 +19,197 @@ import HubIcon from "@mui/icons-material/Hub"; import PersonIcon from "@mui/icons-material/Person"; import RouterIcon from "@mui/icons-material/Router"; import StorageIcon from "@mui/icons-material/Storage"; +import ExpandLess from '@mui/icons-material/ExpandLess'; +import ExpandMore from '@mui/icons-material/ExpandMore'; type MenuEntry = { - icon: ReactNode; - label: string; - to: string; - disabled: boolean; + icon: ReactNode; + label: string; + to: string; + disabled: boolean; } & { - subMenuEntries?: MenuEntry[]; + subMenuEntries?: MenuEntry[]; }; +const menuEntityEntries: MenuEntry[] = [ + { + icon: , + label: "C1", + to: "/client-1", + disabled: false, + }, + { + icon: , + label: "C2", + to: "/client-2", + disabled: false, + } +]; + const menuEntries: MenuEntry[] = [ - { - icon: , - label: "Home", - to: "/", - disabled: false, - }, - { - icon: , - label: "Entities", - to: "/entities", - disabled: true, - }, - { - icon: , - label: "C1", - to: "/client-1", - disabled: false, - }, - { - icon: , - label: "C2", - to: "/client-2", - disabled: false, - }, - { - icon: , - label: "AP", - to: "/access-point", - disabled: false, - }, - { - icon: , - label: "DLG", - to: "/distributed-ledger-gateway", - disabled: false, - }, + { + icon: , + label: "Home", + to: "/", + disabled: false, + }, + { + icon: , + label: "Entities", + to: "/entities", + disabled: false, + }, + { + icon: , + label: "AP", + to: "/access-point", + disabled: false, + }, + { + icon: , + label: "DLG", + to: "/distributed-ledger-gateway", + disabled: false, + }, ]; const hideSidebar = tw`-translate-x-14 lg:-translate-x-64`; const showSidebar = tw`lg:translate-x-0`; interface SidebarProps { - show: boolean; - onClose: () => void; + show: boolean; + onClose: () => void; } + export function Sidebar(props: SidebarProps) { - const { show, onClose } = props; + const {show, onClose} = props; + const [activeMenuItem, setActiveMenuItem] = React.useState("/"); + const [collapseMenuOpen, setCollapseMenuOpen] = React.useState(true); - const [activeMenuItem, setActiveMenuItem] = React.useState("/"); + const handleCollapseClick = () => { + setCollapseMenuOpen(!collapseMenuOpen); + }; - const handleMenuItemClick = (path: string) => { - setActiveMenuItem(path); - }; + const handleMenuItemClick = (path: string) => { + setActiveMenuItem(path); + }; - return ( - - ); + return ( + + ); }