2021-03-11 11:25:49 +02:00
|
|
|
import React from 'react';
|
2020-05-20 12:57:03 +02:00
|
|
|
|
2024-03-08 09:59:02 -06:00
|
|
|
import { NOTIFY_CLICK_MODE } from '../../../../toolbox/types';
|
2023-03-30 11:27:53 +03:00
|
|
|
import Icon from '../../../icons/components/Icon';
|
2023-03-17 12:23:51 +02:00
|
|
|
import Tooltip from '../../../tooltip/components/Tooltip';
|
2020-03-30 17:17:18 +03:00
|
|
|
|
2023-03-30 11:27:53 +03:00
|
|
|
interface IProps {
|
2020-03-30 17:17:18 +03:00
|
|
|
|
2022-01-04 13:21:00 +02:00
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* The id of the element this button icon controls.
|
2022-01-04 13:21:00 +02:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
ariaControls?: string;
|
2022-01-04 13:21:00 +02:00
|
|
|
|
2020-03-30 17:17:18 +03:00
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* Whether the element popup is expanded.
|
2020-03-30 17:17:18 +03:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
ariaExpanded?: boolean;
|
2020-03-30 17:17:18 +03:00
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* Whether the element has a popup.
|
2020-03-30 17:17:18 +03:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
ariaHasPopup?: boolean;
|
2020-03-30 17:17:18 +03:00
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* Aria label for the Icon.
|
2020-03-30 17:17:18 +03:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
ariaLabel?: string;
|
2020-03-30 17:17:18 +03:00
|
|
|
|
2022-01-04 13:21:00 +02:00
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* The button's key.
|
2022-01-04 13:21:00 +02:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
buttonKey?: string;
|
2022-01-04 13:21:00 +02:00
|
|
|
|
2020-03-30 17:17:18 +03:00
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* The decorated component (ToolboxButton).
|
2020-03-30 17:17:18 +03:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
children: React.ReactNode;
|
2020-03-30 17:17:18 +03:00
|
|
|
|
2021-02-23 13:09:22 +02:00
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* Icon of the button.
|
2021-02-23 13:09:22 +02:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
icon: Function;
|
2021-02-23 13:09:22 +02:00
|
|
|
|
2020-03-30 17:17:18 +03:00
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* Flag used for disabling the small icon.
|
2020-03-30 17:17:18 +03:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
iconDisabled: boolean;
|
2021-06-10 14:48:44 +02:00
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* The ID of the icon button.
|
2021-06-10 14:48:44 +02:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
iconId: string;
|
2021-06-10 14:48:44 +02:00
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* The tooltip used for the icon.
|
2021-06-10 14:48:44 +02:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
iconTooltip: string;
|
2021-06-10 14:48:44 +02:00
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* Notify mode for `toolbarButtonClicked` event -
|
|
|
|
|
* whether to only notify or to also prevent button click routine.
|
2021-06-10 14:48:44 +02:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
notifyMode?: string;
|
2021-06-10 14:48:44 +02:00
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* Click handler for the small icon.
|
2021-06-10 14:48:44 +02:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
onIconClick: Function;
|
2021-06-10 14:48:44 +02:00
|
|
|
|
|
|
|
|
/**
|
2021-11-04 22:10:43 +01:00
|
|
|
* Keydown handler for icon.
|
2021-06-10 14:48:44 +02:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
onIconKeyDown?: Function;
|
2021-06-10 14:48:44 +02:00
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:27:53 +03:00
|
|
|
* Additional styles.
|
2021-06-10 14:48:44 +02:00
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
styles?: Object;
|
|
|
|
|
}
|
2022-01-04 13:21:00 +02:00
|
|
|
|
2020-03-30 17:17:18 +03:00
|
|
|
/**
|
2021-03-11 11:25:49 +02:00
|
|
|
* Displays the `ToolboxButtonWithIcon` component.
|
2020-03-30 17:17:18 +03:00
|
|
|
*
|
2021-03-11 11:25:49 +02:00
|
|
|
* @param {Object} props - Component's props.
|
2020-03-30 17:17:18 +03:00
|
|
|
* @returns {ReactElement}
|
|
|
|
|
*/
|
2023-03-30 11:27:53 +03:00
|
|
|
export default function ToolboxButtonWithIcon(props: IProps) {
|
2021-03-11 11:25:49 +02:00
|
|
|
const {
|
|
|
|
|
children,
|
|
|
|
|
icon,
|
|
|
|
|
iconDisabled,
|
|
|
|
|
iconTooltip,
|
2022-01-04 13:21:00 +02:00
|
|
|
buttonKey,
|
|
|
|
|
notifyMode,
|
2021-03-11 11:25:49 +02:00
|
|
|
onIconClick,
|
2021-06-10 14:48:44 +02:00
|
|
|
onIconKeyDown,
|
|
|
|
|
styles,
|
|
|
|
|
ariaLabel,
|
|
|
|
|
ariaHasPopup,
|
|
|
|
|
ariaControls,
|
|
|
|
|
ariaExpanded,
|
|
|
|
|
iconId
|
2021-03-11 11:25:49 +02:00
|
|
|
} = props;
|
|
|
|
|
|
2023-05-17 13:05:47 +03:00
|
|
|
const iconProps: {
|
|
|
|
|
ariaControls?: string;
|
|
|
|
|
ariaExpanded?: boolean;
|
|
|
|
|
containerId?: string;
|
|
|
|
|
onClick?: (e?: React.MouseEvent) => void;
|
|
|
|
|
onKeyDown?: Function;
|
|
|
|
|
role?: string;
|
|
|
|
|
tabIndex?: number;
|
|
|
|
|
} = {};
|
2023-03-17 12:23:51 +02:00
|
|
|
let className = '';
|
2021-03-11 11:25:49 +02:00
|
|
|
|
|
|
|
|
if (iconDisabled) {
|
2023-03-17 12:23:51 +02:00
|
|
|
className
|
2021-03-11 11:25:49 +02:00
|
|
|
= 'settings-button-small-icon settings-button-small-icon--disabled';
|
|
|
|
|
} else {
|
2023-03-17 12:23:51 +02:00
|
|
|
className = 'settings-button-small-icon';
|
2023-05-17 13:05:47 +03:00
|
|
|
iconProps.onClick = (e?: React.MouseEvent) => {
|
2022-01-04 13:21:00 +02:00
|
|
|
if (typeof APP !== 'undefined' && notifyMode) {
|
|
|
|
|
APP.API.notifyToolbarButtonClicked(
|
|
|
|
|
buttonKey, notifyMode === NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (notifyMode !== NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY) {
|
2023-04-07 12:26:56 +03:00
|
|
|
onIconClick(e);
|
2022-01-04 13:21:00 +02:00
|
|
|
}
|
|
|
|
|
};
|
2021-06-10 14:48:44 +02:00
|
|
|
iconProps.onKeyDown = onIconKeyDown;
|
|
|
|
|
iconProps.role = 'button';
|
|
|
|
|
iconProps.tabIndex = 0;
|
|
|
|
|
iconProps.ariaControls = ariaControls;
|
|
|
|
|
iconProps.ariaExpanded = ariaExpanded;
|
|
|
|
|
iconProps.containerId = iconId;
|
2020-03-30 17:17:18 +03:00
|
|
|
}
|
|
|
|
|
|
2020-03-30 17:44:45 +03:00
|
|
|
|
2021-03-11 11:25:49 +02:00
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className = 'settings-button-container'
|
2023-03-30 11:27:53 +03:00
|
|
|
style = { styles }>
|
2021-03-11 11:25:49 +02:00
|
|
|
{children}
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<Tooltip
|
2023-03-17 12:23:51 +02:00
|
|
|
containerClassName = { className }
|
2021-03-11 11:25:49 +02:00
|
|
|
content = { iconTooltip }
|
|
|
|
|
position = 'top'>
|
|
|
|
|
<Icon
|
|
|
|
|
{ ...iconProps }
|
2021-06-10 14:48:44 +02:00
|
|
|
ariaHasPopup = { ariaHasPopup }
|
|
|
|
|
ariaLabel = { ariaLabel }
|
2022-11-08 12:24:32 +02:00
|
|
|
size = { 16 }
|
2021-03-11 11:25:49 +02:00
|
|
|
src = { icon } />
|
|
|
|
|
</Tooltip>
|
2020-03-30 17:44:45 +03:00
|
|
|
</div>
|
2021-03-11 11:25:49 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
2020-03-30 17:17:18 +03:00
|
|
|
}
|