mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
feat: init saajan component
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
@@ -0,0 +1,53 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import sf_mini from "../../assets/sf_mini.png";
|
||||||
|
|
||||||
|
interface SaajanProps {
|
||||||
|
message: string;
|
||||||
|
position?: "top" | "left" | "right" | "bottom";
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Saajan({ message, position = "right" }: SaajanProps) {
|
||||||
|
const [animate, setAnimate] = useState<boolean>(false);
|
||||||
|
const [tooltipPosition, setTooltipPosition] =
|
||||||
|
useState<string>("tooltip-right");
|
||||||
|
const [alignment, setAlignment] = useState<string>("justify-start");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setAnimate(true);
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
setAnimate(false);
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTooltipPosition(`tooltip-${position}`);
|
||||||
|
if (position === "top") {
|
||||||
|
setAlignment("justify-center");
|
||||||
|
}
|
||||||
|
if (position === "right") {
|
||||||
|
setAlignment("justify-start");
|
||||||
|
}
|
||||||
|
if (position === "left") {
|
||||||
|
setAlignment("justify-end");
|
||||||
|
}
|
||||||
|
}, [position]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`relative w-full flex ${alignment}`}>
|
||||||
|
<div
|
||||||
|
className={`tooltip tooltip-open ${tooltipPosition} before:max-w-xs before:whitespace-pre-line italic before:text-left`}
|
||||||
|
data-tip={message}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={sf_mini}
|
||||||
|
alt="saajan"
|
||||||
|
className={`sepia-20 w-35 -mb-3 ${animate ? "animate-[pulse_.5s_ease_2]" : ""}`}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user