DocSpace-client/packages/components/help-button/index.js

105 lines
2.7 KiB
JavaScript
Raw Normal View History

import React from "react";
import PropTypes from "prop-types";
import IconButton from "../icon-button";
import Tooltip from "../tooltip";
import uniqueId from "lodash/uniqueId";
2023-09-05 09:15:29 +00:00
import { classNames } from "../utils/classNames";
2023-01-23 08:24:41 +00:00
import InfoReactSvgUrl from "PUBLIC_DIR/images/info.react.svg?url";
2023-01-11 15:08:01 +00:00
class HelpButton extends React.Component {
constructor(props) {
super(props);
this.id = this.props.id || uniqueId();
}
render() {
const {
tooltipContent,
place,
2023-09-05 09:15:29 +00:00
offset,
iconName,
color,
getContent,
className,
dataTip,
2022-03-24 17:56:51 +00:00
tooltipMaxWidth,
style,
size,
2023-09-05 09:15:29 +00:00
afterShow,
afterHide,
} = this.props;
return (
<div ref={this.ref} style={style}>
2023-01-23 08:24:41 +00:00
<IconButton
id={this.id}
2023-09-05 09:15:29 +00:00
theme={this.props.theme}
className={classNames(className, "help-icon")}
2023-01-23 08:24:41 +00:00
isClickable={true}
iconName={iconName}
size={size}
color={color}
data-for={this.id}
dataTip={dataTip}
/>
2023-09-05 09:15:29 +00:00
<Tooltip
id={this.id}
place={place}
offset={offset}
afterShow={afterShow}
afterHide={afterHide}
maxWidth={tooltipMaxWidth}
getContent={getContent}
>
{tooltipContent}
</Tooltip>
</div>
);
}
}
HelpButton.propTypes = {
/** Displays the child elements */
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
/** Sets the tooltip content */
tooltipContent: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
/** Required to set additional properties of the tooltip */
tooltipProps: PropTypes.object,
/** Sets the maximum width of the tooltip */
2022-03-24 17:56:51 +00:00
tooltipMaxWidth: PropTypes.string,
/** Sets the tooltip id */
tooltipId: PropTypes.string,
/** Global tooltip placement */
place: PropTypes.string,
/** Specifies the icon name */
iconName: PropTypes.string,
/** Icon color */
color: PropTypes.string,
/** The data-* attribute is used to store custom data private to the page or application. Required to display a tip over the hovered element */
dataTip: PropTypes.string,
/** Sets a callback function that generates the tip content dynamically */
getContent: PropTypes.func,
/** Accepts class */
className: PropTypes.string,
/** Accepts id */
id: PropTypes.string,
/** Accepts css style */
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
/** Button height and width value */
size: PropTypes.number,
};
HelpButton.defaultProps = {
2023-01-11 15:08:01 +00:00
iconName: InfoReactSvgUrl,
place: "top",
className: "icon-button",
2022-08-05 00:07:29 +00:00
size: 12,
};
export default HelpButton;