npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-canvas-confetti

v2.0.7

Published

React component for canvas-confetti library

Downloads

296,050

Readme

react-canvas-confetti

The React component for canvas-confetti library. In the demo version, you can play with the settings and see examples.

npm NPM

GIF-confetti

Installation

npm i react-canvas-confetti

:exclamation: It is expected that the react is already installed as peer dependency.

Usage

I recommend that you first familiarize yourself with the canvas-confetti library to better understand exactly how this module works.

There are two ways to use this module:

Working with Presets

A preset is an animation template that is already ready to use. Presets allow you to customize animation settings, but do not allow you to change the animation algorithm. Using presets is an easier way to work with the module.

import Fireworks from "react-canvas-confetti/dist/presets/fireworks";

function Example() {
  return <Fireworks autorun={{ speed: 3 }} />;
}

export default Example;

Live example

Conductor Instance

The preset working can be controlled manually using the Conductor instance. This object allows you to start and stop animations on demand. Conductor can be accessed in the onInit callback. The interface of the object is shown below:

type TRunAnimationParams = {
  speed: number;
  duration?: number;
  delay?: number;
};

type TConductorInstance = {
  run: (params: TRunAnimationParams) => void;
  shoot: () => void;
  pause: () => void;
  stop: () => void;
};

Working with the canvas-confetti instance

Working with an instance is working with the module at a lower level. This is a more powerful approach that allows you to create your own animation algorithms, but requires more effort.

Canvas-confetti instance

Confetti object, which will be received as a result of calling the function create. Gives you full control to create your own animations. Confetti can be accessed in the onInit callback. The interface can be viewed here

API

Base API

The common settings are relevant for all use cases

| Name | Type | Description | | ------------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | width | string | number | value is responsible for the width of the canvas. Alternative ways to control canvas sizes are className and style props. | | height | string | number | value is responsible for the height of the canvas. Alternative ways to control canvas sizes are className and style props. | | className | string | value to set className to canvas element | | style | CSSProperties | value to set style to canvas element. If style and className are not passed, the default styles will be set | | globalOptions | TGlobalOptions | global animation settings that cannot be changed after initialization (details) | | onInit | (params: {confetti: TCanvasConfettiInstance}) => void | the callback is called when the component is mounted on the page and allows you to access confetti instance (details) for manual animation creation |

Advanced API

Advanced settings only work for presets!

| Name | Type | Description | | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | autorun | { speed: number; duration?: number; delay?: number; } | if it is passed, it automatically starts the animation when mounting the component on the page | | decorateOptions | (options: TOptions) => TOptions | the callback allows you to customize the animation settings and is called for each step of the animation | | onInit | (params: { confetti: TCanvasConfettiInstance; conductor: TConductorInstance }) => void | the callback is called when the component is mounted on the page and allows you to access objects for manual creation and animation control |

Examples

Fireworks Preset

Crossfire Preset

Snow Preset

Realistic Preset

Explosion Preset

Pride Preset

Vortex Preset

Photons Preset

Manual Control

Decorating Options

Custom Stylization

Custom Animation