"use client"; import { useEffect, useState } from "react"; interface Particle { id: number; x: number; y: number; color: string; rotation: number; velocity: { x: number; y: number }; } export function ConfettiEffect() { const [particles, setParticles] = useState([]); useEffect(() => { const colors = ["#6366F1", "#A855F7", "#EC4899", "#10B981", "#F59E0B"]; const newParticles: Particle[] = []; for (let i = 0; i < 30; i++) { newParticles.push({ id: i, x: 50 + (Math.random() - 0.5) * 20, y: 50, color: colors[Math.floor(Math.random() * colors.length)], rotation: Math.random() * 360, velocity: { x: (Math.random() - 0.5) * 100, y: -Math.random() * 100 - 50, }, }); } setParticles(newParticles); const timer = setTimeout(() => { setParticles([]); }, 3000); return () => clearTimeout(timer); }, []); if (particles.length === 0) return null; return (
{particles.map((particle) => (
))}
); }