import React, { MouseEventHandler, ReactNode } from "react"; import { Menu, Transition } from "@headlessui/react"; import clsx from "clsx"; import { usePopper } from "./use-popper"; import { Link } from "react-router"; interface Props { button: ReactNode; options: { title?: string; routePath?: string; onClick?: () => void | undefined; disabled?: boolean; className?: string; render?: (active: boolean, close: () => void) => ReactNode; }[]; size?: "sm" | "md" | "lg" | "xl"; onClick?: MouseEventHandler; className?: string; } export default function MenuWithPopper({ button, options, size = "sm", onClick, className }: Props) { let [trigger, container] = usePopper({ strategy: "fixed", }); return ( {button}
{options.map((item, idx) => { return ( {({ active, close }) => ( <> {item.render && item.render(active, close)} {item.onClick && ( )} {item.routePath && ( { e.stopPropagation(); close(); }} className={clsx( item.className, "hover:bg-surface-neutral-secondary w-full text-left", item.disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer", active ? "text-text-neutral-primary bg-surface-neutral-secondary" : "text-text-neutral-secondary", "block px-4 py-2 text-sm" )} > {item.title} )} )} ); })}
); }