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