import React from "react"; import classnames from "classnames"; import { OverlayTrigger, OverlayTriggerProps, Popover } from "react-bootstrap"; import { useTranslation } from "react-i18next"; import { BootstrapThemeColor, convertI18nText, I18nText } from "@/common"; export type MenuItem = | { type: "divider"; } | { type: "button"; text: I18nText; iconClassName?: string; color?: BootstrapThemeColor; onClick: () => void; }; export type MenuItems = MenuItem[]; export interface MenuProps { items: MenuItems; className?: string; onItemClicked?: () => void; } const Menu: React.FC = ({ items, className, onItemClicked }) => { const { t } = useTranslation(); return (
{items.map((item, index) => { if (item.type === "divider") { return
; } else { return (
{ item.onClick(); onItemClicked?.(); }} > {item.iconClassName != null ? ( ) : null} {convertI18nText(item.text, t)}
); } })}
); }; export default Menu; export interface PopupMenuProps { items: MenuItems; children: OverlayTriggerProps["children"]; } export const PopupMenu: React.FC = ({ items, children }) => { const [show, setShow] = React.useState(false); const toggle = (): void => setShow(!show); return ( setShow(false)} /> } show={show} onToggle={toggle} > {children} ); };