|
|
@ -1,5 +1,6 @@ |
|
|
|
/* @flow */ |
|
|
|
/* @flow */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import AKInlineDialog from '@atlaskit/inline-dialog'; |
|
|
|
import { Tooltip } from '@atlaskit/tooltip'; |
|
|
|
import { Tooltip } from '@atlaskit/tooltip'; |
|
|
|
import React, { Component } from 'react'; |
|
|
|
import React, { Component } from 'react'; |
|
|
|
|
|
|
|
|
|
|
@ -11,6 +12,18 @@ import StatelessToolbarButton from './StatelessToolbarButton'; |
|
|
|
|
|
|
|
|
|
|
|
declare var APP: Object; |
|
|
|
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. |
|
|
|
* Represents a button in Toolbar on React. |
|
|
|
* |
|
|
|
* |
|
|
@ -127,26 +140,39 @@ class ToolbarButton extends Component { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
render(): ReactElement<*> { |
|
|
|
render(): ReactElement<*> { |
|
|
|
const { button, t, tooltipPosition } = this.props; |
|
|
|
const { button, t, tooltipPosition } = this.props; |
|
|
|
const popups = button.popups || []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const props = { |
|
|
|
const props = { |
|
|
|
...this.props, |
|
|
|
...this.props, |
|
|
|
onClick: this._onClick, |
|
|
|
onClick: this._onClick, |
|
|
|
createRefToButton: this._createRefToButton |
|
|
|
createRefToButton: this._createRefToButton |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
const buttonComponent = ( // eslint-disable-line no-extra-parens
|
|
|
|
<Tooltip |
|
|
|
<Tooltip |
|
|
|
description = { button.tooltipText || t(button.tooltipKey) } |
|
|
|
description = { button.tooltipText || t(button.tooltipKey) } |
|
|
|
onMouseOut = { this._onMouseOut } |
|
|
|
onMouseOut = { this._onMouseOut } |
|
|
|
onMouseOver = { this._onMouseOver } |
|
|
|
onMouseOver = { this._onMouseOver } |
|
|
|
position = { tooltipPosition } |
|
|
|
position = { tooltipPosition } |
|
|
|
visible = { this.state.showTooltip }> |
|
|
|
visible = { this.state.showTooltip }> |
|
|
|
<StatelessToolbarButton { ...props }> |
|
|
|
<StatelessToolbarButton { ...props } /> |
|
|
|
{ this._renderPopups(popups) } |
|
|
|
|
|
|
|
</StatelessToolbarButton> |
|
|
|
|
|
|
|
</Tooltip> |
|
|
|
</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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -174,46 +200,44 @@ class ToolbarButton extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* If toolbar button should contain children elements |
|
|
|
* Parses the props and state to find any popup that should be displayed |
|
|
|
* renders them. |
|
|
|
* and returns an object describing how the popup should display. |
|
|
|
* |
|
|
|
* |
|
|
|
* @returns {ReactElement|null} |
|
|
|
|
|
|
|
* @private |
|
|
|
* @private |
|
|
|
|
|
|
|
* @returns {Object|null} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
_renderInnerElementsIfRequired(): ReactElement<*> | null { |
|
|
|
_getPopupDisplayConfiguration() { |
|
|
|
if (this.props.button.html) { |
|
|
|
const { button, tooltipPosition } = this.props; |
|
|
|
return this.props.button.html; |
|
|
|
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 {ReactElement|null} |
|
|
|
* @returns {Array} |
|
|
|
|
|
|
|
* @private |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
_renderPopups(popups: Array<*> = []): Array<*> { |
|
|
|
_renderInnerElementsIfRequired(): ReactElement<*> | null { |
|
|
|
return popups.map(popup => { |
|
|
|
if (this.props.button.html) { |
|
|
|
let gravity = 'n'; |
|
|
|
return this.props.button.html; |
|
|
|
|
|
|
|
} |
|
|
|
if (popup.dataAttrPosition) { |
|
|
|
|
|
|
|
gravity = popup.dataAttrPosition; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const title = this.props.t(popup.dataAttr, popup.dataInterpolate); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return null; |
|
|
|
<div |
|
|
|
|
|
|
|
className = { popup.className } |
|
|
|
|
|
|
|
data-popup = { gravity } |
|
|
|
|
|
|
|
id = { popup.id } |
|
|
|
|
|
|
|
key = { popup.id } |
|
|
|
|
|
|
|
title = { title } /> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|