-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added more stuff to header and added dropdown menu
- Loading branch information
1 parent
ffeb536
commit dccd335
Showing
2 changed files
with
62 additions
and
12 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
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,18 +1,59 @@ | ||
import Link from "next/link"; | ||
import { useRouter } from "next/router"; | ||
import { useState } from "react"; | ||
import Icon from "../icon/Icon"; | ||
|
||
const HeaderLink = ({ link, children }: { link: string; children: any }) => { | ||
const isCurrentSite = useRouter().pathname === link; | ||
const HeaderDropdown = ({ | ||
link, | ||
children, | ||
}: { | ||
link: string; | ||
children: { name: string; href: string }[]; | ||
}) => { | ||
const currentSite = useRouter().pathname; | ||
|
||
const [active, setActive] = useState(false); | ||
|
||
function toggleActive() { | ||
setActive(!active); | ||
} | ||
|
||
const isCurrentDropdown = children.some( | ||
(child) => child.href === currentSite | ||
); | ||
|
||
return ( | ||
<Link href={link}> | ||
<a href={link}> | ||
<h1 className={`m-0 text-xl ${isCurrentSite && "color-secondary"}`}> | ||
{children} | ||
</h1> | ||
</a> | ||
</Link> | ||
<div> | ||
<span | ||
className={`m-0 flex items-center text-xl hover:cursor-pointer ${ | ||
isCurrentDropdown && "color-secondary" | ||
}`} | ||
onClick={toggleActive} | ||
> | ||
{link} | ||
<Icon | ||
name="arrow-drop-down-line" | ||
className={`ri-2x transition-all ${active && "rotate-180"}`} | ||
/> | ||
</span> | ||
|
||
{active && ( | ||
<ul | ||
className={`bg-secondary absolute mt-1 flex w-fit flex-col gap-2 rounded-lg p-4`} | ||
> | ||
{children.map((child) => ( | ||
<li key={child.href}> | ||
<a | ||
href={child.href} | ||
className={currentSite === child.href ? "color-secondary" : ""} | ||
> | ||
{child.name} | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default HeaderLink; | ||
export default HeaderDropdown; |