Skip to main content
Glama
text-with-tooltip.tsx1.45 kB
import React, { useRef, useState, useCallback, useEffect } from 'react'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from '@/components/ui/tooltip'; import { cn } from '@/lib/utils'; interface TextWithTooltipProps { tooltipMessage: string; children: React.ReactElement< React.HTMLAttributes<HTMLDivElement> & { ref?: React.Ref<HTMLDivElement> } >; } export const TextWithTooltip = ({ tooltipMessage, children, }: TextWithTooltipProps) => { const textRef = useRef<HTMLDivElement>(null); const [isTruncated, setIsTruncated] = useState(false); const checkTruncation = useCallback(() => { if (textRef.current) { setIsTruncated(textRef.current.scrollWidth > textRef.current.clientWidth); } }, []); useEffect(() => { checkTruncation(); window.addEventListener('resize', checkTruncation); return () => window.removeEventListener('resize', checkTruncation); }, [checkTruncation]); const childWithRef = React.cloneElement(children, { ref: textRef, className: cn('truncate', children.props.className), }); if (!isTruncated) { return childWithRef; } return ( <TooltipProvider> <Tooltip> <TooltipTrigger asChild>{childWithRef}</TooltipTrigger> <TooltipContent className="max-w-md wrap-break-word whitespace-normal"> <p>{tooltipMessage}</p> </TooltipContent> </Tooltip> </TooltipProvider> ); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/activepieces/activepieces'

If you have feedback or need assistance with the MCP directory API, please join our Discord server