2022-11-28 02:00:28 +00:00
|
|
|
import { HelpCircle } from 'lucide-react';
|
2023-02-22 20:13:33 +00:00
|
|
|
import { ReactNode, useMemo } from 'react';
|
2022-12-08 21:41:11 +00:00
|
|
|
import sanitize from 'sanitize-html';
|
2021-11-16 14:11:18 +00:00
|
|
|
|
2022-12-04 20:47:43 +00:00
|
|
|
import { TooltipWithChildren, Position } from '../TooltipWithChildren';
|
2021-11-16 14:11:18 +00:00
|
|
|
|
|
|
|
export interface Props {
|
2022-07-03 23:21:25 +00:00
|
|
|
position?: Position;
|
2023-02-22 20:13:33 +00:00
|
|
|
message: ReactNode;
|
2022-08-24 22:11:25 +00:00
|
|
|
className?: string;
|
2022-12-08 21:41:11 +00:00
|
|
|
setHtmlMessage?: boolean;
|
2021-11-16 14:11:18 +00:00
|
|
|
}
|
|
|
|
|
2022-12-08 21:41:11 +00:00
|
|
|
export function Tooltip({
|
|
|
|
message,
|
|
|
|
position = 'bottom',
|
|
|
|
className,
|
|
|
|
setHtmlMessage,
|
|
|
|
}: Props) {
|
|
|
|
// allow angular views to set html messages for the tooltip
|
|
|
|
const htmlMessage = useMemo(() => {
|
2023-02-22 20:13:33 +00:00
|
|
|
if (setHtmlMessage && typeof message === 'string') {
|
2022-12-08 21:41:11 +00:00
|
|
|
// eslint-disable-next-line react/no-danger
|
|
|
|
return <div dangerouslySetInnerHTML={{ __html: sanitize(message) }} />;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}, [setHtmlMessage, message]);
|
|
|
|
|
2021-11-16 14:11:18 +00:00
|
|
|
return (
|
2022-12-04 20:47:43 +00:00
|
|
|
<TooltipWithChildren
|
2022-12-08 21:41:11 +00:00
|
|
|
message={htmlMessage || message}
|
2022-12-04 20:47:43 +00:00
|
|
|
position={position}
|
|
|
|
className={className}
|
2022-07-03 23:21:25 +00:00
|
|
|
>
|
2022-12-04 20:47:43 +00:00
|
|
|
<span className="inline-flex text-base">
|
|
|
|
<HelpCircle className="lucide ml-1" aria-hidden="true" />
|
|
|
|
</span>
|
|
|
|
</TooltipWithChildren>
|
2021-11-16 14:11:18 +00:00
|
|
|
);
|
|
|
|
}
|