2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2018-05-23 02:11:20 +02:00
|
|
|
import * as React from 'react';
|
2018-03-26 23:32:43 +02:00
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
type Props = {
|
2018-05-23 05:48:22 +02:00
|
|
|
body: string,
|
2018-05-23 02:11:20 +02:00
|
|
|
label?: string,
|
|
|
|
children: ?React.Node,
|
|
|
|
icon: ?boolean,
|
|
|
|
direction: string,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
2018-05-23 02:11:20 +02:00
|
|
|
class ToolTip extends React.PureComponent<Props> {
|
|
|
|
static defaultProps = {
|
2018-05-23 05:48:22 +02:00
|
|
|
direction: 'bottom',
|
2018-05-23 02:11:20 +02:00
|
|
|
};
|
2018-03-26 23:32:43 +02:00
|
|
|
|
|
|
|
render() {
|
2018-05-23 02:11:20 +02:00
|
|
|
const { children, label, body, icon, direction } = this.props;
|
|
|
|
|
|
|
|
const tooltipContent = children || label;
|
2018-03-26 23:32:43 +02:00
|
|
|
|
|
|
|
return (
|
2018-05-23 02:11:20 +02:00
|
|
|
<span
|
|
|
|
className={classnames('tooltip', {
|
|
|
|
'tooltip--label': label && !icon,
|
|
|
|
'tooltip--icon': icon,
|
|
|
|
'tooltip--top': direction === 'top',
|
|
|
|
'tooltip--right': direction === 'right',
|
|
|
|
'tooltip--bottom': direction === 'bottom',
|
|
|
|
'tooltip--left': direction === 'left',
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{tooltipContent}
|
2018-05-23 05:48:22 +02:00
|
|
|
<span className="tooltip__body">{body}</span>
|
2018-03-26 23:32:43 +02:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ToolTip;
|