ohif-viewer/platform/ui/src/components/ToolbarButton/ToolbarButton.jsx

82 lines
2.1 KiB
React
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { IconButton, Icon, Tooltip } from '../';
const ToolbarButton = ({
type,
id,
icon,
label,
commandName,
commandOptions,
onInteraction,
dropdownContent,
//
isActive: _isActive,
bState = {},
//
}) => {
const { primaryToolId, toggles, groups } = bState;
const isActive = _isActive || (type === 'tool' && id === primaryToolId);
const classes = {
type: {
primary: isActive
? 'text-black'
: 'text-common-bright hover:bg-primary-dark hover:text-primary-light',
secondary: isActive
? 'text-black'
: 'text-white hover:bg-secondary-dark hover:text-white focus:bg-secondary-dark focus:text-white',
},
};
const shouldShowDropdown = !!isActive && !!dropdownContent;
return (
<div key={id}>
<Tooltip
isSticky={shouldShowDropdown}
content={shouldShowDropdown ? dropdownContent : label}
tight={shouldShowDropdown}
>
<IconButton
variant={isActive ? 'contained' : 'text'}
fix/chore: Various style improvements (#2015) * Update all the icons * Turn off global tool sync; watch as the world burns * Shift a bunch of things around so we can start tracking/setting per element * ToolBarService to initiate one of three different calls; callback passed to all button types * SplitButton and Toolbar Button to use new `onInteraction` prop and new toolbar state * Changes to toolbar button interface and config * Fix broken layout selector * Update SR viewport to activate tools in viewport component * Duplicate activation logic in measurement tracking extension * Add alternative/dashed variants for SR Viewport * pass through "setToolActive" commands for other viewport types * fix small overlay bugs (no wwwc or scale info) * Show SpacingBetweenSlices instead of PixelSpacing in patient information dialog * Fix prop-types * Update tracked viewport to have alternative tracked styling * alt styling for SR viewports * Update to support isLocked + isRehydratable * fix broken logic * fix broken logic * switch icon style * fix icon styles * hover and click to start flow * expedited workflow when data is not dirty (just after SR hydration) * fix: setting elliptical roi tool * fix arrow annotate dialog * fix: do not show learn more button for now * remove dead code * simpler cache invalidation * simpler cache invalidation part 2 * Fix for unable to spand study cards on separate pages * fix: viewport grid area top padding should align with sidepanel gap * fix: don't wrap split button list item text * fix: cine player moz/chrome styles * fix: split button arrows * fix: tighten toolbar and splitbutton styles * chore: clean up worklist sort logic
2020-09-21 10:42:53 +02:00
size="toolbar"
className={classnames('mx-1', classes.type[type])}
onClick={() => {
onInteraction({
itemId: id,
interactionType: type,
commandName: commandName,
commandOptions: commandOptions,
});
}}
key={id}
>
<Icon name={icon} />
</IconButton>
</Tooltip>
</div>
);
};
ToolbarButton.defaultProps = {
dropdownContent: null,
isActive: false,
type: 'action',
};
ToolbarButton.propTypes = {
/* Influences background/hover styling */
type: PropTypes.oneOf(['action', 'toggle', 'tool']),
id: PropTypes.string.isRequired,
isActive: PropTypes.bool,
onInteraction: PropTypes.func.isRequired,
icon: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
/** Tooltip content can be replaced for a customized content by passing a node to this value. */
dropdownContent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
};
export default ToolbarButton;