2025-01-13 10:49:08 -05:00
|
|
|
import React from 'react';
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuTrigger,
|
2025-01-29 13:36:52 -05:00
|
|
|
DropdownMenuItem,
|
2025-01-13 10:49:08 -05:00
|
|
|
Icons,
|
|
|
|
|
Button,
|
|
|
|
|
} from '@ohif/ui-next';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The default sub-menu appearance and setup is defined here, but this can be
|
|
|
|
|
* replaced by
|
|
|
|
|
*/
|
2025-02-03 09:28:58 -05:00
|
|
|
const getMenuItemsDefault = ({
|
|
|
|
|
commandsManager,
|
|
|
|
|
items,
|
|
|
|
|
servicesManager,
|
|
|
|
|
...props
|
|
|
|
|
}: withAppTypes) => {
|
2025-01-13 10:49:08 -05:00
|
|
|
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');
|
|
|
|
|
|
2025-01-29 13:36:52 -05:00
|
|
|
// Default menu item component if none is provided through customization
|
2025-02-03 09:28:58 -05:00
|
|
|
|
|
|
|
|
const DefaultMenuItem = ({
|
|
|
|
|
item,
|
|
|
|
|
}: {
|
|
|
|
|
item: {
|
|
|
|
|
id: string;
|
|
|
|
|
label: string;
|
|
|
|
|
iconName: string;
|
2025-02-04 18:33:45 -05:00
|
|
|
onClick: ({ commandsManager, ...props }: withAppTypes) => () => void;
|
2025-02-03 09:28:58 -05:00
|
|
|
};
|
|
|
|
|
}) => (
|
2025-02-04 18:33:45 -05:00
|
|
|
<DropdownMenuItem onClick={() => item.onClick({ commandsManager, ...props })}>
|
2025-02-03 09:28:58 -05:00
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
{item.iconName && <Icons.ByName name={item.iconName} />}
|
|
|
|
|
<span>{item.label}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</DropdownMenuItem>
|
2025-01-29 13:36:52 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const MenuItemComponent = menuContent?.content || DefaultMenuItem;
|
|
|
|
|
|
2025-01-13 10:49:08 -05:00
|
|
|
return (
|
|
|
|
|
<DropdownMenuContent
|
|
|
|
|
hideWhenDetached
|
|
|
|
|
align="start"
|
|
|
|
|
onClick={e => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-01-29 13:36:52 -05:00
|
|
|
{items?.map((item, index) => (
|
|
|
|
|
<MenuItemComponent
|
|
|
|
|
key={item.id || `menu-item-${index}`}
|
|
|
|
|
item={item}
|
|
|
|
|
commandsManager={commandsManager}
|
|
|
|
|
servicesManager={servicesManager}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
2025-01-13 10:49:08 -05:00
|
|
|
</DropdownMenuContent>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
|
2025-01-23 14:24:13 -05:00
|
|
|
const items = customizationService.getCustomization(menuItemsKey);
|
2025-01-13 10:49:08 -05:00
|
|
|
|
2025-01-23 14:24:13 -05:00
|
|
|
if (!items?.length) {
|
2025-01-13 10:49:08 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BoundMoreDropdownMenu(props) {
|
|
|
|
|
return (
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
className="hidden group-hover:inline-flex data-[state=open]:inline-flex"
|
|
|
|
|
onClick={e => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Icons.More />
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
{getMenuItems({
|
|
|
|
|
...props,
|
|
|
|
|
commandsManager: commandsManager,
|
|
|
|
|
servicesManager: servicesManager,
|
|
|
|
|
items,
|
|
|
|
|
})}
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return BoundMoreDropdownMenu;
|
|
|
|
|
}
|