mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* poc: Use react-popper for tooltips #10389 * poc: Add popover component and use a hoc() for Tooltip + Popover to avoid code duplication #10389 * jest: Add snapshot tests to Popover and Tooltip #10389 * poc: Move target from hoc into Popover/Tooltip-component #10389 * poc: Clean up unused styles and use the existing Grafana style/colors on popper tooltip #10389 * poc: Remove test code before PR * poc: Remove imports used in poc but shouldn't be included anymore #10389
46 lines
977 B
TypeScript
46 lines
977 B
TypeScript
import React from 'react';
|
|
import withTooltip from './withTooltip';
|
|
import { Target } from 'react-popper';
|
|
|
|
interface ITooltipProps {
|
|
tooltipSetState: (prevState: object) => void;
|
|
}
|
|
|
|
class Tooltip extends React.Component<ITooltipProps, any> {
|
|
constructor(props) {
|
|
super(props);
|
|
this.showTooltip = this.showTooltip.bind(this);
|
|
this.hideTooltip = this.hideTooltip.bind(this);
|
|
}
|
|
|
|
showTooltip() {
|
|
const { tooltipSetState } = this.props;
|
|
tooltipSetState(prevState => {
|
|
return {
|
|
...prevState,
|
|
show: true,
|
|
};
|
|
});
|
|
}
|
|
|
|
hideTooltip() {
|
|
const { tooltipSetState } = this.props;
|
|
tooltipSetState(prevState => {
|
|
return {
|
|
...prevState,
|
|
show: false,
|
|
};
|
|
});
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<Target className="popper__target" onMouseOver={this.showTooltip} onMouseOut={this.hideTooltip}>
|
|
{this.props.children}
|
|
</Target>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default withTooltip(Tooltip);
|