diff --git a/src/components/BirthdayBanner.jsx b/src/components/BirthdayBanner.jsx new file mode 100644 index 0000000..3805fc3 --- /dev/null +++ b/src/components/BirthdayBanner.jsx @@ -0,0 +1,65 @@ +import { useEffect } from 'react' +import confetti from 'canvas-confetti' + +export default function BirthdayBanner({ name = "Linh" }) { + useEffect(() => { + // Fire confetti on load + const duration = 3 * 1000 + const animationEnd = Date.now() + duration + const defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 0 } + + function randomInRange(min, max) { + return Math.random() * (max - min) + min + } + + const interval = setInterval(function() { + const timeLeft = animationEnd - Date.now() + + if (timeLeft <= 0) { + return clearInterval(interval) + } + + const particleCount = 50 * (timeLeft / duration) + confetti({ + ...defaults, + particleCount, + origin: { x: randomInRange(0.1, 0.3), y: Math.random() - 0.2 }, + }) + confetti({ + ...defaults, + particleCount, + origin: { x: randomInRange(0.7, 0.9), y: Math.random() - 0.2 }, + }) + }, 250) + + return () => clearInterval(interval) + }, []) + + const handleClick = () => { + confetti({ + particleCount: 100, + spread: 70, + origin: { y: 0.6 } + }) + } + + return ( +
+
+
+

+ 🎂 Happy Birthday {name}! 🎉 +

+

+ Chúc mừng sinh nhật! Click để ăn confetti! ✨ +

+

+ (Click anywhere for more confetti 🎊) +

+
+
+ ) +}