diff --git a/invokeai/frontend/src/common/components/IAISimpleMenu.tsx b/invokeai/frontend/src/common/components/IAISimpleMenu.tsx new file mode 100644 index 0000000000..397697a3fe --- /dev/null +++ b/invokeai/frontend/src/common/components/IAISimpleMenu.tsx @@ -0,0 +1,101 @@ +import { + Menu, + MenuButton, + MenuItem, + MenuList, + type MenuProps, + type MenuButtonProps, + type MenuListProps, + type MenuItemProps, +} from '@chakra-ui/react'; +import { MouseEventHandler, ReactNode } from 'react'; +import { MdArrowDropDown, MdArrowDropUp } from 'react-icons/md'; +import IAIButton from './IAIButton'; +import IAIIconButton from './IAIIconButton'; + +interface IAIMenuItem { + item: ReactNode | string; + onClick: MouseEventHandler | undefined; +} + +interface IAIMenuProps { + menuType?: 'icon' | 'regular'; + buttonText?: string; + iconTooltip?: string; + menuItems: IAIMenuItem[]; + menuProps?: MenuProps; + menuButtonProps?: MenuButtonProps; + menuListProps?: MenuListProps; + menuItemProps?: MenuItemProps; +} + +export default function IAISimpleMenu(props: IAIMenuProps) { + const { + menuType = 'icon', + iconTooltip, + buttonText, + menuItems, + menuProps, + menuButtonProps, + menuListProps, + menuItemProps, + } = props; + + const renderMenuItems = () => { + const menuItemsToRender: ReactNode[] = []; + menuItems.forEach((menuItem) => { + menuItemsToRender.push( + + {menuItem.item} + + ); + }); + return menuItemsToRender; + }; + + return ( + + {({ isOpen }) => ( + <> + : } + padding={menuType === 'regular' ? '0 0.5rem' : 0} + backgroundColor="var(--destructive-color)" + color="var(--text-color)" + minWidth="1.5rem" + minHeight="1.5rem" + _hover={{ + backgroundColor: 'var(--destructive-color-hover)', + }} + {...menuButtonProps} + > + {menuType === 'regular' && buttonText} + + + {renderMenuItems()} + + + )} + + ); +}