forked from carmelcity/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebarNavigation.tsx
More file actions
79 lines (69 loc) · 2.88 KB
/
SidebarNavigation.tsx
File metadata and controls
79 lines (69 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, { useState, useEffect } from 'react';
import Image from 'next/image';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { SidebarNavigationPlaceholder } from '~/components/placeholders/SidebarNavigation';
import { sidebarRoutes } from './routes';
import { DynamicIcon, readexPro } from '~/elements';
import logo from '~/images/logo/logo-white-with-white-text.svg'
import logoSM from '~/images/logo/logo-white.svg'
export const SidebarNavigation = ({ isLoading, auth }: any) => {
const router = useRouter();
const [navbarElements, setNavbarElemens] = useState(sidebarRoutes);
const handleNavClick = (targetHref: string) => {
const updatedNavData = navbarElements.map((item: any) => ({
...item,
current: item.href === targetHref,
}));
setNavbarElemens(updatedNavData);
};
useEffect(() => {
const currentPath = router.asPath;
const updatedNavData = navbarElements.map((item: any) => ({
...item,
current: normalizePath(currentPath) === normalizePath(item.href)
}));
setNavbarElemens(updatedNavData);
}, []);
const normalizePath = (path: string) => path.replace(/\/+$/, '');
if (isLoading) {
return <SidebarNavigationPlaceholder />;
}
return (
<div className="flex z-10 grow sticky top-0 relative flex-col gap-y-5 overflow-y-auto bg-gradient-to-br from-dark-green to-dark-green min-w-[300px] px-6 w-full mr-auto md:h-screen border-r border-cyan/10">
<Link href="/" className='cursor-pointer mt-4'>
<Image src={logoSM} width={60} height={60} alt='logo' className='lg:hidden ml-2'/>
<Image src={logo} width={200} height={60} alt='logo' className='hidden lg:block'/>
</Link>
<nav className="flex flex-1 flex-col border-t border-primary/20 pt-4">
<ul role="list" className="flex flex-1 flex-col gap-y-7">
<li>
<ul role="list" className="-mx-2 space-y-1">
{navbarElements.map((item, index) => (
<li key={item.name}>
<Link
href={item.href}
className={`${
item.current
? 'bg-dark-green-secondary text-cyan'
: 'text-gray-400 hover:text-white hover:bg-dark-green-secondary'
} ${
readexPro.className
} font-normal group flex gap-x-3 rounded-md p-2 text-sm leading-6 items-center cursor-pointer`}
onClick={() => handleNavClick(item.href)}>
{
<DynamicIcon name={item.img} width={24} height={24} />
}
{item.name}
</Link>
</li>
))}
</ul>
</li>
{/* <li className="-mx-6 mt-auto">
</li> */}
</ul>
</nav>
</div>
);
};