Giter VIP home page Giter VIP logo

react-rewards's Introduction

react-rewards logo

npm version forthebadge

Demo available here!

Usage

Why should I even 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 easily add microinteractions to your app and reward users with the rain of confettis or flying emoji 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 him that something went wrong.

react-rewards demo

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 rain:
this.reward.rewardMe();
// to "punish" user :
this.reward.punishMe();

Props & config

Basic props:

name type description required default
ref func function that creates a ref of the reward component yes
type string 'confetti' or 'emoji' no 'confetti'
config object a configuration object described below no see below

Config object:

name type description default (confett / emoji)
lifetime number time of life of each particle in ms 200 / 200
angle number initial direction of particles in degrees 90 / 90
decay number how much the velocity decreases with each frame 0.91 / 0.91
spread number spread of particles in degrees 45 / 100
startVelocity number initial velocity of particles 35 / 20
elementCount number particles quantity 40 / 15
elementSize number particle size in px 8 / 20
zIndex number z-index of particles 10 / 10
springAnimation bool whether the button should be animated true
colors array An array of colors used when generating confettis
emoji array An array of emoji used when generating emoji particles

This package was based on React-Pose and react-dom-confetti.

react-rewards's People

Contributors

thedevelobear avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.