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-css-in-js-animator

v1.0.0

Published

This package allows you to chain setState changes to trigger CSS-in-JS flags to extend style objects to create complex animations

Downloads

3

Readme

react-css-in-js-animator

This package allows you to chain setState changes to trigger CSS-in-JS flags to extend style objects to create complex animations

Documentation:

Importing:

Import the package into a React file

import animator from 'react-css-in-js-animator';

I recommend assigning the import object from the module as animator when importing

How to Use:

This package contains 1 method and 1 class.


animator.keyframe( obj, delay )

  • obj: (Type: Object) -- Object literal representing state changes to be performed at every keyframe.
ex: {clicked: true, shakeLeft: true};
  • delay: (Type: Number) -- Number in (ms) corresponds to the amount set in the setTimeouts within the buildReel method.

Must be instantiated using ES6 JavaScript class instantiation. This allows for a quick and repeatable way to create a patterned object literal to be used inside of the buildReel method.

When creating a first frame in a series, the delay time does not matter as it is not recorded in the construction of the animation reel.

Example Usage:

let keyframe1 = new animator.keyframe({clicked: true}, 100);

animator.buildReel( setStateFunction, onClickFunction, [ keyframes ... ] )

  • setStateFunction: (Type: Function) -- In order to make this approach work, one must pass in the setState function from the React component, but must be bound first.

Ex:

let reel = animator.buildReel(this.setState.bind(this), ... )
  • onClickFunction: (Type: Function) -- Option for engineer to pass in a function to be ran to simulate an onClick function. If no function needs to be ran, must be stub with an anonymous function.

Ex:

...buildReel(this.setState.bind(this), () => {}, ... )
  • keyframes: This is where you list all of the frames to be animated. Input currently doesn't support an array format, since it relies on an array.slice call to select a specific range.

Ex:

let frame1 = new animator.keyframe({clicked: true}, 0);
let frame2 = new animator.keyframe({clicked: false, 400});
let reel = buildReel(this.setState.bind(this), () => {}, frame1, frame2 );

To define an animation, we simply make a method that exists on a stateful, class-based component.

class CurrentImage extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      shakeLeft: false,
      shakeRight: false
    };
    this.shakeAnimation = this.shakeAnimation.bind(this);
  }
  
.
.
.

  shakeAnimation() {
    let keyframe1 = new animator.keyframe({shakeLeft: true}, 0);
    let keyframe2 = new animator.keyframe({shakeLeft: false, shakeRight: true}, 100);
    let keyframe3 = new animator.keyframe({shakeRight: false}, 100);
    let reel = animator.buildReel(this.setState.bind(this), () => {}, keyframe1, keyframe2, keyframe3);
    reel();
  }

In the example above, we have defined the shakeAnimation method on the currentImage class component.

To build the animation, I constructed 3 keyframes. Each one of these keyframes will update the state of the component, allowing me to use these state flags as means to extend different style objects onto components, creating the CSS-in-JS application.

After creating the 3 keyframes, I construct a reel by calling the buildReel method, passing the bound setState function, a stubbed out onClick function, and my 3 keyframes listed. This returns a function that contains the constructed animation chain.

We then call the function that returned from the buildReel.

You can then use this method anywhere you would use a click handling function.