2022-08-26 18:25:04 +00:00
|
|
|
import React, { Component } from 'react';
|
2022-09-06 17:32:20 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2022-08-26 18:25:04 +00:00
|
|
|
|
2022-09-07 08:20:05 +00:00
|
|
|
import { createToolbarEvent } from '../../../analytics/AnalyticsEvents';
|
|
|
|
import { sendAnalytics } from '../../../analytics/functions';
|
2022-09-06 17:32:20 +00:00
|
|
|
import { translate } from '../../../base/i18n/functions';
|
2022-10-25 13:11:55 +00:00
|
|
|
import Popover from '../../../base/popover/components/Popover.web';
|
2022-08-26 18:25:04 +00:00
|
|
|
|
|
|
|
import HangupToggleButton from './HangupToggleButton';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link HangupMenuButton}.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
interface IProps extends WithTranslation {
|
2022-08-26 18:25:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ID of the menu that is controlled by this button.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
ariaControls: String;
|
2022-08-26 18:25:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A child React Element to display within {@code InlineDialog}.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
children: React.ReactNode;
|
2022-08-26 18:25:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the HangupMenu popover should display.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
isOpen: boolean;
|
2022-08-26 18:25:04 +00:00
|
|
|
|
2022-09-14 16:42:30 +00:00
|
|
|
/**
|
|
|
|
* Notify mode for `toolbarButtonClicked` event -
|
|
|
|
* whether to only notify or to also prevent button click routine.
|
|
|
|
*/
|
|
|
|
notifyMode?: string;
|
|
|
|
|
2022-08-26 18:25:04 +00:00
|
|
|
/**
|
|
|
|
* Callback to change the visibility of the hangup menu.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onVisibilityChange: Function;
|
2022-09-06 17:32:20 +00:00
|
|
|
}
|
2022-08-26 18:25:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A React {@code Component} for opening or closing the {@code HangupMenu}.
|
|
|
|
*
|
|
|
|
* @augments Component
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
class HangupMenuButton extends Component<IProps> {
|
2022-08-26 18:25:04 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code HangupMenuButton} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
constructor(props: IProps) {
|
2022-08-26 18:25:04 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._onCloseDialog = this._onCloseDialog.bind(this);
|
|
|
|
this._toggleDialogVisibility
|
|
|
|
= this._toggleDialogVisibility.bind(this);
|
|
|
|
this._onEscClick = this._onEscClick.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click handler for the more actions entries.
|
|
|
|
*
|
|
|
|
* @param {KeyboardEvent} event - Esc key click to close the popup.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onEscClick(event: KeyboardEvent) {
|
|
|
|
if (event.key === 'Escape' && this.props.isOpen) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
this._onCloseDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2023-02-28 10:21:15 +00:00
|
|
|
const { children, isOpen, t } = this.props;
|
2022-08-26 18:25:04 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className = 'toolbox-button-wth-dialog context-menu'>
|
2022-10-25 13:11:55 +00:00
|
|
|
<Popover
|
2022-08-26 18:25:04 +00:00
|
|
|
content = { children }
|
2023-02-28 10:21:15 +00:00
|
|
|
headingLabel = { t('toolbar.accessibilityLabel.hangup') }
|
2022-10-25 13:11:55 +00:00
|
|
|
onPopoverClose = { this._onCloseDialog }
|
|
|
|
position = 'top'
|
|
|
|
trigger = 'click'
|
|
|
|
visible = { isOpen }>
|
2022-08-26 18:25:04 +00:00
|
|
|
<HangupToggleButton
|
2022-09-14 16:42:30 +00:00
|
|
|
buttonKey = 'hangup-menu'
|
2022-08-26 18:25:04 +00:00
|
|
|
customClass = 'hangup-menu-button'
|
|
|
|
handleClick = { this._toggleDialogVisibility }
|
|
|
|
isOpen = { isOpen }
|
2022-09-14 16:42:30 +00:00
|
|
|
notifyMode = { this.props.notifyMode }
|
2022-08-26 18:25:04 +00:00
|
|
|
onKeyDown = { this._onEscClick } />
|
2022-10-25 13:11:55 +00:00
|
|
|
</Popover>
|
2022-08-26 18:25:04 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked when {@code InlineDialog} signals that it should be
|
|
|
|
* close.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onCloseDialog() {
|
|
|
|
this.props.onVisibilityChange(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked to signal that an event has occurred that should change
|
|
|
|
* the visibility of the {@code InlineDialog} component.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_toggleDialogVisibility() {
|
|
|
|
sendAnalytics(createToolbarEvent('hangup'));
|
|
|
|
|
|
|
|
this.props.onVisibilityChange(!this.props.isOpen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(HangupMenuButton);
|