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 🙏

© 2022 – Pkg Stats / Ryan Hefner

react-animate-props

v0.2.4

Published

React higher order component method that transforms your favorite components to animate their props on change.

Downloads

1,986

Readme

react-animate-props

React HOC (higher order component) method, and React Hook for transforming your favorite components to animate prop values on change.

This package uses Tweenkle for handling the tweening of prop values. It’s not as full-featured as GSAP, but it works pretty well for basic value and object tweening.

Install

Via npm

npm install --save react-animate-props

Via Yarn

yarn add react-animate-props

How to use

react-animate-props now offers two(!) ways for you to animate the props in both your class-based, and functional, React components.

Hook

useAnimateProps

Parameters

  • prop : Number - Value to animate
  • options : Object - Options to define the tween properties to use.

Default options:

{
  delay: 0,                           // Delay to apply before the tween starts
  duration: 1000,                     // Duration of the tween in milliseconds
  ease: Easing.Quad.Out,              // Ease to use for the tween, @see [Tweenkle](https://github.com/ryanhefner/tweenkle) for options
  onAnimateProgress: value => value,  // Callback to use during the tweening process, as well as being able to manipulate the value during the tween
  onAnimateComplete: value => value,  // Callback for when the tween has completed, as well as being able to manipulate the final value of the tween
}

Example

import React from 'react';
import { Easing } from 'tweenkle';
import { useAnimateProps } from 'react-animate-props';

const AnimatedNumberLabel = ({ number }) => {
  const animatedNumber = useAnimateProps(number, {
    ease: Easing.Quad.In,
    delay: 500,
    duration: 1500,
    onAnimateProgress: value => {
      return Math.round(value);
    },
    onAnimateComplete: value => {
      return Math.round(value);
    },
  });

  return <span>{animatedNumber}</span>;
};

export default AnimatedNumberLabel;

HOC (Higher Order Component)

animateProps is a higher order component that allows you to easily create components who’s props animate when changed.

Whether you’re writing a new component, or would like to make an animated version of an existing component, just export your component and pass it through, animateProps.

Parameters

  • component:Class - Class to apply animateProps logic to.

  • defaultProps:Object - Default props declared for the component being animated. (Default: {})

Properties

  • animatedProps:Object - Object defining which props to animate, and the tween settings for each. animateProps uses the Tweenkle tweening library, specifically a Tween instance, and you can pass whatever props that library supports via the tween settings. You can find out more by reading the Tweenkle README.

  • onAnimateProgress:Function - Callback available to manipulate the prop before it is applied to the state. (Example: (prop, value) => { return { [prop]: value }; })

  • onAnimateComplete:Function - Callback fired when the animation for a prop completes. (Example: (prop, value, tweensActive) => {})

Example

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import animateProps from 'react-animate-props';
import { Easing } from 'tweenkle';

class AnimatedNumberLabel extends Component {
  render() {
    const {
      number,
    } = this.props;

    return (
      <span>
        {number}
      </span>
    );
  }
}

AnimatedNumberLabel.propTypes = {
  animatedProps: PropTypes.object,
  number: PropTypes.number,
  onAnimateProgress: PropTypes.func,
};

AnimatedNumberLabel.defaultProps = {
  animatedProps: {
    number: {
      ease: Easing.Quad.In,
      delay: 500,
      duration: 1500,
    },
  },
  number: 0,
  onAnimateProgress: (prop, value) => {
    return {
      [prop]: Math.round(value),
    };
  },
  onAnimateComplete: (prop, value, tweensActive) => {
    return {
      [prop]: Math.round(value),
    };
  },
};

export default animateProps(
  AnimatedNumberLabel,
  AnimatedNumberLabel.defaultProps
);

License

MIT © Ryan Hefner