Skip to content

Commit 1530d4e

Browse files
committed
feat: pause carousel on hover
1 parent 9a22d8a commit 1530d4e

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/Shared/Components/LoginBanner/LoginBanner.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,32 @@ const AnimatedBackground = () => (
9999

100100
const LoginBanner = () => {
101101
const [currentIndex, setCurrentIndex] = useState<number>(0)
102+
const [isHovering, setIsHovering] = useState<boolean>(false)
103+
104+
const handleMouseEnter = () => {
105+
setIsHovering(true)
106+
}
107+
108+
const handleMouseLeave = () => {
109+
setIsHovering(false)
110+
}
102111

103112
useEffect(() => {
104113
const testimonialCount = TESTIMONIAL_CARD_DATA.length
105-
const interval = setInterval(() => {
106-
setCurrentIndex((prevIndex) => (prevIndex + 1) % testimonialCount)
107-
}, TESTIMONIAL_CARD_INTERVAL)
114+
let interval: ReturnType<typeof setInterval>
115+
116+
if (!isHovering) {
117+
interval = setInterval(() => {
118+
setCurrentIndex((prevIndex) => (prevIndex + 1) % testimonialCount)
119+
}, TESTIMONIAL_CARD_INTERVAL)
120+
}
108121

109122
return () => {
110-
clearInterval(interval)
123+
if (interval) {
124+
clearInterval(interval)
125+
}
111126
}
112-
}, [])
127+
}, [isHovering])
113128

114129
const { quote, name, designation, iconName } = TESTIMONIAL_CARD_DATA[currentIndex]
115130

@@ -150,6 +165,8 @@ const LoginBanner = () => {
150165
opacity: { duration: 0.75, ease: TRANSITION_EASE_CURVE },
151166
x: { duration: 0.85, ease: TRANSITION_EASE_CURVE },
152167
}}
168+
onMouseEnter={handleMouseEnter}
169+
onMouseLeave={handleMouseLeave}
153170
className="flexbox-col dc__gap-20"
154171
>
155172
<div className="fs-14 fw-4 lh-1-5 cn-9 dc__truncate--clamp-4">{quote}&quot;</div>

0 commit comments

Comments
 (0)