import React from "react"; import PropTypes from "prop-types"; import IconButton from "../icon-button"; import Tooltip from "../tooltip"; import { handleAnyClick } from "../utils/event"; import uniqueId from "lodash/uniqueId"; class HelpButton extends React.Component { constructor(props) { super(props); this.state = { hideTooltip: false, }; this.ref = React.createRef(); this.refTooltip = React.createRef(); this.id = this.props.id || uniqueId(); } afterShow = () => { this.refTooltip.current.updatePosition(); handleAnyClick(true, this.handleClick); if (this.state.hideTooltip) { this.refTooltip.current.hideTooltip(); } }; afterHide = () => { if (!this.state.hideTooltip) { handleAnyClick(false, this.handleClick); } }; handleClick = (e) => { if (!this.ref.current.contains(e.target)) { this.refTooltip.current.hideTooltip(); } }; componentWillUnmount() { handleAnyClick(false, this.handleClick); } onClick = () => { this.setState({ hideTooltip: false }); }; render() { const { tooltipContent, place, offsetTop, offsetBottom, offsetRight, offsetLeft, iconName, color, getContent, className, dataTip, tooltipMaxWidth, style, } = this.props; return (