import React from 'react';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuTrigger,
DropdownMenuItem,
Icons,
Button,
} from '@ohif/ui-next';
/**
* The default sub-menu appearance and setup is defined here, but this can be
* replaced by
*/
const getMenuItemsDefault = ({
commandsManager,
items,
servicesManager,
...props
}: withAppTypes) => {
const { customizationService } = servicesManager.services;
// This allows replacing the default child item for menus, whereas the entire
// getMenuItems can also be replaced by providing it to the MoreDropdownMenu
const menuContent = customizationService.getCustomization('ohif.menuContent');
// Default menu item component if none is provided through customization
const DefaultMenuItem = ({
item,
}: {
item: {
id: string;
label: string;
iconName: string;
onClick: ({ commandsManager, ...props }: withAppTypes) => () => void;
};
}) => (
item.onClick({ commandsManager, ...props })}>
{item.iconName && }
{item.label}
);
const MenuItemComponent = menuContent?.content || DefaultMenuItem;
return (
{
e.stopPropagation();
e.preventDefault();
}}
>
{items?.map((item, index) => (
))}
);
};
/**
* The component provides a ... sub-menu for various components which appears
* on hover over the main component.
*
* @param bindProps - properties to define the sub-menu
* @returns Component bound to the bindProps
*/
export default function MoreDropdownMenu(bindProps) {
const {
menuItemsKey,
getMenuItems = getMenuItemsDefault,
commandsManager,
servicesManager,
} = bindProps;
const { customizationService } = servicesManager.services;
const items = customizationService.getCustomization(menuItemsKey);
if (!items?.length) {
return null;
}
function BoundMoreDropdownMenu(props) {
return (
{getMenuItems({
...props,
commandsManager: commandsManager,
servicesManager: servicesManager,
items,
})}
);
}
return BoundMoreDropdownMenu;
}