mirror of
https://github.com/documenso/documenso.git
synced 2025-11-11 21:12:48 +10:00
## Before (error) https://github.com/user-attachments/assets/525e6c04-fc03-41a7-8299-2a753e9e9fa6 ## After (fixed) https://github.com/user-attachments/assets/67f7e592-c5ca-47f4-962c-e4a848522d43
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { TooltipArrow } from '@radix-ui/react-tooltip';
|
|
import type { VariantProps } from 'class-variance-authority';
|
|
import { cva } from 'class-variance-authority';
|
|
import { createPortal } from 'react-dom';
|
|
|
|
import { useFieldPageCoords } from '@documenso/lib/client-only/hooks/use-field-page-coords';
|
|
|
|
import { cn } from '../..//lib/utils';
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipProvider,
|
|
TooltipTrigger,
|
|
} from '../..//primitives/tooltip';
|
|
import type { Field } from '.prisma/client';
|
|
|
|
const tooltipVariants = cva('font-semibold', {
|
|
variants: {
|
|
color: {
|
|
default: 'border-2 fill-white',
|
|
warning: 'border-0 bg-orange-300 fill-orange-300 text-orange-900',
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
color: 'default',
|
|
},
|
|
});
|
|
|
|
interface FieldToolTipProps extends VariantProps<typeof tooltipVariants> {
|
|
children: React.ReactNode;
|
|
className?: string;
|
|
field: Field;
|
|
}
|
|
|
|
/**
|
|
* Renders a tooltip for a given field.
|
|
*/
|
|
export function FieldToolTip({ children, color, className = '', field }: FieldToolTipProps) {
|
|
const coords = useFieldPageCoords(field);
|
|
|
|
return createPortal(
|
|
<div
|
|
className={cn('pointer-events-none absolute')}
|
|
style={{
|
|
top: `${coords.y}px`,
|
|
left: `${coords.x}px`,
|
|
height: `${coords.height}px`,
|
|
width: `${coords.width}px`,
|
|
}}
|
|
>
|
|
<TooltipProvider>
|
|
<Tooltip delayDuration={0} open={!field.inserted || !field.fieldMeta}>
|
|
<TooltipTrigger className="absolute inset-0 w-full"></TooltipTrigger>
|
|
|
|
<TooltipContent className={tooltipVariants({ color, className })} sideOffset={2}>
|
|
{children}
|
|
<TooltipArrow />
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
</div>,
|
|
document.body,
|
|
);
|
|
}
|