ui(components): Viewport components added to ui-next (#4649)

Co-authored-by: sedghi <ar.sedghi@gmail.com>
This commit is contained in:
Dan Rukasandsedghi authored and GitHub committed 2025-01-08 14:23:34 -05:00
1 parent 47de38f3ff
commit 230ae9758b
37 files changed
+1617 -21

No files matched your search

@@ -0,0 +1,138 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { useTranslation } from 'react-i18next';
import { Icons, Tooltip, TooltipTrigger, TooltipContent } from '../../components';
const classes = {
infoHeader: 'text-base text-primary-light',
infoText: 'text-base text-white max-w-24 truncate',
firstRow: 'flex flex-col',
row: 'flex flex-col ml-4',
};
/**
* A small info icon that, when clicked, can reveal additional patient details in a tooltip overlay.
*/
function PatientInfo({
patientName,
patientSex,
patientAge,
MRN,
thickness,
thicknessUnits,
spacing,
scanner,
isOpen,
showPatientInfoRef,
}) {
const { t } = useTranslation('PatientInfo');
// strip leading '0' from age if present
while (patientAge.charAt(0) === '0') {
patientAge = patientAge.substr(1);
}
return (
<div ref={showPatientInfoRef}>
<Tooltip>
<TooltipTrigger asChild>
<Icons.Info className="hover:text-primary-light cursor-pointer text-white" />
</TooltipTrigger>
{isOpen && (
<TooltipContent
side="bottom"
align="end"
>
<div className="flex py-2">
<div className="flex pt-1">
<Icons.InfoLink className="text-primary-main w-4" />
</div>
<div className="ml-2 flex flex-col">
<span
className="text-base font-bold text-white"
title={patientName}
>
{patientName}
</span>
<div className="border-secondary-main mt-4 mb-4 flex border-b pb-4">
<div className={classnames(classes.firstRow)}>
<span className={classnames(classes.infoHeader)}>{t('Sex')}</span>
<span
className={classnames(classes.infoText)}
title={patientSex}
>
{patientSex}
</span>
</div>
<div className={classnames(classes.row)}>
<span className={classnames(classes.infoHeader)}>{t('Age')}</span>
<span
className={classnames(classes.infoText)}
title={patientAge}
>
{patientAge}
</span>
</div>
<div className={classnames(classes.row)}>
<span className={classnames(classes.infoHeader)}>{t('MRN')}</span>
<span
className={classnames(classes.infoText)}
title={MRN}
>
{MRN}
</span>
</div>
</div>
<div className="flex">
<div className={classnames(classes.firstRow)}>
<span className={classnames(classes.infoHeader)}>{t('Thickness')}</span>
<span
className={classnames(classes.infoText)}
title={thickness}
>
{thicknessUnits ? `${thickness}${thicknessUnits}` : `${thickness}`}
</span>
</div>
<div className={classnames(classes.row)}>
<span className={classnames(classes.infoHeader)}>{t('Spacing')}</span>
<span
className={classnames(classes.infoText)}
title={spacing}
>
{spacing}
</span>
</div>
<div className={classnames(classes.row)}>
<span className={classnames(classes.infoHeader)}>{t('Scanner')}</span>
<span
className={classnames(classes.infoText)}
title={scanner}
>
{scanner}
</span>
</div>
</div>
</div>
</div>
</TooltipContent>
)}
</Tooltip>
</div>
);
}
PatientInfo.propTypes = {
patientName: PropTypes.string,
patientSex: PropTypes.string,
patientAge: PropTypes.string,
MRN: PropTypes.string,
thickness: PropTypes.string,
thicknessUnits: PropTypes.string,
spacing: PropTypes.string,
scanner: PropTypes.string,
isOpen: PropTypes.bool,
showPatientInfoRef: PropTypes.object,
};
export { PatientInfo };
@@ -0,0 +1,31 @@
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { Icons } from '@ohif/ui-next';
const arrowClasses =
'cursor-pointer flex items-center justify-center shrink-0 text-primary-light active:text-white hover:bg-secondary-light/60 rounded';
/**
* A small set of left/right arrow icons for stepping through slices or series.
*/
function ViewportActionArrows({ onArrowsClick, className }) {
return (
<div className={classNames(className, 'flex')}>
<div className={arrowClasses}>
<Icons.ArrowLeftBold onClick={() => onArrowsClick(-1)} />
</div>
<div className={arrowClasses}>
<Icons.ArrowRightBold onClick={() => onArrowsClick(1)} />
</div>
</div>
);
}
ViewportActionArrows.propTypes = {
onArrowsClick: PropTypes.func.isRequired,
className: PropTypes.string,
};
export { ViewportActionArrows };
@@ -0,0 +1,128 @@
import React, {
MouseEventHandler,
ReactElement,
useCallback,
useEffect,
useRef,
useState,
} from 'react';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
import { Icons } from '@ohif/ui-next';
import PatientInfo from './PatientInfo';
/**
* This is the modern Viewport Action Bar, showing patient info, series date,
* series description, and optional next/prev arrows if there's enough screen width.
*/
type ViewportActionBarProps = {
studyData: any;
onArrowsClick: (arrow: string) => void;
onDoubleClick: MouseEventHandler;
getStatusComponent: () => ReactElement;
};
function ViewportActionBar({
studyData,
onArrowsClick,
onDoubleClick,
getStatusComponent,
}: ViewportActionBarProps): JSX.Element {
const { label, studyDate, seriesDescription, patientInformation } = studyData;
const { patientName, patientSex, patientAge, MRN, thickness, thicknessUnits, spacing, scanner } =
patientInformation;
const [showPatientInfo, setShowPatientInfo] = useState(false);
const showPatientInfoElemRef = useRef<HTMLDivElement>(null);
const { t } = useTranslation();
// handle click outside to close patient info
const handleClickOutside = useCallback(
(evt: MouseEvent) => {
if (
showPatientInfo &&
showPatientInfoElemRef.current &&
!showPatientInfoElemRef.current.contains(evt.target as Node)
) {
setShowPatientInfo(false);
}
},
[showPatientInfoElemRef, showPatientInfo]
);
useEffect(() => {
document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, [handleClickOutside]);
return (
<div
className="pointer-events-auto flex h-8 shrink-0 select-none items-center overflow-visible whitespace-nowrap px-2 text-base"
onDoubleClick={onDoubleClick}
>
{getStatusComponent()}
{!!label?.length && <span className="text-aqua-pale text-large ml-1">{label}</span>}
<div className="border-secondary-light mx-2 border-l py-2"></div>
<span
data-cy="studyDate"
className="text-white"
>
{studyDate}
</span>
<div className="border-secondary-light mx-2 border-l py-2"></div>
<span className="text-aqua-pale mr-1 overflow-hidden text-ellipsis">{seriesDescription}</span>
{/* Prev/Next icons */}
<Icons.ByName
className="hover:text-primary-light ml-auto mr-2 cursor-pointer text-white"
name="chevron-prev"
onClick={() => onArrowsClick('left')}
/>
<Icons.ByName
className="hover:text-primary-light mr-2 cursor-pointer text-white"
name="chevron-next"
onClick={() => onArrowsClick('right')}
/>
{/* Patient Info */}
<div onClick={() => setShowPatientInfo(!showPatientInfo)}>
<PatientInfo
showPatientInfoRef={showPatientInfoElemRef}
isOpen={showPatientInfo}
patientName={patientName}
patientSex={patientSex}
patientAge={patientAge}
MRN={MRN}
thickness={thickness}
thicknessUnits={thicknessUnits}
spacing={spacing}
scanner={scanner}
/>
</div>
</div>
);
}
ViewportActionBar.propTypes = {
onArrowsClick: PropTypes.func.isRequired,
onDoubleClick: PropTypes.func,
studyData: PropTypes.shape({
label: PropTypes.string.isRequired,
studyDate: PropTypes.string.isRequired,
seriesDescription: PropTypes.string.isRequired,
patientInformation: PropTypes.shape({
patientName: PropTypes.string,
patientSex: PropTypes.string,
patientAge: PropTypes.string,
MRN: PropTypes.string,
thickness: PropTypes.string,
thicknessUnits: PropTypes.string,
spacing: PropTypes.string,
scanner: PropTypes.string,
}),
}).isRequired,
getStatusComponent: PropTypes.func.isRequired,
};
export { ViewportActionBar };
@@ -0,0 +1,31 @@
import React from 'react';
import PropTypes from 'prop-types';
/**
* A button that can trigger commands when clicked.
*/
function ViewportActionButton({ onInteraction, commands, id, children }) {
return (
<div
className="bg-primary-main hover:bg-primary-light ml-1 cursor-pointer rounded px-1.5 hover:text-black"
// Using onMouseUp because onClick wasn't firing if pointer-events are none.
onMouseUp={() => {
onInteraction({
itemId: id,
commands,
});
}}
>
{children}
</div>
);
}
ViewportActionButton.propTypes = {
id: PropTypes.string,
onInteraction: PropTypes.func.isRequired,
commands: PropTypes.array,
children: PropTypes.node,
};
export { ViewportActionButton };
@@ -0,0 +1,67 @@
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
/**
* A small container that can render multiple "corner" items (like icons, status)
* in each corner of the viewport: top-left, top-right, bottom-left, bottom-right.
*/
export enum ViewportActionCornersLocations {
topLeft,
topRight,
bottomLeft,
bottomRight,
}
const commonClasses = 'pointer-events-auto flex items-center gap-1';
const locationClasses = {
[ViewportActionCornersLocations.topLeft]: classNames(
commonClasses,
'absolute top-[4px] left-[0px] pl-[4px]'
),
[ViewportActionCornersLocations.topRight]: classNames(
commonClasses,
'absolute top-[4px] right-[4px] right-viewport-scrollbar'
),
[ViewportActionCornersLocations.bottomLeft]: classNames(
commonClasses,
'absolute bottom-[4px] left-[0px] pl-[4px]'
),
[ViewportActionCornersLocations.bottomRight]: classNames(
commonClasses,
'absolute bottom-[4px] right-[0px] right-viewport-scrollbar'
),
};
function ViewportActionCorners({ cornerComponents }) {
if (!cornerComponents) {
return null;
}
return (
<div
className="pointer-events-none absolute h-full w-full select-none"
onDoubleClick={event => {
event.preventDefault();
event.stopPropagation();
}}
>
{Object.entries(cornerComponents).map(([location, locationArray]) => (
<div
key={location}
className={locationClasses[location]}
>
{locationArray.map(componentInfo => (
<div key={componentInfo.id}>{componentInfo.component}</div>
))}
</div>
))}
</div>
);
}
ViewportActionCorners.propTypes = {
cornerComponents: PropTypes.object.isRequired,
};
export { ViewportActionCorners };
@@ -0,0 +1,30 @@
import React from 'react';
import PropTypes from 'prop-types';
/**
* A minimal top-level container that organizes multiple <ViewportPane>
* children in a grid. Typically driven by a layout config.
*/
function ViewportGrid({ numRows, numCols, layoutType, children }) {
return (
<div
data-cy="viewport-grid"
style={{
position: 'relative',
height: '100%',
width: '100%',
}}
>
{children}
</div>
);
}
ViewportGrid.propTypes = {
numRows: PropTypes.number.isRequired,
numCols: PropTypes.number.isRequired,
layoutType: PropTypes.string,
children: PropTypes.arrayOf(PropTypes.node).isRequired,
};
export { ViewportGrid };
@@ -0,0 +1,22 @@
.imageViewerViewport.empty ~ .ViewportOverlay {
display: none;
}
.ViewportOverlay {
color: #9ccef9;
}
.ViewportOverlay .overlay-element {
position: absolute;
font-weight: 400;
text-shadow: 1px 1px #000;
pointer-events: none;
}
.overlay-top {
top: 28px;
}
.overlay-bottom {
bottom: 3px;
}
.overlay-text {
text-shadow: 0.8px 0.8px 0.5px rgba(0, 0, 0, 0.75);
}
@@ -0,0 +1,69 @@
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import './ViewportOverlay.css';
/**
* Renders text overlays (top-left, top-right, bottom-left, bottom-right)
* around the active viewport for metadata or status messages.
*
* The parent is responsible for styling offsets.
*/
const classes = {
topLeft: 'overlay-top left-viewport',
topRight: 'overlay-top right-viewport-scrollbar',
bottomRight: 'overlay-bottom right-viewport-scrollbar',
bottomLeft: 'overlay-bottom left-viewport',
};
function ViewportOverlay({
topLeft,
topRight,
bottomRight,
bottomLeft,
color = 'text-primary-light',
}) {
const overlay = 'absolute pointer-events-none viewport-overlay';
return (
<div className={classNames(color, 'overlay-text text-[13px] leading-5')}>
<div
data-cy="viewport-overlay-top-left"
className={classNames(overlay, classes.topLeft)}
>
{topLeft}
</div>
<div
data-cy="viewport-overlay-top-right"
className={classNames(overlay, classes.topRight)}
style={{ transform: 'translateX(-8px)' }}
>
{topRight}
</div>
<div
data-cy="viewport-overlay-bottom-right"
className={classNames(overlay, classes.bottomRight)}
style={{ transform: 'translateX(-8px)' }}
>
{bottomRight}
</div>
<div
data-cy="viewport-overlay-bottom-left"
className={classNames(overlay, classes.bottomLeft)}
>
{bottomLeft}
</div>
</div>
);
}
ViewportOverlay.propTypes = {
topLeft: PropTypes.node,
topRight: PropTypes.node,
bottomRight: PropTypes.node,
bottomLeft: PropTypes.node,
color: PropTypes.string,
};
export { ViewportOverlay };
@@ -0,0 +1,97 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { useDrop } from 'react-dnd';
/**
* The "pane" that encloses a Cornerstone or other type of Viewport. This handles
* drag-and-drop for display sets, activation on click, etc.
*/
function ViewportPane({
children,
className,
customStyle,
isActive,
onDrop,
onDoubleClick,
onInteraction = () => {},
acceptDropsFor,
}) {
let dropElement = null;
const [{ isHovered, isHighlighted }, drop] = useDrop({
accept: acceptDropsFor,
drop: (droppedItem, monitor) => {
if (monitor.canDrop() && monitor.isOver() && onDrop) {
onInteraction();
onDrop(droppedItem);
}
},
collect: monitor => ({
isHighlighted: monitor.canDrop(),
isHovered: monitor.isOver(),
}),
});
const focus = () => {
if (dropElement) {
dropElement.focus();
}
};
const onInteractionHandler = event => {
focus();
onInteraction(event);
};
const refHandler = element => {
drop(element);
dropElement = element;
};
return (
<div
ref={refHandler}
onPointerDown={onInteractionHandler}
onDoubleClick={onDoubleClick}
onClick={onInteractionHandler}
onScroll={onInteractionHandler}
onWheel={onInteractionHandler}
className={classNames(
'group/pane h-full w-full overflow-hidden rounded-md transition duration-300',
{
'border-primary-light border-2': isActive,
'border-2 border-transparent': !isActive,
},
className
)}
style={customStyle}
>
<div
className={classNames(
'h-full w-full overflow-hidden rounded-md',
{
'border border-transparent': isActive,
'border-secondary-light group-hover/pane:border-primary-light/70 border': !isActive,
},
className
)}
>
{children}
</div>
</div>
);
}
ViewportPane.propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string,
isActive: PropTypes.bool.isRequired,
acceptDropsFor: PropTypes.string.isRequired,
onDrop: PropTypes.func.isRequired,
onInteraction: PropTypes.func.isRequired,
onDoubleClick: PropTypes.func,
customStyle: PropTypes.object,
};
export { ViewportPane };
@@ -0,0 +1,8 @@
export { ViewportActionButton } from './ViewportActionButton';
export { PatientInfo } from './PatientInfo';
export { ViewportActionBar } from './ViewportActionBar';
export { ViewportActionArrows } from './ViewportActionArrows';
export { ViewportPane } from './ViewportPane';
export { ViewportActionCorners, ViewportActionCornersLocations } from './ViewportActionCorners';
export { ViewportOverlay } from './ViewportOverlay';
export { ViewportGrid } from './ViewportGrid';