2019-10-18 06:38:10 +00:00
|
|
|
import React from "react";
|
|
|
|
import PropTypes from "prop-types";
|
2021-02-10 08:00:17 +00:00
|
|
|
|
2019-10-18 06:38:10 +00:00
|
|
|
import IconButton from "../icon-button";
|
|
|
|
import Tooltip from "../tooltip";
|
2021-02-24 17:11:23 +00:00
|
|
|
import { handleAnyClick } from "../utils/event";
|
2019-10-18 06:38:10 +00:00
|
|
|
import uniqueId from "lodash/uniqueId";
|
2019-11-20 06:13:04 +00:00
|
|
|
|
2019-10-18 06:38:10 +00:00
|
|
|
class HelpButton extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
this.state = {
|
|
|
|
hideTooltip: false,
|
|
|
|
};
|
2019-10-18 06:38:10 +00:00
|
|
|
this.ref = React.createRef();
|
|
|
|
this.refTooltip = React.createRef();
|
2019-11-28 10:54:14 +00:00
|
|
|
this.id = this.props.id || uniqueId();
|
2019-10-18 06:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
afterShow = () => {
|
|
|
|
this.refTooltip.current.updatePosition();
|
2021-10-29 13:29:54 +00:00
|
|
|
handleAnyClick(true, this.handleClick);
|
2020-02-18 07:07:10 +00:00
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
if (this.state.hideTooltip) {
|
2020-02-18 07:07:10 +00:00
|
|
|
this.refTooltip.current.hideTooltip();
|
|
|
|
}
|
2019-10-18 06:38:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
afterHide = () => {
|
2021-10-29 13:29:54 +00:00
|
|
|
if (!this.state.hideTooltip) {
|
|
|
|
handleAnyClick(false, this.handleClick);
|
2019-10-18 06:38:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-16 13:16:01 +00:00
|
|
|
handleClick = (e) => {
|
2019-10-18 06:38:10 +00:00
|
|
|
if (!this.ref.current.contains(e.target)) {
|
|
|
|
this.refTooltip.current.hideTooltip();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
handleAnyClick(false, this.handleClick);
|
2019-11-20 06:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onClick = () => {
|
2021-10-29 13:29:54 +00:00
|
|
|
this.setState({ hideTooltip: false });
|
2019-11-27 13:50:37 +00:00
|
|
|
};
|
2019-10-18 06:38:10 +00:00
|
|
|
|
|
|
|
render() {
|
2019-11-20 06:13:04 +00:00
|
|
|
const {
|
|
|
|
tooltipContent,
|
|
|
|
place,
|
2020-02-07 12:21:11 +00:00
|
|
|
offsetTop,
|
|
|
|
offsetBottom,
|
2019-11-20 06:13:04 +00:00
|
|
|
offsetRight,
|
|
|
|
offsetLeft,
|
2019-12-26 10:49:07 +00:00
|
|
|
iconName,
|
|
|
|
color,
|
|
|
|
getContent,
|
|
|
|
className,
|
2019-12-05 11:17:45 +00:00
|
|
|
dataTip,
|
2022-03-24 17:56:51 +00:00
|
|
|
tooltipMaxWidth,
|
2020-10-16 13:16:01 +00:00
|
|
|
style,
|
2022-02-08 14:41:57 +00:00
|
|
|
size,
|
2019-11-20 06:13:04 +00:00
|
|
|
} = this.props;
|
2019-10-18 06:38:10 +00:00
|
|
|
|
|
|
|
return (
|
2020-02-07 10:06:32 +00:00
|
|
|
<div ref={this.ref} style={style}>
|
2019-10-18 06:38:10 +00:00
|
|
|
<IconButton
|
2022-01-24 15:27:24 +00:00
|
|
|
theme={this.props.theme}
|
2019-10-18 06:38:10 +00:00
|
|
|
id={this.id}
|
2019-12-19 09:26:58 +00:00
|
|
|
className={`${className} help-icon`}
|
2019-10-18 06:38:10 +00:00
|
|
|
isClickable={true}
|
2019-11-06 14:41:35 +00:00
|
|
|
iconName={iconName}
|
2022-02-08 14:41:57 +00:00
|
|
|
size={size}
|
2019-11-06 14:41:35 +00:00
|
|
|
color={color}
|
|
|
|
data-for={this.id}
|
|
|
|
dataTip={dataTip}
|
2019-11-20 06:13:04 +00:00
|
|
|
onClick={this.onClick}
|
2019-10-18 06:38:10 +00:00
|
|
|
/>
|
2020-02-18 07:07:10 +00:00
|
|
|
{getContent ? (
|
|
|
|
<Tooltip
|
2022-01-24 15:27:24 +00:00
|
|
|
theme={this.props.theme}
|
2020-02-18 07:07:10 +00:00
|
|
|
id={this.id}
|
|
|
|
reference={this.refTooltip}
|
|
|
|
effect="solid"
|
|
|
|
place={place}
|
|
|
|
offsetTop={offsetTop}
|
|
|
|
offsetBottom={offsetBottom}
|
|
|
|
offsetRight={offsetRight}
|
|
|
|
offsetLeft={offsetLeft}
|
|
|
|
afterShow={this.afterShow}
|
|
|
|
afterHide={this.afterHide}
|
|
|
|
getContent={getContent}
|
2022-03-24 17:56:51 +00:00
|
|
|
maxWidth={tooltipMaxWidth}
|
2020-02-18 07:07:10 +00:00
|
|
|
/>
|
2019-12-26 10:49:07 +00:00
|
|
|
) : (
|
2020-02-18 07:07:10 +00:00
|
|
|
<Tooltip
|
2022-01-24 15:27:24 +00:00
|
|
|
theme={this.props.theme}
|
2020-02-18 07:07:10 +00:00
|
|
|
id={this.id}
|
|
|
|
reference={this.refTooltip}
|
|
|
|
effect="solid"
|
|
|
|
place={place}
|
|
|
|
offsetRight={offsetRight}
|
|
|
|
offsetLeft={offsetLeft}
|
|
|
|
afterShow={this.afterShow}
|
|
|
|
afterHide={this.afterHide}
|
|
|
|
>
|
|
|
|
{tooltipContent}
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
2020-02-07 10:06:32 +00:00
|
|
|
</div>
|
2019-10-18 06:38:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HelpButton.propTypes = {
|
|
|
|
children: PropTypes.oneOfType([
|
|
|
|
PropTypes.arrayOf(PropTypes.node),
|
2020-10-16 13:16:01 +00:00
|
|
|
PropTypes.node,
|
2019-10-18 06:38:10 +00:00
|
|
|
]),
|
2019-11-29 13:41:16 +00:00
|
|
|
tooltipContent: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
2019-10-21 05:59:47 +00:00
|
|
|
offsetRight: PropTypes.number,
|
2020-02-07 12:21:11 +00:00
|
|
|
offsetLeft: PropTypes.number,
|
|
|
|
offsetTop: PropTypes.number,
|
|
|
|
offsetBottom: PropTypes.number,
|
2022-03-24 17:56:51 +00:00
|
|
|
tooltipMaxWidth: PropTypes.string,
|
2019-10-18 12:13:08 +00:00
|
|
|
tooltipId: PropTypes.string,
|
2019-10-21 09:05:45 +00:00
|
|
|
place: PropTypes.string,
|
2019-11-06 14:41:35 +00:00
|
|
|
iconName: PropTypes.string,
|
|
|
|
color: PropTypes.string,
|
|
|
|
dataTip: PropTypes.string,
|
2019-12-05 11:17:45 +00:00
|
|
|
getContent: PropTypes.func,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** Accepts class */
|
2019-11-28 10:54:14 +00:00
|
|
|
className: PropTypes.string,
|
2021-03-07 11:57:26 +00:00
|
|
|
/** Accepts id */
|
2019-11-28 10:54:14 +00:00
|
|
|
id: PropTypes.string,
|
2020-10-16 13:16:01 +00:00
|
|
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
2022-02-08 14:41:57 +00:00
|
|
|
size: PropTypes.number,
|
2019-10-18 06:38:10 +00:00
|
|
|
};
|
|
|
|
|
2019-10-18 12:13:08 +00:00
|
|
|
HelpButton.defaultProps = {
|
2021-05-26 14:16:32 +00:00
|
|
|
iconName: "/static/images/question.react.svg",
|
2019-10-18 12:13:08 +00:00
|
|
|
place: "top",
|
2022-03-17 13:37:11 +00:00
|
|
|
offsetRight: 60,
|
2019-11-06 14:41:35 +00:00
|
|
|
offsetLeft: 0,
|
2020-02-07 12:21:11 +00:00
|
|
|
offsetTop: 0,
|
|
|
|
offsetBottom: 0,
|
2019-12-05 11:17:45 +00:00
|
|
|
className: "icon-button",
|
2022-02-08 14:41:57 +00:00
|
|
|
size: 13,
|
2019-11-20 06:13:04 +00:00
|
|
|
};
|
2019-10-18 12:13:08 +00:00
|
|
|
|
2019-10-18 06:38:10 +00:00
|
|
|
export default HelpButton;
|