-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added changelog and changed navbar design * added key for mapped items * added key for mapped items * added key for dropdown items --------- Co-authored-by: Anusree Subash <[email protected]>
- Loading branch information
1 parent
174b47a
commit e4947fd
Showing
8 changed files
with
667 additions
and
233 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useState } from 'react'; | ||
import Link from 'next/link'; | ||
import { IconChevronRight } from '@tabler/icons'; | ||
import FlyoutMenu from '../FlyoutMenu'; | ||
|
||
const Dropdown = ({ menuTitle, dropdownItems, isSmallSCreen, current }) => { | ||
const [dropdownOpen, setDropdownOpen] = useState(false); | ||
|
||
const toggleDropdown = () => { | ||
setDropdownOpen(!dropdownOpen); | ||
}; | ||
if(!isSmallSCreen) { | ||
return ( | ||
<div> | ||
<FlyoutMenu className="font-medium mr-3 hover:text-yellow-600" menuTitle={menuTitle} subItems={dropdownItems} current={current} /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
{isSmallSCreen && ( | ||
<div className="cursor-pointer mb-4 hover:none" onClick={toggleDropdown}> | ||
<div className="flex items-center"> | ||
<span>{menuTitle}</span> | ||
<IconChevronRight | ||
size={18} | ||
className={`ml-1 transition-transform duration-300 ${dropdownOpen ? 'rotate-90' : ''}`} | ||
/> | ||
</div> | ||
{dropdownOpen && ( | ||
<div className="p-2"> | ||
{dropdownItems.map((item) => ( | ||
<div className="py-2" key={item.name}> | ||
<Link href={item.href} legacyBehavior className="menu-item"> | ||
<a | ||
target={item.target} | ||
className={`${current === item.href ? 'text-yellow-600' : ''} transition`} | ||
aria-current={item.current ? 'page' : undefined} | ||
> | ||
{item.name} | ||
</a> | ||
</Link> | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default Dropdown; |
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { useRef, useState, useEffect } from "react"; | ||
import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react"; | ||
|
||
const FlyoutMenu = ({ menuTitle, subItems, className, current }) => { | ||
let timeout; | ||
const timeoutDuration = 200; | ||
|
||
const buttonRef = useRef(null); | ||
const panelRef = useRef(null); | ||
const [openState, setOpenState] = useState(false); | ||
|
||
const getClassNames = (classes) => { | ||
return `${className} ${classes}`; | ||
}; | ||
|
||
const toggleMenu = (open) => { | ||
setOpenState((openState) => !openState); | ||
buttonRef?.current?.click(); | ||
}; | ||
|
||
const onHover = (open, action) => { | ||
if ( | ||
(!open && !openState && action === "onMouseEnter") || | ||
(open && openState && action === "onMouseLeave") | ||
) { | ||
clearTimeout(timeout); | ||
timeout = setTimeout(() => toggleMenu(open), timeoutDuration); | ||
} | ||
}; | ||
|
||
const handleClickOutside = (event) => { | ||
if ( | ||
buttonRef.current && | ||
!buttonRef.current.contains(event.target) && | ||
panelRef.current && | ||
!panelRef.current.contains(event.target) | ||
) { | ||
setOpenState(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
document.addEventListener("mousedown", handleClickOutside); | ||
return () => { | ||
document.removeEventListener("mousedown", handleClickOutside); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<Popover className="relative"> | ||
{({ open }) => ( | ||
<div | ||
onMouseEnter={() => onHover(open, "onMouseEnter")} | ||
onMouseLeave={() => onHover(open, "onMouseLeave")} | ||
className="flex flex-col" | ||
> | ||
<PopoverButton | ||
ref={buttonRef} | ||
className={getClassNames("hover:outline-none focus:outline-none")} | ||
style={{ marginBottom: "0.8rem" }} | ||
> | ||
<span>{menuTitle}</span> | ||
</PopoverButton> | ||
<PopoverPanel | ||
ref={panelRef} | ||
onMouseEnter={() => clearTimeout(timeout)} | ||
onMouseLeave={() => onHover(open, "onMouseLeave")} | ||
transition | ||
className="absolute left-1/2 z-10 mt-8 flex w-screen max-w-min -translate-x-1/2 px-4 transition data-[closed]:translate-y-1 data-[closed]:opacity-0" | ||
> | ||
<div className="shrink rounded-xl bg-white p-2 text-sm font-medium leading-6 shadow-lg ring-1 ring-gray-900/5"> | ||
{subItems.map((item) => ( | ||
<div className="p-1" key={item.name}> | ||
<a | ||
key={item.name} | ||
href={item.href} | ||
target={item?.target || "_self"} | ||
className={`${current === item.href ? 'border-yellow-600 text-yellow-600' : ''} inline-block hover:text-yellow-600`} | ||
> | ||
{item.name} | ||
</a> | ||
</div> | ||
))} | ||
</div> | ||
</PopoverPanel> | ||
</div> | ||
)} | ||
</Popover> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FlyoutMenu; |
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
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
Oops, something went wrong.