-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
48 lines (44 loc) · 1.3 KB
/
index.tsx
File metadata and controls
48 lines (44 loc) · 1.3 KB
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
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
import classNames from 'classnames';
import type { FC, PropsWithChildren, ReactNode } from 'react';
import styles from './index.module.css';
type TooltipProps = {
asChild?: boolean;
content: ReactNode;
kind?: 'default' | 'warning' | 'error';
side?: TooltipPrimitive.TooltipContentProps['side'];
container?: HTMLElement | null;
};
const Tooltip: FC<PropsWithChildren<TooltipProps>> = ({
kind = 'default',
children,
content,
asChild = false,
side = 'bottom',
container,
}) => (
<TooltipPrimitive.Provider delayDuration={200}>
<TooltipPrimitive.Root>
<TooltipPrimitive.Trigger asChild={asChild}>
{children}
</TooltipPrimitive.Trigger>
<TooltipPrimitive.Portal container={container}>
<TooltipPrimitive.Content
side={side}
sideOffset={4}
className={classNames(styles[kind], styles.content, {
'mx-1.5': side === 'top' || side === 'bottom',
})}
>
{content}
<TooltipPrimitive.Arrow
className={styles.arrow}
width={14}
height={6}
/>
</TooltipPrimitive.Content>
</TooltipPrimitive.Portal>
</TooltipPrimitive.Root>
</TooltipPrimitive.Provider>
);
export default Tooltip;