2017-09-27 21:23:31 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-19 16:01:44 +00:00
|
|
|
import React, { Component } from 'react';
|
2017-08-15 22:14:49 +00:00
|
|
|
import Tooltip from '@atlaskit/tooltip';
|
2017-06-19 16:01:44 +00:00
|
|
|
|
2017-08-15 22:14:49 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
2017-06-19 16:01:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* React {@code Component} for showing an icon with a tooltip.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
|
|
|
class BaseIndicator extends Component {
|
2017-08-15 22:14:49 +00:00
|
|
|
/**
|
|
|
|
* Default values for {@code BaseIndicator} component's properties.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
2017-07-10 22:29:44 +00:00
|
|
|
static defaultProps = {
|
|
|
|
className: '',
|
|
|
|
iconClassName: '',
|
|
|
|
iconSize: 'auto',
|
2017-08-15 22:14:49 +00:00
|
|
|
id: '',
|
|
|
|
tooltipPosition: 'top'
|
2017-07-10 22:29:44 +00:00
|
|
|
};
|
|
|
|
|
2017-08-15 22:14:49 +00:00
|
|
|
/**
|
|
|
|
* {@code BaseIndicator} component's property types.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
2017-07-10 22:29:44 +00:00
|
|
|
static propTypes = {
|
|
|
|
/**
|
2017-08-15 22:14:49 +00:00
|
|
|
* Additional CSS class names to set on the icon container.
|
2017-07-10 22:29:44 +00:00
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
className: PropTypes.string,
|
2017-07-10 22:29:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The CSS classnames to set on the icon element of the component.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
iconClassName: PropTypes.string,
|
2017-07-10 22:29:44 +00:00
|
|
|
|
|
|
|
/**
|
2017-08-14 15:02:58 +00:00
|
|
|
* The font size for the icon.
|
2017-07-10 22:29:44 +00:00
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
iconSize: PropTypes.string,
|
2017-07-10 22:29:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ID attribue to set on the root element of the component.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
id: PropTypes.string,
|
2017-07-10 22:29:44 +00:00
|
|
|
|
2017-08-15 22:14:49 +00:00
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
t: PropTypes.func,
|
2017-08-15 22:14:49 +00:00
|
|
|
|
2017-07-10 22:29:44 +00:00
|
|
|
/**
|
|
|
|
* The translation key to use for displaying a tooltip when hovering
|
|
|
|
* over the component.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
tooltipKey: PropTypes.string,
|
2017-06-19 16:01:44 +00:00
|
|
|
|
|
|
|
/**
|
2017-08-15 22:14:49 +00:00
|
|
|
* From which side of the indicator the tooltip should appear from.
|
|
|
|
* Defaults to "top".
|
2017-06-19 16:01:44 +00:00
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
tooltipPosition: PropTypes.string
|
2017-08-15 22:14:49 +00:00
|
|
|
};
|
2017-06-19 16:01:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2017-08-15 22:14:49 +00:00
|
|
|
const {
|
|
|
|
className,
|
|
|
|
iconClassName,
|
|
|
|
iconSize,
|
|
|
|
id,
|
|
|
|
t,
|
|
|
|
tooltipKey,
|
|
|
|
tooltipPosition
|
|
|
|
} = this.props;
|
2017-06-19 16:01:44 +00:00
|
|
|
|
2017-08-15 22:14:49 +00:00
|
|
|
const iconContainerClassName = `indicator-icon-container ${className}`;
|
2017-06-19 16:01:44 +00:00
|
|
|
|
2017-08-15 22:14:49 +00:00
|
|
|
return (
|
|
|
|
<div className = 'indicator-container'>
|
|
|
|
<Tooltip
|
|
|
|
description = { t(tooltipKey) }
|
|
|
|
position = { tooltipPosition }>
|
|
|
|
<span
|
|
|
|
className = { iconContainerClassName }
|
|
|
|
id = { id }>
|
|
|
|
<i
|
|
|
|
className = { iconClassName }
|
|
|
|
style = {{ fontSize: iconSize }} />
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
2017-06-19 16:01:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 22:14:49 +00:00
|
|
|
export default translate(BaseIndicator);
|