2020-06-18 19:53:02 +00:00
|
|
|
import React from 'react';
|
2020-06-17 21:36:19 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2020-06-18 19:53:02 +00:00
|
|
|
import TooltipTrigger from 'react-popper-tooltip';
|
|
|
|
import { Trans } from 'react-i18next';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import './Tooltip.css';
|
|
|
|
import 'react-popper-tooltip/dist/styles.css';
|
|
|
|
import { HIDE_TOOLTIP_DELAY } from '../../../helpers/constants';
|
2020-07-13 12:23:13 +00:00
|
|
|
import { processContent } from '../../../helpers/helpers';
|
2020-06-17 21:36:19 +00:00
|
|
|
|
|
|
|
const getHintElement = ({
|
|
|
|
className,
|
|
|
|
contentItemClass,
|
|
|
|
columnClass,
|
2020-06-18 19:53:02 +00:00
|
|
|
canShowTooltip = true,
|
2020-06-17 21:36:19 +00:00
|
|
|
xlinkHref,
|
|
|
|
title,
|
2020-06-18 19:53:02 +00:00
|
|
|
placement,
|
2020-06-17 21:36:19 +00:00
|
|
|
tooltipClass,
|
2020-06-18 19:53:02 +00:00
|
|
|
content,
|
2020-07-13 12:23:13 +00:00
|
|
|
renderContent = content ? React.Children.map(
|
|
|
|
processContent(content),
|
2020-06-18 19:53:02 +00:00
|
|
|
(item, idx) => <div key={idx} className={contentItemClass}>
|
|
|
|
<Trans>{item || '—'}</Trans>
|
|
|
|
</div>,
|
2020-07-13 12:23:13 +00:00
|
|
|
) : null,
|
2020-06-18 19:53:02 +00:00
|
|
|
}) => <TooltipTrigger placement={placement} trigger="hover" delayHide={HIDE_TOOLTIP_DELAY} tooltip={
|
2020-07-13 12:23:13 +00:00
|
|
|
({
|
|
|
|
tooltipRef,
|
|
|
|
getTooltipProps,
|
|
|
|
}) => <div {...getTooltipProps({
|
|
|
|
ref: tooltipRef,
|
|
|
|
className: classNames('tooltip__container', tooltipClass, { 'd-none': !canShowTooltip }),
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{title && <div className="pb-4 h-25 grid-content font-weight-bold">
|
|
|
|
<Trans>{title}</Trans>
|
|
|
|
</div>}
|
|
|
|
<div className={classNames(columnClass)}>{renderContent}</div>
|
|
|
|
</div>
|
|
|
|
}>{({
|
|
|
|
getTriggerProps, triggerRef,
|
|
|
|
}) => <span {...getTriggerProps({ ref: triggerRef })}>
|
2020-06-17 21:36:19 +00:00
|
|
|
{xlinkHref && <svg className={className}>
|
|
|
|
<use xlinkHref={`#${xlinkHref}`} />
|
|
|
|
</svg>}
|
2020-06-18 19:53:02 +00:00
|
|
|
</span>}
|
2020-07-13 12:23:13 +00:00
|
|
|
</TooltipTrigger>;
|
2020-06-17 21:36:19 +00:00
|
|
|
|
|
|
|
getHintElement.propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
contentItemClass: PropTypes.string,
|
|
|
|
columnClass: PropTypes.string,
|
|
|
|
tooltipClass: PropTypes.string,
|
|
|
|
title: PropTypes.string,
|
2020-06-18 19:53:02 +00:00
|
|
|
placement: PropTypes.string,
|
|
|
|
canShowTooltip: PropTypes.string,
|
2020-06-17 21:36:19 +00:00
|
|
|
xlinkHref: PropTypes.string,
|
|
|
|
content: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.array,
|
|
|
|
]),
|
|
|
|
renderContent: PropTypes.arrayOf(PropTypes.element),
|
|
|
|
};
|
|
|
|
|
|
|
|
export default getHintElement;
|