Files
personal-site/components/AnimatedName.js
T

36 lines
946 B
JavaScript
Raw Normal View History

2025-12-03 03:24:29 +01:00
import { useState, useEffect } from 'react';
import { profile } from '../data/profile';
2025-12-03 03:24:29 +01:00
const names = profile.handles;
2025-12-03 03:24:29 +01:00
export default function AnimatedName() {
const [currentIndex, setCurrentIndex] = useState(0);
const [isAnimating, setIsAnimating] = useState(false);
useEffect(() => {
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
let timeout;
2025-12-03 03:24:29 +01:00
const interval = setInterval(() => {
setIsAnimating(true);
timeout = setTimeout(() => {
2025-12-03 03:24:29 +01:00
setCurrentIndex((prevIndex) => (prevIndex + 1) % names.length);
setIsAnimating(false);
}, 350);
}, 3000);
2025-12-03 03:24:29 +01:00
return () => {
clearInterval(interval);
clearTimeout(timeout);
};
2025-12-03 03:24:29 +01:00
}, []);
return (
<span className="animated-name" aria-label={names[0]}>
<span aria-hidden="true" className={isAnimating ? 'is-leaving' : 'is-entering'}>
2025-12-03 03:24:29 +01:00
{names[currentIndex]}
</span>
</span>
);
}