|
|
@ -1,6 +1,7 @@ |
|
|
|
import React, { Component } from 'react'; |
|
|
|
import React, { Component } from 'react'; |
|
|
|
|
|
|
|
import Tooltip from '@atlaskit/tooltip'; |
|
|
|
|
|
|
|
|
|
|
|
import { setTooltip } from '../../../../../modules/UI/util/Tooltip'; |
|
|
|
import { translate } from '../../../base/i18n'; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* React {@code Component} for showing an icon with a tooltip. |
|
|
|
* React {@code Component} for showing an icon with a tooltip. |
|
|
@ -8,16 +9,27 @@ import { setTooltip } from '../../../../../modules/UI/util/Tooltip'; |
|
|
|
* @extends Component |
|
|
|
* @extends Component |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class BaseIndicator extends Component { |
|
|
|
class BaseIndicator extends Component { |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Default values for {@code BaseIndicator} component's properties. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @static |
|
|
|
|
|
|
|
*/ |
|
|
|
static defaultProps = { |
|
|
|
static defaultProps = { |
|
|
|
className: '', |
|
|
|
className: '', |
|
|
|
iconClassName: '', |
|
|
|
iconClassName: '', |
|
|
|
iconSize: 'auto', |
|
|
|
iconSize: 'auto', |
|
|
|
id: '' |
|
|
|
id: '', |
|
|
|
|
|
|
|
tooltipPosition: 'top' |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* {@code BaseIndicator} component's property types. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @static |
|
|
|
|
|
|
|
*/ |
|
|
|
static propTypes = { |
|
|
|
static propTypes = { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* The CSS class names to set on the root element of the component. |
|
|
|
* Additional CSS class names to set on the icon container. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
className: React.PropTypes.string, |
|
|
|
className: React.PropTypes.string, |
|
|
|
|
|
|
|
|
|
|
@ -36,44 +48,23 @@ class BaseIndicator extends Component { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
id: React.PropTypes.string, |
|
|
|
id: React.PropTypes.string, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Invoked to obtain translated strings. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
t: React.PropTypes.func, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The translation key to use for displaying a tooltip when hovering |
|
|
|
* The translation key to use for displaying a tooltip when hovering |
|
|
|
* over the component. |
|
|
|
* over the component. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
tooltipKey: React.PropTypes.string |
|
|
|
tooltipKey: React.PropTypes.string, |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Initializes a new {@code BaseIndicator} instance. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {Object} props - The read-only properties with which the new |
|
|
|
|
|
|
|
* instance is to be initialized. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
constructor(props) { |
|
|
|
|
|
|
|
super(props); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* An internal reference to the HTML element at the top of the |
|
|
|
* From which side of the indicator the tooltip should appear from. |
|
|
|
* component's DOM hierarchy. The reference is needed for attaching a |
|
|
|
* Defaults to "top". |
|
|
|
* tooltip. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @type {HTMLElement} |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
this._rootElement = null; |
|
|
|
tooltipPosition: React.PropTypes.string |
|
|
|
|
|
|
|
}; |
|
|
|
// Bind event handler so it is only bound once for every instance.
|
|
|
|
|
|
|
|
this._setRootElementRef = this._setRootElementRef.bind(this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Sets a tooltip which will display when hovering over the component. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @inheritdoc |
|
|
|
|
|
|
|
* @returns {void} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
|
|
|
|
this._setTooltip(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Implements React's {@link Component#render()}. |
|
|
|
* Implements React's {@link Component#render()}. |
|
|
@ -82,46 +73,34 @@ class BaseIndicator extends Component { |
|
|
|
* @returns {ReactElement} |
|
|
|
* @returns {ReactElement} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
render() { |
|
|
|
render() { |
|
|
|
return ( |
|
|
|
const { |
|
|
|
<span |
|
|
|
className, |
|
|
|
className = { this.props.className } |
|
|
|
iconClassName, |
|
|
|
id = { this.props.id } |
|
|
|
iconSize, |
|
|
|
ref = { this._setRootElementRef }> |
|
|
|
id, |
|
|
|
<i |
|
|
|
t, |
|
|
|
className = { this.props.iconClassName } |
|
|
|
tooltipKey, |
|
|
|
style = {{ fontSize: this.props.iconSize }} /> |
|
|
|
tooltipPosition |
|
|
|
</span> |
|
|
|
} = this.props; |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
const iconContainerClassName = `indicator-icon-container ${className}`; |
|
|
|
* Sets the internal reference to the root HTML element for the component. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {HTMLIconElement} element - The root HTML element of the |
|
|
|
|
|
|
|
* component. |
|
|
|
|
|
|
|
* @private |
|
|
|
|
|
|
|
* @returns {void} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
_setRootElementRef(element) { |
|
|
|
|
|
|
|
this._rootElement = element; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
return ( |
|
|
|
* Associate the component as a tooltip trigger so a tooltip may display on |
|
|
|
<div className = 'indicator-container'> |
|
|
|
* hover. |
|
|
|
<Tooltip |
|
|
|
* |
|
|
|
description = { t(tooltipKey) } |
|
|
|
* @private |
|
|
|
position = { tooltipPosition }> |
|
|
|
* @returns {void} |
|
|
|
<span |
|
|
|
*/ |
|
|
|
className = { iconContainerClassName } |
|
|
|
_setTooltip() { |
|
|
|
id = { id }> |
|
|
|
// TODO Replace UIUtil with an AtlasKit component when a suitable one
|
|
|
|
<i |
|
|
|
// becomes available for tooltips.
|
|
|
|
className = { iconClassName } |
|
|
|
setTooltip( |
|
|
|
style = {{ fontSize: iconSize }} /> |
|
|
|
this._rootElement, |
|
|
|
</span> |
|
|
|
this.props.tooltipKey, |
|
|
|
</Tooltip> |
|
|
|
'top' |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default BaseIndicator; |
|
|
|
export default translate(BaseIndicator); |
|
|
|