import React from 'react'; import { useToolbar } from '@ohif/core'; /** * Props for the Toolbar component that renders a collection of toolbar buttons and/or button sections. * * @interface ToolbarProps */ interface ToolbarProps { /** * The section of buttons to display in the toolbar. * Common values include 'primary', 'secondary', 'tertiary', etc. * Defaults to 'primary' if not specified. * * @default 'primary' */ buttonSection?: string; /** * The unique identifier of the viewport this toolbar is associated with. */ viewportId?: string; /** * The numeric position or location of the toolbar. * Used for ordering and layout purposes in the UI. */ location?: number; } export function Toolbar({ buttonSection = 'primary', viewportId, location }: ToolbarProps) { const { toolbarButtons, onInteraction, isItemOpen, isItemLocked, openItem, closeItem, toggleLock, } = useToolbar({ buttonSection, }); if (!toolbarButtons.length) { return null; } return ( <> {toolbarButtons?.map(toolDef => { if (!toolDef) { return null; } const { id, Component, componentProps } = toolDef; // Enhanced props with state and actions - respecting viewport specificity const enhancedProps = { ...componentProps, isOpen: isItemOpen(id, viewportId), isLocked: isItemLocked(id, viewportId), onOpen: () => openItem(id, viewportId), onClose: () => closeItem(id, viewportId), onToggleLock: () => toggleLock(id, viewportId), viewportId, }; const tool = ( { onInteraction({ ...args, itemId: id, viewportId, }); }} {...enhancedProps} /> ); return (
{tool}
); })} ); }