forked from carmelcity/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobileNavigation.tsx
More file actions
53 lines (48 loc) · 1.91 KB
/
MobileNavigation.tsx
File metadata and controls
53 lines (48 loc) · 1.91 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
import React, { useState, useEffect } from 'react';
import Image from 'next/image';
import { sidebarRoutes } from '../SidebarNavigation/routes';
import Link from 'next/link';
import { DynamicIcon, readexPro } from '~/elements';
export const MobileNavigation = () => {
const [navbarElements, setNavbarElemens] = useState(sidebarRoutes);
const handleNavClick = (targetHref: string) => {
const updatedNavData = navbarElements.map((item: any) => ({
...item,
current: item.href === targetHref,
}));
setNavbarElemens(updatedNavData);
};
const normalizePath = (path: string) => path.replace(/\/+$/, '');
useEffect(() => {
const currentPath = window.location.pathname;
const updatedNavData = navbarElements.map((item: any) => ({
...item,
current: normalizePath(currentPath) === normalizePath(item.href)
}));
setNavbarElemens(updatedNavData);
}, []);
return (
<div className="fixed bottom-0 left-0 z-50 w-full h-16 border-t border-cyan border-opacity-40 backdrop-blur-lg">
<nav className="flex justify-center">
<ul role="list" className="flex justify-between w-full h-full items-center px-4 bg-dark-green/80">
{navbarElements.map((item, index) => (
<li key={item.name} className="flex-grow w-1/5">
<Link
href={item.href}
className={
`${item.current ? `text-cyan` : `text-gray-400`} ` +
`${readexPro.className} font-thin h-16 text-xs flex flex-col gap-x-3 gap-y-2 rounded-md p-2 text-sm leading-3 font-semibold items-center cursor-pointer`
}
onClick={() => handleNavClick(item.href)}>
{
<DynamicIcon name={item.img} width={40} height={40} className={`-m-1`} />
}
{item.name}
</Link>
</li>
))}
</ul>
</nav>
</div>
);
};