2024-10-22 22:52:56 +01:00
|
|
|
"use client";
|
|
|
|
|
2024-09-30 22:16:55 +01:00
|
|
|
import { Tooltip as ShadCnTooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
|
2024-10-22 22:52:56 +01:00
|
|
|
import { useState } from "react";
|
|
|
|
import { cn } from "@/common/utils";
|
2024-09-12 17:52:01 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
/**
|
|
|
|
* What will trigger the tooltip
|
|
|
|
*/
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* What will be displayed in the tooltip
|
|
|
|
*/
|
|
|
|
display: React.ReactNode;
|
2024-09-27 23:04:14 +01:00
|
|
|
|
2024-10-13 00:41:39 +01:00
|
|
|
/**
|
|
|
|
* Display the trigger as a child element.
|
|
|
|
*/
|
|
|
|
asChild?: boolean;
|
|
|
|
|
2024-10-20 13:59:48 +01:00
|
|
|
/**
|
|
|
|
* The additional class names
|
|
|
|
*/
|
|
|
|
className?: string;
|
|
|
|
|
2024-09-27 23:04:14 +01:00
|
|
|
/**
|
|
|
|
* Where the tooltip will be displayed
|
|
|
|
*/
|
|
|
|
side?: "top" | "bottom" | "left" | "right";
|
2024-09-12 17:52:01 +01:00
|
|
|
};
|
|
|
|
|
2024-10-20 13:59:48 +01:00
|
|
|
export default function Tooltip({ children, display, asChild = true, side = "top", className }: Props) {
|
2024-10-22 22:52:56 +01:00
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
2024-09-12 17:52:01 +01:00
|
|
|
return (
|
2024-10-23 16:44:08 +01:00
|
|
|
<ShadCnTooltip open={open}>
|
2024-10-20 13:59:48 +01:00
|
|
|
<TooltipTrigger className={className} asChild={asChild}>
|
2024-10-23 15:33:25 +01:00
|
|
|
<div
|
2024-10-22 22:52:56 +01:00
|
|
|
className={cn("cursor-default", className)}
|
|
|
|
onMouseEnter={() => setOpen(true)}
|
|
|
|
onMouseLeave={() => setOpen(false)}
|
|
|
|
onTouchStart={() => setOpen(!open)}
|
2024-10-23 16:44:08 +01:00
|
|
|
onTouchEnd={() => setOpen(!open)}
|
2024-10-22 22:52:56 +01:00
|
|
|
>
|
|
|
|
{children}
|
2024-10-23 15:33:25 +01:00
|
|
|
</div>
|
2024-10-20 13:59:48 +01:00
|
|
|
</TooltipTrigger>
|
2024-10-23 08:13:07 +01:00
|
|
|
<TooltipContent className="max-w-[350px]" side={side}>
|
|
|
|
{display}
|
|
|
|
</TooltipContent>
|
2024-09-12 17:52:01 +01:00
|
|
|
</ShadCnTooltip>
|
|
|
|
);
|
|
|
|
}
|