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';
|
2023-09-24 18:56:09 +00:00
|
|
|
import clsx from 'clsx';
|
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
|
|
|
|
2023-09-24 18:56:09 +00:00
|
|
|
type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
|
|
|
|
|
|
const sizeClasses: Record<Size, string> = {
|
|
|
|
xs: 'text-xs',
|
|
|
|
sm: 'text-sm',
|
|
|
|
md: 'text-base',
|
|
|
|
lg: 'text-lg',
|
|
|
|
xl: 'text-xl',
|
|
|
|
};
|
|
|
|
|
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;
|
2023-09-24 18:56:09 +00:00
|
|
|
size?: Size;
|
2021-11-16 14:11:18 +00:00
|
|
|
}
|
|
|
|
|
2022-12-08 21:41:11 +00:00
|
|
|
export function Tooltip({
|
|
|
|
message,
|
|
|
|
position = 'bottom',
|
|
|
|
className,
|
|
|
|
setHtmlMessage,
|
2023-09-24 18:56:09 +00:00
|
|
|
size = 'md',
|
2022-12-08 21:41:11 +00:00
|
|
|
}: 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 (
|
2023-09-24 18:56:09 +00:00
|
|
|
<span className={clsx('ml-1 inline-flex items-center', sizeClasses[size])}>
|
|
|
|
<TooltipWithChildren
|
|
|
|
message={htmlMessage || message}
|
|
|
|
position={position}
|
|
|
|
className={className}
|
|
|
|
>
|
|
|
|
<HelpCircle className="lucide" aria-hidden="true" />
|
|
|
|
</TooltipWithChildren>
|
|
|
|
</span>
|
2021-11-16 14:11:18 +00:00
|
|
|
);
|
|
|
|
}
|