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-rewards

v2.0.4

Published

This package lets you easily add micro-interactions to your app and reward users with the rain of confetti, emoji or balloons.

Downloads

140,121

Readme

react-rewards logo

npm version forthebadge

:evergreen_tree: Tree-shakeable :female_detective: Built with TypeScript :package: 3.6kB gzipped

This package was inspired by react-dom-confetti.

React-rewards lets you add micro-interactions to your app, and rewards users with the rain of confetti, emoji or balloons in seconds. Firing confetti all over the page may seem like a questionable idea, but keep in mind that rewarding users for their actions is not. If a huge cloud of smiling emoji doesn't fit your application well, try changing the physics config to make it more subtle.

You can read more on the subject of micro-interactions in my blog post – https://www.thedevelobear.com/post/microinteractions/

Confetti

Balloons

Emoji

Installation

Install from npm by typing npm install react-rewards or yarn add react-rewards while in your package.json directory.

Usage

In order to use the rewards, you'll need to provide an element that will become the origin of the animation. This element needs to have an ID that matches the one used inside the hook - it can be anywhere in the DOM as long as the IDs match.

You can place the element inside a button, center it and shoot up from the button. You can place it on top of the viewport with position: "fixed" and change the angle to 270, to shoot downwards. Try, experiment, have fun!

Animation particles are set to position: 'fixed' by default, but this can be changed through a config object.

Single reward

TIP: Try using <span id=“rewardId” style={{width: 2, height: 2, background: “red”}} /> to place the element correctly, wherever you want. Then just remove the styles.

import { useReward } from 'react-rewards';
...
const { reward, isAnimating } = useReward('rewardId', 'confetti');
...
<button
    disabled={isAnimating}
    onClick={reward}
>
    <span id="rewardId" />
    🎉
</button>

Multiple rewards

TIP: You can use the same ID to shoot from the same spot, or provide separate elements with unique IDs.

import { useReward } from 'react-rewards';
...
const {reward: confettiReward, isAnimating: isConfettiAnimating} = useReward('confettiReward', 'confetti');
const {reward: balloonsReward, isAnimating: isBalloonsAnimating} = useReward('balloonsReward', 'balloons');
...
<button
    disabled={isConfettiAnimating || isBalloonsAnimating}
    onClick={() => {
        confettiReward();
        balloonsReward();
    }}
>
    <span id="confettiReward" />
    <span id="balloonsReward" />
    🎉
</button>

Props & config

useReward params:

| name | type | description | required |default | |-----------------|--------|--------------------------------------------------------|------------|-------------| | id | string | A unique id of the element you want to shoot from | yes | | | type | string | 'confetti' | 'balloons' | 'emoji' | yes |'confetti' | | config | object | a configuration object described below | no |see below |

Confetti config object:

| name | type | description | default | |-----------------|--------|--------------------------------------------------------|---------------------------| | lifetime | number | time of life | 200 | | angle | number | initial direction of particles in degrees | 90 | | decay | number | how much the velocity decreases with each frame | 0.94 | | spread | number | spread of particles in degrees | 45 | | startVelocity | number | initial velocity of particles | 35 | | elementCount | number | particles quantity | 50 | | elementSize | number | particle size in px | 8 | | zIndex | number | z-index of particles | 0 | | position | string | one of CSSProperties['position'] - e.g. "absolute" | "fixed" | | colors | string[]| An array of colors used when generating confetti |['#A45BF1', '#25C6F6', '#72F753', '#F76C88', '#F5F770']| | onAnimationComplete | () => void | A function that runs when animation completes | undefined |

Balloons config object:

| name | type | description | default | |-----------------|--------|--------------------------------------------------------|---------------------------| | lifetime | number | time of life | 600 | | angle | number | initial direction of balloons in degrees | 90 | | decay | number | how much the velocity decreases with each frame | 0.999 | | spread | number | spread of balloons in degrees | 50 | | startVelocity | number | initial velocity of the balloons | 3 | | elementCount | number | balloons quantity | 10 | | elementSize | number | balloons size in px | 20 | | zIndex | number | z-index of balloons | 0 | | position | string | one of CSSProperties['position'] - e.g. "absolute" | "fixed" | | colors | string[]| An array of colors used when generating balloons |['#A45BF1', '#25C6F6', '#72F753', '#F76C88', '#F5F770']| | onAnimationComplete | () => void | A function that runs when animation completes | undefined |

Emoji config object:

| name | type | description | default | |-----------------|--------|--------------------------------------------------------|---------------------------| | lifetime | number | time of life | 200 | | angle | number | initial direction of emoji in degrees | 90 | | decay | number | how much the velocity decreases with each frame | 0.94 | | spread | number | spread of emoji in degrees | 45 | | startVelocity | number | initial velocity of emoji | 35 | | elementCount | number | emoji quantity | 20 | | elementSize | number | emoji size in px | 25 | | zIndex | number | z-index of emoji | 0 | | position | string | one of CSSProperties['position'] - e.g. "absolute" | "fixed" | | emoji | string[]| An array of emoji to shoot |['🤓', '😊', '🥳'] | | onAnimationComplete | () => void | A function that runs when animation completes | undefined |