2023-06-05 08:53:47 +03:00
|
|
|
"use client";
|
|
|
|
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
|
|
import { AnimatePresence, motion } from "framer-motion";
|
2023-06-15 12:52:46 +03:00
|
|
|
import { ReactNode, useState } from "react";
|
2023-06-05 08:53:47 +03:00
|
|
|
|
|
|
|
interface TooltipProps {
|
|
|
|
children?: ReactNode;
|
|
|
|
tooltip?: ReactNode;
|
|
|
|
}
|
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
const Tooltip = ({ children, tooltip }: TooltipProps): JSX.Element => {
|
2023-06-05 08:53:47 +03:00
|
|
|
const [open, setOpen] = useState(false);
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2023-06-05 08:53:47 +03:00
|
|
|
return (
|
|
|
|
<TooltipPrimitive.Provider>
|
|
|
|
<TooltipPrimitive.Root onOpenChange={setOpen} open={open}>
|
|
|
|
<TooltipPrimitive.Trigger asChild>{children}</TooltipPrimitive.Trigger>
|
|
|
|
<AnimatePresence>
|
|
|
|
{open && (
|
|
|
|
<TooltipPrimitive.Portal forceMount>
|
|
|
|
<TooltipPrimitive.Content sideOffset={5} asChild>
|
|
|
|
<motion.div
|
|
|
|
initial={{ y: 10, opacity: 0 }}
|
|
|
|
animate={{
|
|
|
|
y: 0,
|
|
|
|
opacity: 1,
|
|
|
|
transition: { ease: "easeOut", duration: 0.1 },
|
|
|
|
}}
|
|
|
|
exit={{
|
|
|
|
y: 10,
|
|
|
|
opacity: 0,
|
|
|
|
transition: { ease: "easeIn", duration: 0.1 },
|
|
|
|
}}
|
|
|
|
// transition={{ duration: 0.2, ease: "circInOut" }}
|
|
|
|
className="select-none rounded-md border border-black/10 dark:border-white/25 bg-white dark:bg-gray-800 px-5 py-3 text-sm leading-none shadow-lg dark:shadow-primary/25"
|
|
|
|
>
|
|
|
|
{tooltip}
|
|
|
|
<TooltipPrimitive.Arrow className="fill-white dark:fill-black" />
|
|
|
|
</motion.div>
|
|
|
|
</TooltipPrimitive.Content>
|
|
|
|
</TooltipPrimitive.Portal>
|
|
|
|
)}
|
|
|
|
</AnimatePresence>
|
|
|
|
</TooltipPrimitive.Root>
|
|
|
|
</TooltipPrimitive.Provider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Tooltip;
|