Created
April 21, 2025 15:51
-
-
Save tifandotme/eeecf32608bbaf6e0093984e4df85a32 to your computer and use it in GitHub Desktop.
confetti.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useMemo, useState } from "react"; | |
import { loadAll } from "@tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too. | |
import { type Container, type ISourceOptions } from "@tsparticles/engine"; | |
import Particles, { initParticlesEngine } from "@tsparticles/react"; | |
export function Confetti() { | |
const [init, setInit] = useState(false); | |
useEffect(() => { | |
initParticlesEngine(async (engine) => { | |
await loadAll(engine); | |
}).then(() => { | |
setInit(true); | |
}); | |
}, []); | |
const particlesLoaded = async (container?: Container): Promise<void> => { | |
console.log(container); | |
}; | |
const options: ISourceOptions = useMemo( | |
() => ({ | |
fullScreen: { | |
zIndex: 1, | |
}, | |
emitters: { | |
position: { | |
x: 50, | |
y: 100, | |
}, | |
rate: { | |
quantity: 1, | |
delay: 0.15, | |
}, | |
}, | |
particles: { | |
color: { | |
value: ["#1E00FF", "#FF0061", "#E1FF00", "#00FF9E"], | |
}, | |
move: { | |
decay: 0.05, | |
direction: "top", | |
enable: true, | |
gravity: { | |
enable: true, | |
}, | |
outModes: { | |
top: "none", | |
default: "destroy", | |
}, | |
speed: { | |
min: 50, | |
max: 100, | |
}, | |
}, | |
number: { | |
value: 0, | |
}, | |
opacity: { | |
value: 1, | |
}, | |
rotate: { | |
value: { | |
min: 0, | |
max: 360, | |
}, | |
direction: "random", | |
animation: { | |
enable: true, | |
speed: 30, | |
}, | |
}, | |
tilt: { | |
direction: "random", | |
enable: true, | |
value: { | |
min: 0, | |
max: 360, | |
}, | |
animation: { | |
enable: true, | |
speed: 30, | |
}, | |
}, | |
size: { | |
value: 3, | |
animation: { | |
enable: true, | |
startValue: "min", | |
count: 1, | |
speed: 16, | |
sync: true, | |
}, | |
}, | |
roll: { | |
darken: { | |
enable: true, | |
value: 25, | |
}, | |
enlighten: { | |
enable: true, | |
value: 25, | |
}, | |
enable: true, | |
speed: { | |
min: 5, | |
max: 15, | |
}, | |
}, | |
wobble: { | |
distance: 30, | |
enable: true, | |
speed: { | |
min: -7, | |
max: 7, | |
}, | |
}, | |
shape: { | |
type: "circle", | |
options: {}, | |
}, | |
}, | |
responsive: [ | |
{ | |
maxWidth: 1024, | |
options: { | |
particles: { | |
move: { | |
speed: { | |
min: 33, | |
max: 66, | |
}, | |
}, | |
}, | |
}, | |
}, | |
], | |
}), | |
[], | |
); | |
if (init) { | |
return ( | |
<Particles | |
id="tsparticles" | |
particlesLoaded={particlesLoaded} | |
options={options} | |
className="pointer-events-none" | |
/> | |
); | |
} | |
return <></>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment