From 979330478c7ce2cb65741a75341115bb517ec4f8 Mon Sep 17 00:00:00 2001 From: victorAnumudu Date: Mon, 18 Mar 2024 01:32:52 +0100 Subject: [PATCH 1/2] made aside bar to close on mobile view whenever a link is clicked --- src/components/DashboardLayout/Aside.tsx | 104 ++++++++++++++---- .../DashboardLayout/DashboardLayout.tsx | 12 +- 2 files changed, 90 insertions(+), 26 deletions(-) diff --git a/src/components/DashboardLayout/Aside.tsx b/src/components/DashboardLayout/Aside.tsx index 2e833e4..c37e932 100644 --- a/src/components/DashboardLayout/Aside.tsx +++ b/src/components/DashboardLayout/Aside.tsx @@ -1,31 +1,86 @@ +import {useState} from 'react' import { Link, useLocation, useNavigate } from "react-router-dom"; import { Icons } from "../index"; -export default function Aside() { +type Props = { + asideDisplay?: () => void +} + +export default function Aside({asideDisplay}:Props) { const {pathname} = useLocation() const navigate = useNavigate() + const [openNestedLink, setOpenNestedLink] = useState<{name:string|null}>({name: ''}) + + const handleOpenNestedLink = (e:any) => { + if(!e || !e.target){ + return setOpenNestedLink({name: ''}) + } + if(openNestedLink.name && openNestedLink.name == e.target.name){ + setOpenNestedLink({name: ''}) + }else{ + setOpenNestedLink({name: e.target.name}) + } + } + return ( -
+

AC

-
- {asideLinks.map((link, index) => ( - - - {link.name} - - ))} +
+ {asideLinks.map((link, index) => { + if(link.nestedLink?.length){ + let allNestedLinks = link.nestedLink.map(item => item.link) + return ( +
+ +
+ {link.nestedLink.map((nextLink, index) => ( + {asideDisplay && asideDisplay()}} + key={index} + to={nextLink.link ? nextLink.link : '#'} + className={`w-full my-1 flex items-center gap-2 py-2 pl-5 text-base font-medium border-l-2 ${pathname == nextLink.link ? 'border-[#5C2684] text-[#5C2684]' : 'border-transparent text-[#585858]'}`} + > + + {nextLink.name} + + ))} +
+
+ ) + }else{ + return( + {asideDisplay && asideDisplay()}} + key={index} + to={link.link ? link.link : '#'} + className={`w-full my-4 flex items-center gap-2 py-2 pl-5 rounded-lg text-base font-medium border-2 ${pathname == link.link ? 'border-[#5C2684] text-[#5C2684]' : 'border-transparent text-[#585858]'}`} + > + + {link.name} + + ) + } + })}