2020-04-16 18:19:37 -03:00
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
2024-03-28 16:45:11 -04:00
|
|
|
import classNames from 'classnames';
|
2020-04-16 18:19:37 -03:00
|
|
|
|
2023-06-07 10:05:35 -03:00
|
|
|
import IconButton from '../IconButton';
|
|
|
|
|
import Icon from '../Icon';
|
|
|
|
|
import Tooltip from '../Tooltip';
|
2020-04-16 18:19:37 -03:00
|
|
|
|
|
|
|
|
const ToolbarButton = ({
|
|
|
|
|
id,
|
|
|
|
|
icon,
|
|
|
|
|
label,
|
2022-07-27 16:39:04 +00:00
|
|
|
commands,
|
2020-09-14 21:18:46 -04:00
|
|
|
onInteraction,
|
2024-05-27 14:30:25 -04:00
|
|
|
dropdownContent = null,
|
2020-09-14 21:18:46 -04:00
|
|
|
//
|
2023-01-06 15:00:23 -05:00
|
|
|
className,
|
2024-03-28 16:45:11 -04:00
|
|
|
disabled,
|
2024-04-02 23:33:04 -04:00
|
|
|
disabledText,
|
2024-03-27 16:01:32 -04:00
|
|
|
size,
|
|
|
|
|
toolTipClassName,
|
2024-03-28 10:40:32 -04:00
|
|
|
disableToolTip = false,
|
2023-01-06 15:00:23 -05:00
|
|
|
...rest
|
2020-09-14 21:18:46 -04:00
|
|
|
//
|
2020-04-16 18:19:37 -03:00
|
|
|
}) => {
|
2024-03-27 16:01:32 -04:00
|
|
|
const shouldShowDropdown = !!dropdownContent;
|
2023-09-01 16:19:39 -04:00
|
|
|
const iconEl = icon ? <Icon name={icon} /> : <div>{label || 'Missing icon and label'}</div>;
|
2020-06-24 12:11:54 -03:00
|
|
|
|
2024-03-27 16:01:32 -04:00
|
|
|
const sizeToUse = size ?? 'toolbar';
|
|
|
|
|
const toolTipClassNameToUse =
|
|
|
|
|
toolTipClassName !== undefined
|
|
|
|
|
? toolTipClassName
|
|
|
|
|
: sizeToUse === 'toolbar'
|
|
|
|
|
? 'w-[40px] h-[40px]'
|
2024-04-16 10:31:06 -02:30
|
|
|
: 'w-[32px] h-[32px]';
|
2024-03-27 16:01:32 -04:00
|
|
|
|
2020-04-16 18:19:37 -03:00
|
|
|
return (
|
|
|
|
|
<div key={id}>
|
|
|
|
|
<Tooltip
|
2020-06-14 23:42:44 -04:00
|
|
|
isSticky={shouldShowDropdown}
|
2020-04-16 18:19:37 -03:00
|
|
|
content={shouldShowDropdown ? dropdownContent : label}
|
2024-04-17 16:12:40 -02:30
|
|
|
secondaryContent={disabled ? disabledText : null}
|
2020-04-16 18:19:37 -03:00
|
|
|
tight={shouldShowDropdown}
|
2024-03-27 16:01:32 -04:00
|
|
|
className={toolTipClassNameToUse}
|
2024-03-28 10:40:32 -04:00
|
|
|
isDisabled={disableToolTip}
|
2020-04-16 18:19:37 -03:00
|
|
|
>
|
|
|
|
|
<IconButton
|
2024-03-27 16:01:32 -04:00
|
|
|
size={sizeToUse}
|
2024-04-17 16:12:40 -02:30
|
|
|
className={classNames(className, disabled ? 'ohif-disabled' : '')}
|
2020-09-14 21:18:46 -04:00
|
|
|
onClick={() => {
|
|
|
|
|
onInteraction({
|
|
|
|
|
itemId: id,
|
2022-07-27 16:39:04 +00:00
|
|
|
commands,
|
2020-09-14 21:18:46 -04:00
|
|
|
});
|
|
|
|
|
}}
|
2021-03-01 16:52:54 +01:00
|
|
|
name={label}
|
2020-04-16 18:19:37 -03:00
|
|
|
key={id}
|
2021-03-01 16:52:54 +01:00
|
|
|
id={id}
|
2023-01-06 15:00:23 -05:00
|
|
|
{...rest}
|
2020-04-16 18:19:37 -03:00
|
|
|
>
|
2023-03-15 12:41:41 -04:00
|
|
|
{iconEl}
|
2020-04-16 18:19:37 -03:00
|
|
|
</IconButton>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ToolbarButton.propTypes = {
|
2020-06-14 21:57:45 -04:00
|
|
|
/* Influences background/hover styling */
|
2020-04-16 18:19:37 -03:00
|
|
|
id: PropTypes.string.isRequired,
|
2023-09-22 10:23:44 -04:00
|
|
|
className: PropTypes.string,
|
2024-03-27 16:01:32 -04:00
|
|
|
commands: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
|
|
|
|
|
onInteraction: PropTypes.func,
|
2020-04-16 18:19:37 -03:00
|
|
|
icon: PropTypes.string.isRequired,
|
|
|
|
|
label: PropTypes.string.isRequired,
|
|
|
|
|
/** Tooltip content can be replaced for a customized content by passing a node to this value. */
|
2020-06-15 00:51:36 -04:00
|
|
|
dropdownContent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
2024-03-27 16:01:32 -04:00
|
|
|
size: PropTypes.string,
|
|
|
|
|
toolTipClassName: PropTypes.string,
|
2024-03-28 10:40:32 -04:00
|
|
|
disableToolTip: PropTypes.bool,
|
2024-03-28 16:45:11 -04:00
|
|
|
disabled: PropTypes.bool,
|
2020-04-16 18:19:37 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ToolbarButton;
|