1.1.1 • Published 5 years ago

react-rewards-lm v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

react-rewards logo

npm version forthebadge

Demo available here!

Usage

This package was built using React-Pose, react-dom-confetti and Lottie-web.

Why should I use that? Read my blog post and you will know – https://www.thedevelobear.com/post/microinteractions/

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

This package lets you add microinteractions to your app, and rewards users with the rain of confettis, flying emoji or memphis design particles in seconds. In order to make it rain, you need to wrap your button of choice with the \<Reward> component, fire the rewardMe() method from the refs and voilà. You can also "punish" the user by calling the punishMe() method and showing them that something went wrong.

import Reward from 'react-rewards';

// in render
<Reward
  ref={(ref) => { this.reward = ref }}
  type='emoji'
>
  <button onClick={this.fetchSomeData} />
</Reward>

// in fetchSomeData:
// to reward a user with confetti/emoji/memphis rain:
this.reward.rewardMe();
// to "punish" user :
this.reward.punishMe();

Props & config

Basic props:

nametypedescriptionrequireddefault
reffuncfunction that creates a ref of the reward componentyes
typestring'confetti', 'emoji' or 'memphis'no'confetti'
configobjecta configuration object described belownosee below

Config object:

nametypedescriptiondefault (confetti / emoji)
lifetimenumbertime of life of each particle in ms200 / 200
anglenumberinitial direction of particles in degrees90 / 90
decaynumberhow much the velocity decreases with each frame0.91 / 0.91
spreadnumberspread of particles in degrees45 / 100
startVelocitynumberinitial velocity of particles35 / 20
elementCountnumberparticles quantity40 / 15
elementSizenumberparticle size in px8 / 20
zIndexnumberz-index of particles10 / 10
springAnimationboolwhether the button should be animatedtrue
colorsarrayAn array of colors used when generating confettis
emojiarrayAn array of emoji used when generating emoji particles