All files / src/components/common HeroTooltip.tsx

14.63% Statements 6/41
100% Branches 0/0
0% Functions 0/1
14.63% Lines 6/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 641x 1x                         1x     1x 1x                                                                                       1x  
import { cn, Tooltip } from "@heroui/react"
import React, { useMemo } from "react"
 
interface HeroTooltipProps {
	content: React.ReactNode
	children: React.ReactNode
	className?: string
	delay?: number
	closeDelay?: number
	placement?: "top" | "bottom" | "left" | "right"
	showArrow?: boolean
	disabled?: boolean
}
 
/**
 * HeroTooltip component that wraps the HeroUI tooltip with styling
 * similar to TaskTimelineTooltip
 */
const HeroTooltip: React.FC<HeroTooltipProps> = ({
	content,
	children,
	className,
	showArrow = false,
	delay = 0,
	closeDelay = 500,
	placement = "top",
	disabled = false,
}) => {
	// If content is a simple string, wrap it in the tailwind styled divs
	const formattedContent = useMemo(() => {
		return typeof content === "string" ? (
			<div
				className={cn(
					"bg-code-background text-code-foreground border border-code-foreground/20 rounded shadow-md max-w-[250px] text-sm",
					className,
					"p-2",
				)}>
				<span className="whitespace-pre-wrap break-words overflow-y-auto">{content}</span>
			</div>
		) : (
			// If content is already a React node, assume it's pre-formatted
			content
		)
	}, [content, className])
 
	return (
		<Tooltip
			classNames={{
				content: "hero-tooltip-content pointer-events-none", // Prevent hovering over tooltip
			}}
			closeDelay={closeDelay}
			content={formattedContent} // Immediate close when cursor moves away
			delay={delay}
			disableAnimation={true}
			isDisabled={disabled}
			placement={placement} // Disable animation for immediate appearance/disappearance
			showArrow={showArrow}>
			{children}
		</Tooltip>
	)
}
 
export default HeroTooltip