2022-08-25 11:35:19 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2018-03-07 00:28:19 +00:00
|
|
|
import InlineDialog from '@atlaskit/inline-dialog';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { withStyles } from '@mui/styles';
|
2022-08-25 11:35:19 +00:00
|
|
|
import React, { Component, ReactElement } from 'react';
|
|
|
|
import { WithTranslation } from 'react-i18next';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { connect } from 'react-redux';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2022-09-07 08:20:05 +00:00
|
|
|
import { createToolbarEvent } from '../../../analytics/AnalyticsEvents';
|
|
|
|
import { sendAnalytics } from '../../../analytics/functions';
|
2022-09-05 11:24:13 +00:00
|
|
|
import { IState } from '../../../app/types';
|
2022-08-25 11:35:19 +00:00
|
|
|
import { translate } from '../../../base/i18n/functions';
|
|
|
|
// @ts-ignore
|
2021-07-13 06:50:08 +00:00
|
|
|
import { ReactionEmoji, ReactionsMenu } from '../../../reactions/components';
|
2022-09-27 07:10:28 +00:00
|
|
|
import { REACTIONS_MENU_HEIGHT, type ReactionEmojiProps } from '../../../reactions/constants';
|
2021-07-13 06:50:08 +00:00
|
|
|
import { getReactionsQueue } from '../../../reactions/functions.any';
|
2022-04-05 12:19:03 +00:00
|
|
|
import { DRAWER_MAX_HEIGHT } from '../../constants';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-01-04 13:30:23 +00:00
|
|
|
import Drawer from './Drawer';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2021-10-04 14:07:05 +00:00
|
|
|
import JitsiPortal from './JitsiPortal';
|
2022-08-25 11:35:19 +00:00
|
|
|
// @ts-ignore
|
2022-01-04 11:21:00 +00:00
|
|
|
import OverflowToggleButton from './OverflowToggleButton';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of {@link OverflowMenuButton}.
|
2018-03-07 00:28:19 +00:00
|
|
|
*/
|
2022-08-25 11:35:19 +00:00
|
|
|
interface Props extends WithTranslation {
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
/**
|
|
|
|
* ID of the menu that is controlled by this button.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
ariaControls: String;
|
2021-06-10 12:48:44 +00:00
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* A child React Element to display within {@code InlineDialog}.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
children: ReactElement;
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2022-04-05 12:19:03 +00:00
|
|
|
/**
|
|
|
|
* An object containing the CSS classes.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
classes: any;
|
2022-04-05 12:19:03 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the OverflowMenu popover should display.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
isOpen: boolean;
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
2021-03-16 15:59:33 +00:00
|
|
|
* Callback to change the visibility of the overflow menu.
|
2018-03-07 00:28:19 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onVisibilityChange: Function;
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2021-01-04 13:30:23 +00:00
|
|
|
/**
|
|
|
|
* Whether to display the OverflowMenu as a drawer.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
overflowDrawer: boolean;
|
2021-01-04 13:30:23 +00:00
|
|
|
|
2021-07-13 06:50:08 +00:00
|
|
|
/**
|
|
|
|
* The array of reactions to be displayed.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
reactionsQueue: Array<ReactionEmojiProps>;
|
2021-07-13 06:50:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not to display the reactions in the mobile menu.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
showMobileReactions: boolean;
|
2022-08-25 11:35:19 +00:00
|
|
|
}
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2022-04-05 12:19:03 +00:00
|
|
|
const styles = () => {
|
|
|
|
return {
|
|
|
|
overflowMenuDrawer: {
|
2022-09-13 07:36:00 +00:00
|
|
|
overflowY: 'auto' as const,
|
2022-04-05 12:19:03 +00:00
|
|
|
height: `calc(${DRAWER_MAX_HEIGHT} - ${REACTIONS_MENU_HEIGHT}px - 16px)`
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* A React {@code Component} for opening or closing the {@code OverflowMenu}.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
|
|
|
class OverflowMenuButton extends Component<Props> {
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code OverflowMenuButton} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
constructor(props: Props) {
|
2018-03-07 00:28:19 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._onCloseDialog = this._onCloseDialog.bind(this);
|
2022-01-04 11:21:00 +00:00
|
|
|
this._toggleDialogVisibility
|
|
|
|
= this._toggleDialogVisibility.bind(this);
|
2021-06-10 12:48:44 +00:00
|
|
|
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}
|
|
|
|
*/
|
2022-08-25 11:35:19 +00:00
|
|
|
_onEscClick(event: React.KeyboardEvent) {
|
2021-06-10 12:48:44 +00:00
|
|
|
if (event.key === 'Escape' && this.props.isOpen) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
this._onCloseDialog();
|
|
|
|
}
|
2018-03-07 00:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2022-04-05 12:19:03 +00:00
|
|
|
const { children, classes, isOpen, overflowDrawer, reactionsQueue, showMobileReactions } = this.props;
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
return (
|
2022-04-05 12:19:03 +00:00
|
|
|
<div className = 'toolbox-button-wth-dialog context-menu'>
|
2021-01-04 13:30:23 +00:00
|
|
|
{
|
|
|
|
overflowDrawer ? (
|
|
|
|
<>
|
2022-01-04 11:21:00 +00:00
|
|
|
<OverflowToggleButton
|
|
|
|
handleClick = { this._toggleDialogVisibility }
|
|
|
|
isOpen = { isOpen }
|
|
|
|
onKeyDown = { this._onEscClick } />
|
2021-10-04 14:07:05 +00:00
|
|
|
<JitsiPortal>
|
2021-01-04 13:30:23 +00:00
|
|
|
<Drawer
|
|
|
|
isOpen = { isOpen }
|
|
|
|
onClose = { this._onCloseDialog }>
|
2022-08-25 11:35:19 +00:00
|
|
|
<>
|
|
|
|
<div className = { classes.overflowMenuDrawer }>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
{showMobileReactions && <ReactionsMenu overflowMenu = { true } />}
|
|
|
|
</>
|
2021-01-04 13:30:23 +00:00
|
|
|
</Drawer>
|
2021-07-13 06:50:08 +00:00
|
|
|
{showMobileReactions && <div className = 'reactions-animations-container'>
|
|
|
|
{reactionsQueue.map(({ reaction, uid }, index) => (<ReactionEmoji
|
|
|
|
index = { index }
|
|
|
|
key = { uid }
|
|
|
|
reaction = { reaction }
|
|
|
|
uid = { uid } />))}
|
|
|
|
</div>}
|
2021-10-04 14:07:05 +00:00
|
|
|
</JitsiPortal>
|
2021-01-04 13:30:23 +00:00
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<InlineDialog
|
|
|
|
content = { children }
|
|
|
|
isOpen = { isOpen }
|
|
|
|
onClose = { this._onCloseDialog }
|
2021-01-14 16:12:08 +00:00
|
|
|
placement = 'top-end'>
|
2022-01-04 11:21:00 +00:00
|
|
|
<OverflowToggleButton
|
|
|
|
handleClick = { this._toggleDialogVisibility }
|
|
|
|
isOpen = { isOpen }
|
|
|
|
onKeyDown = { this._onEscClick } />
|
2021-01-04 13:30:23 +00:00
|
|
|
</InlineDialog>
|
|
|
|
)
|
|
|
|
}
|
2018-03-07 00:28:19 +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}
|
|
|
|
*/
|
2022-01-04 11:21:00 +00:00
|
|
|
_toggleDialogVisibility() {
|
2018-04-20 11:24:14 +00:00
|
|
|
sendAnalytics(createToolbarEvent('overflow'));
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
this.props.onVisibilityChange(!this.props.isOpen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:30:23 +00:00
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated props for the
|
|
|
|
* {@code OverflowMenuButton} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
function mapStateToProps(state: IState) {
|
2021-01-04 13:30:23 +00:00
|
|
|
const { overflowDrawer } = state['features/toolbox'];
|
|
|
|
|
|
|
|
return {
|
2021-07-13 06:50:08 +00:00
|
|
|
overflowDrawer,
|
|
|
|
reactionsQueue: getReactionsQueue(state)
|
2021-01-04 13:30:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-05 12:19:03 +00:00
|
|
|
export default withStyles(styles)(translate(connect(mapStateToProps)(OverflowMenuButton)));
|