Skip to content

Commit

Permalink
feat(tooltips): convert popup tooltips to InlineDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuacoplenny authored and yanas committed Aug 21, 2017
1 parent c3a4a38 commit e3361e2
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 80 deletions.
12 changes: 8 additions & 4 deletions conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -1263,21 +1263,24 @@ export default {
* @returns {void}
*/
_displayAudioOnlyTooltip(featureName) {
let buttonName = null;
let tooltipElementId = null;

switch (featureName) {
case 'screenShare':
tooltipElementId = '#screenshareWhileAudioOnly';
buttonName = 'desktop';
tooltipElementId = 'screenshareWhileAudioOnly';
break;
case 'videoMute':
tooltipElementId = '#unmuteWhileAudioOnly';
buttonName = 'camera';
tooltipElementId = 'unmuteWhileAudioOnly';
break;
}

if (tooltipElementId) {
APP.UI.showToolbar(6000);
APP.UI.showCustomToolbarPopup(
tooltipElementId, true, 5000);
buttonName, tooltipElementId, true, 5000);
}
},

Expand Down Expand Up @@ -1697,7 +1700,8 @@ export default {
room.on(ConferenceEvents.TALK_WHILE_MUTED, () => {
APP.UI.showToolbar(6000);

APP.UI.showCustomToolbarPopup('#talkWhileMutedPopup', true, 5000);
APP.UI.showCustomToolbarPopup(
'microphone', 'talkWhileMutedPopup', true, 5000);
});

room.on(
Expand Down
4 changes: 2 additions & 2 deletions css/_toolbars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@

@include transform(translateX(-50%));

.button:first-child {
> div:first-child .button {
border-bottom-left-radius: 3px;
border-top-left-radius: 3px;
}
.button:last-child {
> div:last-child .button {
border-bottom-right-radius: 3px;
border-top-right-radius: 3px;
}
Expand Down
4 changes: 2 additions & 2 deletions lang/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
"login": "Login",
"logout": "Logout",
"dialpad": "Open / Close dialpad",
"sharedVideoMutedPopup": "Your shared video has been muted so<br/>that you can talk to the other participants.",
"micMutedPopup": "Your microphone has been muted so that you<br/>would fully enjoy your shared video.",
"sharedVideoMutedPopup": "Your shared video has been muted so that you can talk to the other participants.",
"micMutedPopup": "Your microphone has been muted so that you would fully enjoy your shared video.",
"talkWhileMutedPopup": "Trying to speak? You are muted.",
"unableToUnmutePopup": "You cannot un-mute while the shared video is on.",
"cameraDisabled": "Camera is not available",
Expand Down
22 changes: 16 additions & 6 deletions modules/UI/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import {
import { openDisplayNamePrompt } from '../../react/features/display-name';
import {
checkAutoEnableDesktopSharing,
clearButtonPopup,
dockToolbox,
setButtonPopupTimeout,
setToolbarButton,
showDialPadButton,
showEtherpadButton,
Expand Down Expand Up @@ -609,13 +611,21 @@ UI.inputDisplayNameHandler = function (newDisplayName) {

/**
* Show custom popup/tooltip for a specified button.
* @param popupSelectorID the selector id of the popup to show
* @param show true or false/show or hide the popup
* @param timeout the time to show the popup
*
* @param {string} buttonName - The name of the button as specified in the
* button configurations for the toolbar.
* @param {string} popupSelectorID - The id of the popup to show as specified in
* the button configurations for the toolbar.
* @param {boolean} show - True or false/show or hide the popup
* @param {number} timeout - The time to show the popup
* @returns {void}
*/
UI.showCustomToolbarPopup = function (popupSelectorID, show, timeout) {
eventEmitter.emit(UIEvents.SHOW_CUSTOM_TOOLBAR_BUTTON_POPUP,
popupSelectorID, show, timeout);
UI.showCustomToolbarPopup = function (buttonName, popupID, show, timeout) {
const action = show
? setButtonPopupTimeout(buttonName, popupID, timeout)
: clearButtonPopup(buttonName);

APP.store.dispatch(action);
};

/**
Expand Down
3 changes: 0 additions & 3 deletions modules/UI/recording/Recording.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const logger = require("jitsi-meet-logger").getLogger(__filename);

import UIEvents from "../../../service/UI/UIEvents";
import UIUtil from '../util/UIUtil';
import { setTooltip } from '../util/Tooltip';
import VideoLayout from '../videolayout/VideoLayout';

import { setToolboxEnabled } from '../../../react/features/toolbox';
Expand Down Expand Up @@ -324,8 +323,6 @@ var Recording = {
initRecordingButton() {
const selector = $('#toolbar_button_record');

setTooltip(selector, 'liveStreaming.buttonTooltip', 'right');

selector.addClass(this.baseClass);
selector.attr("data-i18n", "[content]" + this.recordingButtonTooltip);
APP.translation.translateElement(selector);
Expand Down
6 changes: 4 additions & 2 deletions modules/UI/shared_video/SharedVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ export default class SharedVideoManager {
if(show)
this.showSharedVideoMutedPopup(false);

APP.UI.showCustomToolbarPopup('#micMutedPopup', show, 5000);
APP.UI.showCustomToolbarPopup(
'microphone', 'micMutedPopup', show, 5000);
}

/**
Expand All @@ -571,7 +572,8 @@ export default class SharedVideoManager {
if(show)
this.showMicMutedPopup(false);

APP.UI.showCustomToolbarPopup('#sharedVideoMutedPopup', show, 5000);
APP.UI.showCustomToolbarPopup(
'sharedvideo', 'sharedVideoMutedPopup', show, 5000);
}
}

Expand Down
63 changes: 63 additions & 0 deletions react/features/toolbox/actions.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from './actions.native';
import { SET_DEFAULT_TOOLBOX_BUTTONS } from './actionTypes';
import {
getButton,
getDefaultToolboxButtons,
isButtonEnabled
} from './functions';
Expand Down Expand Up @@ -48,6 +49,23 @@ export function checkAutoEnableDesktopSharing(): Function {
};
}

/**
* Dispatches an action to hide any popups displayed by the associated button.
*
* @param {string} buttonName - The name of the button as specified in the
* button configurations for the toolbar.
* @returns {Function}
*/
export function clearButtonPopup(buttonName) {
return (dispatch, getState) => {
_clearPopupTimeout(buttonName, getState());

dispatch(setToolbarButton(buttonName, {
popupDisplay: null
}));
};
}

/**
* Docks/undocks the Toolbox.
*
Expand Down Expand Up @@ -195,6 +213,34 @@ export function hideToolbox(force: boolean = false): Function {
};
}

/**
* Dispatches an action to show the popup associated with a button. Sets a
* timeout to be fired which will dismiss the popup.
*
* @param {string} buttonName - The name of the button as specified in the
* button configurations for the toolbar.
* @param {string} popupName - The id of the popup to show as specified in
* the button configurations for the toolbar.
* @param {number} timeout - The time in milliseconds to show the popup.
* @returns {Function}
*/
export function setButtonPopupTimeout(buttonName, popupName, timeout) {
return (dispatch, getState) => {
_clearPopupTimeout(buttonName, getState());

const newTimeoutId = setTimeout(() => {
dispatch(clearButtonPopup(buttonName));
}, timeout);

dispatch(setToolbarButton(buttonName, {
popupDisplay: {
popupID: popupName,
timeoutID: newTimeoutId
}
}));
};
}

/**
* Sets the default toolbar buttons of the Toolbox.
*
Expand Down Expand Up @@ -387,3 +433,20 @@ export function toggleSideToolbarContainer(containerId: string): Function {
}
};
}

/**
* Clears the timeout set for hiding a button popup.
*
* @param {string} buttonName - The name of the button as specified in the
* button configurations for the toolbar.
* @param {Object} state - The redux state in which the button is expected to
* be defined.
* @private
* @returns {void}
*/
function _clearPopupTimeout(buttonName, state) {
const { popupDisplay } = getButton(buttonName, state);
const { timeoutID } = popupDisplay || {};

clearTimeout(timeoutID);
}
92 changes: 58 additions & 34 deletions react/features/toolbox/components/ToolbarButton.web.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */

import AKInlineDialog from '@atlaskit/inline-dialog';
import { Tooltip } from '@atlaskit/tooltip';
import React, { Component } from 'react';

Expand All @@ -11,6 +12,18 @@ import StatelessToolbarButton from './StatelessToolbarButton';

declare var APP: Object;

/**
* Mapping of tooltip positions to equivalent {@code AKInlineDialog} positions.
*
* @private
*/
const TOOLTIP_TO_POPUP_POSITION = {
bottom: 'bottom center',
left: 'left middle',
top: 'top center',
right: 'right middle'
};

/**
* Represents a button in Toolbar on React.
*
Expand Down Expand Up @@ -127,26 +140,39 @@ class ToolbarButton extends Component {
*/
render(): ReactElement<*> {
const { button, t, tooltipPosition } = this.props;
const popups = button.popups || [];

const props = {
...this.props,
onClick: this._onClick,
createRefToButton: this._createRefToButton
};

return (
const buttonComponent = ( // eslint-disable-line no-extra-parens
<Tooltip
description = { button.tooltipText || t(button.tooltipKey) }
onMouseOut = { this._onMouseOut }
onMouseOver = { this._onMouseOver }
position = { tooltipPosition }
visible = { this.state.showTooltip }>
<StatelessToolbarButton { ...props }>
{ this._renderPopups(popups) }
</StatelessToolbarButton>
<StatelessToolbarButton { ...props } />
</Tooltip>
);

const popupConfig = this._getPopupDisplayConfiguration();

if (popupConfig) {
const { dataAttr, dataInterpolate, position } = popupConfig;

return (
<AKInlineDialog
content = { t(dataAttr, dataInterpolate) }
isOpen = { Boolean(popupConfig) }
position = { position }>
{ buttonComponent }
</AKInlineDialog>
);
}

return buttonComponent;
}

/**
Expand Down Expand Up @@ -174,46 +200,44 @@ class ToolbarButton extends Component {
}

/**
* If toolbar button should contain children elements
* renders them.
* Parses the props and state to find any popup that should be displayed
* and returns an object describing how the popup should display.
*
* @returns {ReactElement|null}
* @private
* @returns {Object|null}
*/
_renderInnerElementsIfRequired(): ReactElement<*> | null {
if (this.props.button.html) {
return this.props.button.html;
_getPopupDisplayConfiguration() {
const { button, tooltipPosition } = this.props;
const { popups, popupDisplay } = button;

if (!popups || !popupDisplay) {
return null;
}

return null;
const { popupID } = popupDisplay;
const currentPopup = popups.find(popup => popup.id === popupID);

return Object.assign(
{},
currentPopup || {},
{
position: TOOLTIP_TO_POPUP_POSITION[tooltipPosition]
});
}

/**
* Renders popup element for toolbar button.
* If toolbar button should contain children elements
* renders them.
*
* @param {Array} popups - Array of popup objects.
* @returns {Array}
* @returns {ReactElement|null}
* @private
*/
_renderPopups(popups: Array<*> = []): Array<*> {
return popups.map(popup => {
let gravity = 'n';

if (popup.dataAttrPosition) {
gravity = popup.dataAttrPosition;
}

const title = this.props.t(popup.dataAttr, popup.dataInterpolate);
_renderInnerElementsIfRequired(): ReactElement<*> | null {
if (this.props.button.html) {
return this.props.button.html;
}

return (
<div
className = { popup.className }
data-popup = { gravity }
id = { popup.id }
key = { popup.id }
title = { title } />
);
});
return null;
}

/**
Expand Down
Loading

0 comments on commit e3361e2

Please sign in to comment.