2018-10-30 05:02:23 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
import InlineDialog from '@atlaskit/inline-dialog';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
2018-05-10 23:01:55 +00:00
|
|
|
import { createToolbarEvent, sendAnalytics } from '../../../analytics';
|
|
|
|
import { translate } from '../../../base/i18n';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2018-04-10 03:27:19 +00:00
|
|
|
import ToolbarButton from './ToolbarButton';
|
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
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
type Props = {
|
|
|
|
|
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}.
|
|
|
|
*/
|
|
|
|
children: React$Node,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the OverflowMenu popover should display.
|
|
|
|
*/
|
|
|
|
isOpen: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calback to change the visibility of the overflow menu.
|
2018-03-07 00:28:19 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
onVisibilityChange: Function,
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A React {@code Component} for opening or closing the {@code OverflowMenu}.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
this._onToggleDialogVisibility
|
|
|
|
= this._onToggleDialogVisibility.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { children, isOpen, t } = this.props;
|
|
|
|
const iconClasses = `icon-thumb-menu ${isOpen ? 'toggled' : ''}`;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className = 'toolbox-button-wth-dialog'>
|
|
|
|
<InlineDialog
|
|
|
|
content = { children }
|
|
|
|
isOpen = { isOpen }
|
|
|
|
onClose = { this._onCloseDialog }
|
|
|
|
position = { 'top right' }>
|
2018-04-10 03:27:19 +00:00
|
|
|
<ToolbarButton
|
2018-06-07 20:32:18 +00:00
|
|
|
accessibilityLabel =
|
|
|
|
{ t('toolbar.accessibilityLabel.moreActions') }
|
2018-03-07 00:28:19 +00:00
|
|
|
iconName = { iconClasses }
|
|
|
|
onClick = { this._onToggleDialogVisibility }
|
|
|
|
tooltip = { t('toolbar.moreActions') } />
|
|
|
|
</InlineDialog>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onCloseDialog: () => void;
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Callback invoked when {@code InlineDialog} signals that it should be
|
|
|
|
* close.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onCloseDialog() {
|
|
|
|
this.props.onVisibilityChange(false);
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onToggleDialogVisibility: () => void;
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Callback invoked to signal that an event has occurred that should change
|
|
|
|
* the visibility of the {@code InlineDialog} component.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onToggleDialogVisibility() {
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(OverflowMenuButton);
|