-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCallHint.tsx
91 lines (80 loc) · 2.49 KB
/
CallHint.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"use client";
import { useState, useEffect } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { ChevronDown } from "lucide-react";
interface CallHintProps {
text?: string;
timeoutDuration?: number;
onDismiss?: () => void;
targetId?: string;
}
const CallHint = ({
text = "Click CALL to start the interview",
timeoutDuration = 5000,
onDismiss,
targetId,
}: CallHintProps) => {
const [isVisible, setIsVisible] = useState(true);
useEffect(() => {
// Set timeout to hide the hint after specified duration
const timeout = setTimeout(() => {
setIsVisible(false);
if (onDismiss) onDismiss();
}, timeoutDuration);
// Add click event listener to the target button if targetId is provided
if (targetId) {
const targetElement = document.getElementById(targetId);
if (targetElement) {
const clickHandler = () => {
setIsVisible(false);
if (onDismiss) onDismiss();
clearTimeout(timeout);
};
targetElement.addEventListener("click", clickHandler);
// Clean up event listener
return () => {
targetElement.removeEventListener("click", clickHandler);
clearTimeout(timeout);
};
}
}
// Clean up timeout
return () => clearTimeout(timeout);
}, [timeoutDuration, onDismiss, targetId]);
return (
<AnimatePresence>
{isVisible && (
<motion.div
className="absolute left-1/2 transform -translate-x-1/2 -translate-y-full mb-6 flex flex-col items-center"
initial={{ opacity: 0, y: -10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -10 }}
transition={{ duration: 0.3 }}
>
<motion.div
className="bg-dark-300/80 backdrop-blur-sm text-white px-4 py-2 rounded-lg shadow-lg text-center"
initial={{ scale: 0.95 }}
animate={{ scale: 1 }}
transition={{ duration: 0.2 }}
>
<p className="text-sm font-medium">{text}</p>
</motion.div>
<motion.div
animate={{
y: [0, 5, 0],
}}
transition={{
repeat: Infinity,
duration: 1.5,
ease: "easeInOut"
}}
className="text-primary-200 mt-1"
>
<ChevronDown size={24} />
</motion.div>
</motion.div>
)}
</AnimatePresence>
);
};
export default CallHint;