Files
next-web/src/components/Dropdown.tsx
T

84 lines
2.8 KiB
TypeScript
Raw Normal View History

2025-07-02 16:39:16 -04:00
import React, { useState } from 'react'
import Link from 'next/link';
import classnames from 'classnames';
import Button from './Button';
import { MenuItem } from './Navbar'
interface Props {
item: MenuItem;
}
export default function Dropdown(props: Props) {
const { item } = props;
const [isOpen, setIsOpen] = useState<boolean>(false);
const menuItems = item?.children ? item.children : [];
const lastIndex = menuItems.length - 1;
2025-07-09 15:56:02 -04:00
const itemId = item.id;
2025-07-02 16:39:16 -04:00
const toggle = () => {
setIsOpen(old => !old);
}
const transClass = isOpen
?
"flex"
:
"hidden";
function isLastItem (currentItem: MenuItem) {
return lastIndex == menuItems.indexOf(currentItem)
}
2025-07-09 15:56:02 -04:00
function isSecondItem (currentItem: MenuItem) {
return 1 == menuItems.indexOf(currentItem)
}
2025-07-02 16:39:16 -04:00
return (
<>
<div className="relative">
<Button
2025-07-03 13:35:22 -04:00
className="hover:text-britton-light font-semibold text-lg"
2025-07-02 16:39:16 -04:00
onClick={toggle}
>{item.title}</Button>
2025-07-10 11:52:38 -04:00
<div className={`absolute top-8 z-11 w-[150px] flex flex-col bg-stone-300 text-sm rounded-md ${transClass}`}>
2025-07-02 16:39:16 -04:00
{
menuItems.map(item =>
<>
<Link
2025-07-09 15:56:02 -04:00
key={item.id}
className={classnames(
"hover:text-britton-neutral text-center px-2 py-1",
{
"hover:bg-britton-newblue" : itemId == 'employers',
"hover:bg-britton-medium" : itemId != 'employers'
}
)}
2025-07-02 16:39:16 -04:00
href={item?.route || ''}
onClick={toggle}
>
{item.title}
</Link>
<div className={classnames(
2025-07-03 13:35:22 -04:00
"h-px bg-britton-accent mx-2",
2025-07-02 16:39:16 -04:00
{"hidden" : isLastItem(item)}
)}
/>
</>
)
}
</div>
</div>
{
isOpen
?
<div
2025-07-10 11:52:38 -04:00
className="fixed top-0 right-0 bottom-0 left-0 z-11 bg-britton-dark/40"
2025-07-02 16:39:16 -04:00
onClick={toggle}
></div>
:
<></>
}
</>
)
}