New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-confetti-blast

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-confetti-blast

A lightweight css-animation based confetti exploder for React

latest
npmnpm
Version
1.0.2
Version published
Weekly downloads
2.2K
-0.5%
Maintainers
0
Weekly downloads
 
Created
Source

React Confetti Blast

The package is inspired by this beautiful and oft-used confetti which uses canvas, but equally inspired by how many bad looking CSS examples there are out there. The goal was to create a super lightweight confetti component that would not require canvas, use only CSS for animation, and could also be controlled as an explosion (rather than raining confetti), without the need to write a full-blown particle generator.

This package is an updated version of react-confetti-explosion, which looks like it's no longer being maintained.

Install:

$ npm install react-confetti-blast

Usage

import ConfettiExplosion from 'react-confetti-blast';
import * as React from 'react';

function App() {
  const [isExploding, setIsExploding] = React.useState(true);
  return <>{isExploding && <ConfettiExplosion />}</>;
}

Updates from react-confetti-explosion

  • Remove dependency on react-jss in favour of no styling dependencies
  • Update peer dependencies to react 19.x
  • Remove yarn.lock

Optional Props

NameTypeDefaultDescription
particleCountnumber100Total number of particles used. Generally try to stay under 400 for optimal performance.
particleSizenumber12Size of particles in pixels. This means width for squares, diameter for circles. Note there is also a bit of randomness added to these.
durationnumber2200Duration of explosion in ms. This is the time it takes particles to travel from explosion point to the floor, as defined by height.
onCompletefunctionundefinedFunction that is called at end of duration
zIndexnumberundefinedzIndex that will be applied to the explosion, in case higher Portal stacking order is required.
colorsstring[][
'#FFC700',
'#FF0000',
'#2E3191',
'#41BBC7'
]
An array of any css-readable colors, which are evenly distributed across the number of total particles.
forcenumber0.5Between 0-1, roughly the vertical force at which particles initially explode. Straying too far away from 0.5 may start looking...interesting.
heightnumber string'120vh'Pixel distance the particles will vertically spread from initial explosion point.
widthnumber1000Pixel distance the particles will horizontally spread from initial explosion point.

Although the above properties of the explosion is controlled, mounting/unmounting is entirely left to the consumer.

Potential gotchas

  • The height is defaulted to 120vh in an attempt to guarantee particles land past the bottom of the viewport, which may not be ideal in some scenarios.
  • If using a string for relative height (vh or % for example), the relative height changes between mobile/desktop screens, which means different looking explosions.
  • If your height is too small, particles may visibly land on the floor instead of disappearing off-screen.
  • The ConfettiExplosion is appended to the document body via ReactDOM.createPortal() to ensure it is positioned correctly and layered above all page content. Make sure to remember to unmount it when your explosion is finished!

To keep the library as little as possible much of the physics have been estimated, cheapened, and downright mutilated. There are certainly prop combinations that will not look realistic, due to the limitations of CSS animations. But there should be enough options to fit most needs.

Examples

See src/example.tsx as an example app, bootstrapped with Create React App.

This can be run locally with npm run start.

Large explosion

{
  force: 0.8,
  duration: 3000,
  particleCount: 250,
  width: 1600,
}

confetti-large-edit

Medium explosion

{
  force: 0.6,
  duration: 2500,
  particleCount: 80,
  width: 1000,
}

confetti-small-edit

Small explosion

{
  force: 0.4,
  duration: 2200,
  particleCount: 30,
  width: 400,
}

confetti-tiny

Author

Originally authored by herrethan Currently maintained by muhashi

License

Original code licensed under MIT license by herrethan. Current package is licensed under MIT as well.

Keywords

confetti

FAQs

Package last updated on 16 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts