feat: Tooltip, ToolbarButton, Toolbar API and misc
This commit is contained in:
1 parent
3223d6a8a1
commit
9154f36477
15 files changed
+580
-290
No files matched your search
@@ -1,96 +1,78 @@
|
||||
import React, { useState } from 'react';
|
||||
import classnames from 'classnames';
|
||||
import { NavBar, Svg, Icon, IconButton } from '@ohif/ui';
|
||||
import { NavBar, Svg, Icon, IconButton, PrimaryToolbar } from '@ohif/ui';
|
||||
|
||||
const Header = () => {
|
||||
const [activeTool, setActiveTool] = useState(null);
|
||||
const [showTooltip, setShowTooltip] = useState(null);
|
||||
const [activeTool, setActiveTool] = useState('Zoom');
|
||||
const dropdownContent = [
|
||||
{
|
||||
name: 'Soft tissue',
|
||||
value: '400/40',
|
||||
},
|
||||
{ name: 'Lung', value: '1500 / -600' },
|
||||
{ name: 'Liver', value: '150 / 90' },
|
||||
{ name: 'Bone', value: '2500 / 480' },
|
||||
{ name: 'Brain', value: '80 / 40' },
|
||||
];
|
||||
const tools = [
|
||||
{
|
||||
id: 'Zoom',
|
||||
label: 'Zoom',
|
||||
icon: 'tool-zoom',
|
||||
type: null,
|
||||
commandName: 'setToolActive',
|
||||
commandOptions: { toolName: 'Zoom' },
|
||||
onClick: () => setActiveTool('Zoom'),
|
||||
},
|
||||
{
|
||||
id: 'Wwwc',
|
||||
label: 'Levels',
|
||||
icon: 'tool-window-level',
|
||||
type: null,
|
||||
commandName: 'setToolActive',
|
||||
commandOptions: { toolName: 'Wwwc' },
|
||||
onClick: () => setActiveTool('Wwwc'),
|
||||
dropdownContent: (
|
||||
<div>
|
||||
{dropdownContent.map((row, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="flex justify-between py-2 px-3 hover:bg-secondary-dark cursor-pointer"
|
||||
>
|
||||
<div>
|
||||
<span className="text-base text-white">{row.name}</span>
|
||||
<span className="text-base text-primary-light ml-3">
|
||||
{row.value}
|
||||
</span>
|
||||
</div>
|
||||
<span className="text-base text-primary-active ml-4">{i}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'Pan',
|
||||
label: 'Pan',
|
||||
icon: 'tool-move',
|
||||
type: null,
|
||||
commandName: 'setToolActive',
|
||||
commandOptions: { toolName: 'Pan' },
|
||||
onClick: () => setActiveTool('Pan'),
|
||||
},
|
||||
{
|
||||
id: 'Capture',
|
||||
label: 'Capture',
|
||||
icon: 'tool-capture',
|
||||
type: null,
|
||||
commandName: 'setToolActive',
|
||||
commandOptions: { toolName: 'Capture' },
|
||||
onClick: () => setActiveTool('Capture'),
|
||||
},
|
||||
{
|
||||
id: 'Layout',
|
||||
label: 'Layout',
|
||||
icon: 'tool-layout',
|
||||
type: null,
|
||||
commandName: 'setToolActive',
|
||||
commandOptions: { toolName: 'Layout' },
|
||||
onClick: () => setActiveTool('Layout'),
|
||||
},
|
||||
];
|
||||
const renderToolbar = () => {
|
||||
return tools.map((tool, i) => {
|
||||
const isActive = activeTool === tool.id;
|
||||
const shouldShowTooltip = showTooltip === tool.id;
|
||||
return (
|
||||
<div className="relative flex justify-center" key={tool.id}>
|
||||
<IconButton
|
||||
variant={isActive ? 'contained' : 'text'}
|
||||
className={classnames('mx-1', {
|
||||
'text-black': isActive,
|
||||
'text-common-bright hover:bg-primary-dark hover:text-primary-light': !isActive,
|
||||
})}
|
||||
onClick={(e) => {
|
||||
setActiveTool(tool.id);
|
||||
}}
|
||||
onMouseOver={() => setShowTooltip(tool.id)}
|
||||
onMouseOut={() => setShowTooltip(null)}
|
||||
key={tool.id}
|
||||
>
|
||||
<Icon name={tool.icon} />
|
||||
</IconButton>
|
||||
{shouldShowTooltip && (
|
||||
<div
|
||||
className={classnames(
|
||||
'tooltip tooltip-up bg-primary-dark border border-secondary-main text-white text-base rounded py-1 px-4 inset-x-auto top-full mt-2 w-max-content'
|
||||
)}
|
||||
>
|
||||
{tool.label}
|
||||
<svg
|
||||
className="absolute text-primary-dark w-full h-4 left-0 stroke-secondary-main"
|
||||
style={{ top: -15 }}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path fill="currentColor" d="M24 22h-24l12-20z" />
|
||||
</svg>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
};
|
||||
return (
|
||||
<NavBar className="justify-between border-b-4 border-black">
|
||||
<div className="flex flex-1 justify-between">
|
||||
@@ -107,21 +89,11 @@ const Header = () => {
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<div className="flex items-center">
|
||||
{renderToolbar()}
|
||||
<span className="w-1 border-l py-4 mx-2 border-common-dark" />
|
||||
<IconButton
|
||||
className={classnames(
|
||||
'mx-1 text-common-bright hover:bg-primary-dark hover:text-primary-light'
|
||||
)}
|
||||
color="inherit"
|
||||
onClick={(e) => {
|
||||
alert('Open menu');
|
||||
}}
|
||||
>
|
||||
<Icon name="tool-more-menu" />
|
||||
</IconButton>
|
||||
</div>
|
||||
<PrimaryToolbar
|
||||
tools={tools}
|
||||
activeTool={activeTool}
|
||||
moreTools={tools}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<span className="mr-3 text-common-light text-lg">
|
||||
|
||||
Reference in new issue
Block a user