-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made hamburger menu and navbar sticky
- Loading branch information
Tanuj Nainwal
authored and
Tanuj Nainwal
committed
Nov 11, 2024
1 parent
56cab69
commit 4e9ca50
Showing
3 changed files
with
55 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,60 @@ | ||
import React,{useState,forwardRef} from 'react'; | ||
import links from '../../config/links.json'; | ||
import React, { useState, forwardRef } from 'react'; | ||
import links from '../../config/links.json'; // Your link data | ||
import Link from 'next/link'; | ||
import Dropdown from '../illustration/dropdown'; | ||
|
||
const NavDrop = forwardRef((props, ref) => { | ||
const { setDrop } = props; | ||
const [show, setShow] = useState(null); // Track which submenu is open | ||
|
||
// Toggle the dropdown for a particular menu | ||
const toggleDropdown = (linkTitle) => { | ||
setShow(show === linkTitle ? null : linkTitle); // Toggle open/close | ||
}; | ||
|
||
const NavDrop = forwardRef((props, ref)=> { | ||
const {setDrop}=props; | ||
const [show, setShow] = useState(null); | ||
return ( | ||
<div ref ={ref} className='absolute ml-[-20px] top-16 w-full bg-[#1B1130]'> | ||
<div className='flex flex-col p-5 pb-8 w-full'> | ||
{links.map((link) => { | ||
return ( | ||
<Link href={link.ref} key={link.title}> | ||
<div | ||
className='min-h-[50px] cursor-pointer' | ||
onClick={() => | ||
show === link.title ? setShow(null) : setShow(link.title) | ||
} | ||
> | ||
{link.subMenu ? ( | ||
<div> | ||
<div className='flex items-center justify-between'> | ||
<div className='text-white'>{link.title}</div> | ||
<Dropdown | ||
className={`transition-transform duration-700 ${ | ||
show === link.title ? 'rotate-0' : 'rotate-[-90deg]' | ||
}`} | ||
/> | ||
</div> | ||
{show && show === link.title && ( | ||
<div className='flex flex-col py-6 w-full'> | ||
{link.subMenu.map((sub) => ( | ||
<Link href={sub.ref} key={sub.ref}> | ||
<div | ||
onClick={() => setDrop(false)} | ||
className='h-[40px] flex navbg items-center p-6 hover:text-black text-white cursor-pointer' | ||
> | ||
{sub.title} | ||
</div> | ||
</Link> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
) : ( | ||
<div className='text-white' onClick={() => setDrop(false)}> | ||
{link.title} | ||
</div> | ||
)} | ||
</div> | ||
</Link> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
}) | ||
<div ref={ref} className="absolute ml-[-20px] top-16 w-full bg-[#1B1130]"> | ||
<div className="flex flex-col p-5 pb-8 w-full"> | ||
{links.map((link) => ( | ||
<Link href={link.ref} key={link.title}> | ||
<div className="min-h-[50px] cursor-pointer"> | ||
<div | ||
className="flex items-center justify-between" | ||
onClick={() => toggleDropdown(link.title)} | ||
> | ||
<div className="text-white">{link.title}</div> | ||
{link.subMenu && ( | ||
<Dropdown | ||
className={`transition-transform duration-700 ${ | ||
show === link.title ? 'rotate-0' : 'rotate-[-90deg]' | ||
}`} | ||
/> | ||
)} | ||
</div> | ||
|
||
{/* Display submenu if it is open */} | ||
{show === link.title && link.subMenu && ( | ||
<div className="flex flex-col py-6 w-full"> | ||
{link.subMenu.map((sub) => ( | ||
<Link href={sub.ref} key={sub.ref}> | ||
<div | ||
onClick={() => setDrop(false)} // Close the menu when a sub-link is clicked | ||
className="h-[40px] flex navbg items-center p-6 hover:text-black text-white cursor-pointer" | ||
> | ||
{sub.title} | ||
</div> | ||
</Link> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
</Link> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}); | ||
|
||
NavDrop.displayName = 'NavDrop'; | ||
|
||
export default NavDrop; | ||
export default NavDrop; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.