forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InfoTooltipWithTrigger.jsx
50 lines (47 loc) · 1.25 KB
/
InfoTooltipWithTrigger.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React from 'react';
import PropTypes from 'prop-types';
import { Tooltip, OverlayTrigger } from 'react-bootstrap';
import { slugify } from '../modules/utils';
const propTypes = {
label: PropTypes.string.isRequired,
tooltip: PropTypes.string,
icon: PropTypes.string,
className: PropTypes.string,
onClick: PropTypes.func,
placement: PropTypes.string,
bsStyle: PropTypes.string,
};
const defaultProps = {
icon: 'info-circle',
className: 'text-muted',
placement: 'right',
};
const tooltipStyle = { wordWrap: 'break-word' };
export default function InfoTooltipWithTrigger({
label, tooltip, icon, className, onClick, placement, bsStyle }) {
const iconClass = `fa fa-${icon} ${className} ${bsStyle ? `text-${bsStyle}` : ''}`;
const iconEl = (
<i
className={iconClass}
onClick={onClick}
style={{ cursor: onClick ? 'pointer' : null }}
/>
);
if (!tooltip) {
return iconEl;
}
return (
<OverlayTrigger
placement={placement}
overlay={
<Tooltip id={`${slugify(label)}-tooltip`} style={tooltipStyle}>
{tooltip}
</Tooltip>
}
>
{iconEl}
</OverlayTrigger>
);
}
InfoTooltipWithTrigger.propTypes = propTypes;
InfoTooltipWithTrigger.defaultProps = defaultProps;