2022-10-14 16:45:57 +00:00
|
|
|
import classnames from "classnames";
|
2022-02-28 21:25:06 +00:00
|
|
|
import React from "react";
|
|
|
|
|
|
2023-06-08 17:13:27 +00:00
|
|
|
import * as DOMPurify from "dompurify";
|
|
|
|
|
|
2022-02-28 21:25:06 +00:00
|
|
|
interface ITooltipWrapperProps {
|
|
|
|
|
children: string;
|
|
|
|
|
tipContent: string;
|
|
|
|
|
position?: "top" | "bottom";
|
2022-10-04 14:03:51 +00:00
|
|
|
isDelayed?: boolean;
|
2022-10-14 16:45:57 +00:00
|
|
|
className?: string;
|
2022-02-28 21:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const baseClass = "component__tooltip-wrapper";
|
|
|
|
|
|
|
|
|
|
const TooltipWrapper = ({
|
|
|
|
|
children,
|
|
|
|
|
tipContent,
|
|
|
|
|
position = "bottom",
|
2022-10-04 14:03:51 +00:00
|
|
|
isDelayed,
|
2022-10-14 16:45:57 +00:00
|
|
|
className,
|
2022-02-28 21:25:06 +00:00
|
|
|
}: ITooltipWrapperProps): JSX.Element => {
|
2022-10-14 16:45:57 +00:00
|
|
|
const classname = classnames(baseClass, className);
|
2022-10-04 14:03:51 +00:00
|
|
|
const tipClass = isDelayed
|
|
|
|
|
? `${baseClass}__tip-text delayed-tip`
|
|
|
|
|
: `${baseClass}__tip-text`;
|
|
|
|
|
|
2023-06-08 17:13:27 +00:00
|
|
|
const sanitizedTipContent = DOMPurify.sanitize(tipContent);
|
|
|
|
|
|
2022-02-28 21:25:06 +00:00
|
|
|
return (
|
2022-10-14 16:45:57 +00:00
|
|
|
<div className={classname} data-position={position}>
|
2022-02-28 21:25:06 +00:00
|
|
|
<div className={`${baseClass}__element`}>
|
|
|
|
|
{children}
|
|
|
|
|
<div className={`${baseClass}__underline`} data-text={children} />
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
2022-10-04 14:03:51 +00:00
|
|
|
className={tipClass}
|
2023-06-08 17:13:27 +00:00
|
|
|
dangerouslySetInnerHTML={{ __html: sanitizedTipContent }}
|
2022-02-28 21:25:06 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TooltipWrapper;
|