/** * Tooltip animation preview components for the admin settings UI. */ import React from "react"; import { getExtensionTooltipAnimationDuration } from "./presentationConstants"; export type TooltipAnimationPreviewProps = { anim: string; tooltipBgColor: string; tooltipTextColor: string; tooltipFontSize: number | string; fadeInEnabled?: boolean; fadeOutEnabled?: boolean; }; /** * Small tooltip animation preview tile (for animation picker grid). */ export function TooltipAnimationPreview({ anim, tooltipBgColor, tooltipTextColor, tooltipFontSize, fadeInEnabled = true, fadeOutEnabled = false, }: TooltipAnimationPreviewProps): React.ReactElement { const [tooltipKey, setTooltipKey] = React.useState(0); const [isHovered, setIsHovered] = React.useState(false); const [isHiding, setIsHiding] = React.useState(false); const hideTimeoutRef = React.useRef(null); React.useEffect(() => { return () => { if (hideTimeoutRef.current) { clearTimeout(hideTimeoutRef.current); } }; }, []); const handleMouseLeave = () => { if (fadeOutEnabled) { setIsHiding(true); hideTimeoutRef.current = window.setTimeout(() => { setIsHovered(false); setIsHiding(false); }, getExtensionTooltipAnimationDuration(anim)); } else { setIsHovered(false); setIsHiding(false); } }; const handleMouseEnter = () => { if (hideTimeoutRef.current) { clearTimeout(hideTimeoutRef.current); hideTimeoutRef.current = null; } setIsHiding(false); setIsHovered(true); setTooltipKey((prev) => prev + 1); }; return (
A
{isHovered && (() => { const animateClass = anim !== "none" && fadeInEnabled && !isHiding ? `b3-wvs-animate-tooltip-${anim}` : ""; const animateOutClass = anim !== "none" && isHiding && fadeOutEnabled ? `b3-wvs-animate-tooltip-${anim}-out` : ""; return (
Preview
); })()}
{anim}
); }