-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
Tooltip.tsx
54 lines (50 loc) · 1.44 KB
/
Tooltip.tsx
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
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import React from "react";
import { useIsPlatform } from "@calcom/atoms/monorepo";
import classNames from "@calcom/lib/classNames";
export function Tooltip({
children,
content,
open,
defaultOpen,
onOpenChange,
delayDuration,
side = "top",
...props
}: {
children: React.ReactNode;
content: React.ReactNode;
delayDuration?: number;
open?: boolean;
defaultOpen?: boolean;
side?: "top" | "right" | "bottom" | "left";
onOpenChange?: (open: boolean) => void;
} & TooltipPrimitive.TooltipContentProps) {
const isPlatform = useIsPlatform();
const Content = (
<TooltipPrimitive.Content
{...props}
className={classNames(
"calcom-tooltip",
side === "top" && "-mt-7",
side === "right" && "ml-2",
"bg-inverted text-inverted relative z-50 rounded-md px-2 py-1 text-xs font-semibold shadow-lg",
props.className && `${props.className}`
)}
side={side}
align="center">
{content}
</TooltipPrimitive.Content>
);
return (
<TooltipPrimitive.Root
delayDuration={delayDuration || 50}
open={open}
defaultOpen={defaultOpen}
onOpenChange={onOpenChange}>
<TooltipPrimitive.Trigger asChild>{children}</TooltipPrimitive.Trigger>
{isPlatform ? <>{Content}</> : <TooltipPrimitive.Portal>{Content}</TooltipPrimitive.Portal>}
</TooltipPrimitive.Root>
);
}
export default Tooltip;