"use client"; import React, { useLayoutEffect } from 'react'; declare global { interface Window { particlesJS: any; } } interface ParticlesBackgroundProps { colors?: string[]; size?: number; countDesktop?: number; countTablet?: number; countMobile?: number; zIndex?: number; height?: string; } const ParticlesBackground: React.FC = ({ colors = ['#ff223e', '#5d1eb2', '#ff7300'], size = 3, countDesktop = 60, countTablet = 50, countMobile = 40, zIndex = 0, height = '100vh', }) => { useLayoutEffect(() => { const script = document.createElement('script'); script.src = "https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"; script.onload = () => { const particlesElement = document.getElementById('js-particles'); if (particlesElement && window.particlesJS) { const getParticleCount = () => { const screenWidth = window.innerWidth; if (screenWidth > 1024) return countDesktop; if (screenWidth > 768) return countTablet; return countMobile; }; window.particlesJS('js-particles', { particles: { number: { value: getParticleCount(), }, color: { value: colors, }, shape: { type: 'circle', }, opacity: { value: 1, random: false, }, size: { value: size, random: true, }, line_linked: { enable: false, }, move: { enable: true, speed: 2, direction: 'none', random: true, straight: false, out_mode: 'out', }, }, interactivity: { detect_on: 'canvas', events: { onhover: { enable: false, }, onclick: { enable: false, }, resize: true, }, }, retina_detect: true, }); } }; document.body.appendChild(script); return () => { document.body.removeChild(script); }; }, [colors, size, countDesktop, countTablet, countMobile]); return (
); }; export default ParticlesBackground;