Files
echecsfrance/src/components/DropdownMenu.tsx
T
owenrees da78e82a44 upgrade Nodemailer to v10
fix dead code with knip

upgrade TS to v6 and fix linting errors

auto apply oxfmt rules

fix linting errors - unused deps etc

ignore file

remove all ignored files in knip

add knip - dead code analysis tool

swap prettier and eslint of oxfmt and oxlint

fix: fix map rendering in react strict mode

fix: headlessUI float replace

fix: disable Matomo if not URL and SITE ID exist

upgrade: 1st pass upgrade to Next.js v16

deps: upgrade react to v19
2026-09-29 22:16:07 +02:00

60 lines
1.8 KiB
TypeScript

import React from "react";
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/react";
import { IoMdMore } from "react-icons/io";
import { twMerge } from "tailwind-merge";
export type DropdownMenuItem = {
title: React.ReactNode;
disabled?: boolean;
onClick: () => void;
className?: string;
};
type DropdownMenuProps = {
items: DropdownMenuItem[];
buttonComponent?: React.ReactElement;
containerClassName?: string;
};
export const DropdownMenu = ({ items, buttonComponent, containerClassName }: DropdownMenuProps) => {
return (
<Menu as="div" className={twMerge("relative", containerClassName)}>
{buttonComponent ?? (
<MenuButton>
<IoMdMore />
</MenuButton>
)}
<MenuItems
anchor={{ to: "bottom end", gap: 15 }}
portal
transition
className="z-20 flex w-auto items-start overflow-hidden rounded-md bg-neutral-200 transition ease-out data-[closed]:scale-95 data-[closed]:opacity-0 focus:outline-none dark:bg-neutral-600"
>
<div className="flex flex-col px-1 py-1">
{items.map(({ title, onClick, className, disabled }, i) => (
<MenuItem key={i}>
<button
type="button"
className={twMerge(
"w-full whitespace-nowrap rounded-md px-2.5 py-2 text-left text-sm text-black dark:text-white",
!disabled && "hover:bg-white dark:hover:bg-neutral-700",
disabled && "text-neutral-500 dark:text-neutral-500",
className,
)}
disabled={disabled ?? false}
onClick={() => {
if (!disabled) onClick();
}}
>
{title}
</button>
</MenuItem>
))}
</div>
</MenuItems>
</Menu>
);
};