MCPcopy Create free account
hub / github.com/dailydotdev/apps / Tooltip

Function Tooltip

packages/shared/src/components/tooltip/Tooltip.tsx:27–89  ·  view source on GitHub ↗
({
  children,
  content,
  appendTo,
  visible = true,
  delayDuration = 200,
  className,
  enableMobileClick,
  open: controlledOpen,
  showArrow = false,
  ...props
}: TooltipProps)

Source from the content-addressed store, hash-verified

25 showArrow?: boolean;
26 };
27export function Tooltip({
28 children,
29 content,
30 appendTo,
31 visible = true,
32 delayDuration = 200,
33 className,
34 enableMobileClick,
35 open: controlledOpen,
36 showArrow = false,
37 ...props
38}: TooltipProps) {
39 const [open, setOpen] = useState(false);
40 const { isCompanion } = useRequestProtocol();
41 const container = isCompanion ? getCompanionWrapper() : appendTo;
42 const showAriaLabel = typeof content === 'string';
43 if (!visible) {
44 return children;
45 }
46
47 return (
48 <RadixPrimitive.Provider delayDuration={delayDuration}>
49 <RadixPrimitive.Root
50 open={isNullOrUndefined(controlledOpen) ? open : controlledOpen}
51 onOpenChange={setOpen}
52 >
53 <RadixPrimitive.Trigger
54 aria-label={showAriaLabel ? content.toString() : undefined}
55 asChild
56 onMouseUp={(e: React.MouseEvent) =>
57 (e.currentTarget as HTMLElement).blur()
58 }
59 {...(enableMobileClick && { onClick: () => setOpen(true) })}
60 >
61 {children}
62 </RadixPrimitive.Trigger>
63 <RadixPrimitive.Portal
64 container={container || globalThis?.document?.body}
65 >
66 <RadixPrimitive.Content
67 // The default `flex items-center gap-1.5` lays out simple content
68 // (leading icon + label + trailing shortcut). Full-bleed custom
69 // tooltips pass a single self-contained child and override the
70 // surface via className; the flex wrapper is a no-op around one item.
71 className={classNames(
72 styles.TooltipContent,
73 'z-tooltip flex max-w-[18rem] items-center gap-1.5 rounded-8 border border-border-subtlest-tertiary bg-background-subtle px-2 py-1 font-medium text-text-primary shadow-2 typo-caption1',
74 className,
75 )}
76 sideOffset={5}
77 collisionPadding={{ top: 75 }}
78 {...props}
79 >
80 {content}
81 {showArrow && (
82 <RadixPrimitive.Arrow className="TooltipArrow fill-background-subtle" />
83 )}
84 </RadixPrimitive.Content>

Callers

nothing calls this directly

Calls 4

useRequestProtocolFunction · 0.90
getCompanionWrapperFunction · 0.90
isNullOrUndefinedFunction · 0.90
setOpenFunction · 0.85

Tested by

no test coverage detected