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-tiny-crossfade

v2.2.0

Published

A component that helps you apply transitions when replacing one component with another

Downloads

4,929

Readme

react-tiny-crossfade

npm version

TinyCrossfade is a lightweight component for adding css transitions when replacing one component with another. Specifically, TinyCrossfade does these things:

  • Measures height and applies it inline so you can add a transition
  • Adds class names when children are mounting/unmounting so you can add your animation effects.

tiny-crossfade

Browser support:

TinyCrossfade needs requestAnimationFrame and element.classList in order to do its thing, so make sure to add polyfills if you need to support older browsers (like IE9 and below).

Why it exists

There are a couple of other libraries like this, like react-crossfade or react-css-transition-replace. These usually use react-transition-group which is great, but in some cases it is just too big a library if you just want to do simple css stuff. TinyCrossfade is meant to be a smaller alternative and uses react-tiny-transition instead, which is a much smaller library.

Other Tiny libraries

Install

npm install --save react-tiny-crossfade

API:

children : React element Single React element. The element must have a key, in order for react-tiny-crossfade to tell whether to animate or not. See example below


component : String = "div" Type of element used for the wrapper node


duration : Number = 500 The duration of your css transition (milliseconds)


disableInitialAnimation : Boolean = false Disable the animation when TinyTransition mounts


classNames : Object =

{
	beforeEnter: "before-enter",
	entering: "entering",
	beforeLeave: "before-leave",
	leaving: "leaving"
}

Classnames to use when mounting / unmounting


Example usage:

import TinyCrossfade from "react-tiny-crossfade";

...

<TinyCrossfade className="component-wrapper">
  {this.state.showComponentA
  	 ? <ComponentA key="a" /> // NOTE: Key is required for animations to work
  	 : <ComponentB key="b" />
  }
</TinyCrossfade>

CSS example:

TinyCrossfade will add the following class names (unless you provided your own). When your child component is mounting, before-enter will be applied. Here's where you put the initial styles of your mounting animation. One frame later, entering will be applied, which is where you put the final animation styles as well as a transition property. Same logic for unmounting-transition.

(Remember to add transition and overflow to the wrapper if you want animated height)

.component-wrapper {
  transition: height 0.5s;
  overflow: hidden;
}

.before-enter {
  opacity: 0;
}

.entering {
  opacity: 1;
  transition: opacity 0.5s;
}

.before-leave {
  opacity: 1;
}

.leaving {
  opacity: 0;
  transition: opacity 0.5s;
}