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-animate-out

v0.6.0

Published

Unmounts a component after a CSS animation completes.

Downloads

8

Readme

react-animate-out

Unmounts a component after a CSS animation completes.

This component manages the mounting of a component by relying entirely on CSS animation events which provides DRY-ness and performance advantages. As such, it does not support IE9 and requires React v15 or later.

Motivation

ReactCSSTransitionGroup is overkill for a single component and requires you to re-define animation timings that you may already have defined in your CSS, leading to potential errors.

Installation

$ npm install react-animate-out

Usage

If we have a CSS class called "component-leave" and that uses a keyframe animation called "anim-close", we can apply AnimateOut to a DisplayElement component using the following logic:

import AnimateOut from 'react-animate-out'

const Module = React.createClass({
  getInitialState: function() {
    return {
      showChild: true
    }
  },

  removeChild: function() {
    this.setState({showChild: false})
  },

  render: function(props) {
    return (
      <AnimateOut showing={this.state.showChild} complete={this.removeChild}>
        <DisplayComponent>
      </AnimateOut>
    )
  }
})

function DisplayElement(props) {
  // onAnimationEnd will only be defined if we wrap DisplayElement with AnimateOut
  return (
    <div className={(props.leaving ? 'component-leave' : '')}
      onAnimationEnd={props.onAnimationEnd ?
       props.onAnimationEnd.bind(null, 'anim-close') :
       null}/>
      Your content...
    </div>
    )
}
.component-leave {
  animation-duration: 0.3s;
  animation-fill-mode: forwards;
  animation-name: anim-close;
}


@keyframes anim-close {
  0% { opacity: 1; }
  100% { opacity: 0; transform: scale3d(0.9, 0.9, 1); }
}

You can of course add an enter animation as you would do normally and use AnimateOut with CSS Modules.

API

Props accepted:

  • showing is a boolean dictating if the children should mount and should usually be tied to a state
  • complete is a function called immeditaly to request switching showing to false -- when AnimatOut has processed a close call and has taken over mounting temporarily to complete the animation. If your modal has a single possible action, this is also where you can process it.

Props passed to the child element:

  • onAnimationEnd -- to properly notify of the leave animation end, bound this function with the name of your leave animation name and call it in the onAnimationEnd callback of the element of the children component bearing the animation
  • close -- calling this function will trigger the leave animation and call to complete
  • leaving is a boolean determining that the leave animation is in progress -- you can use this to display the leaving animation

Lifecycle

Assuming the child component is a modal,

action                show modal        close -﹁ (calls complete)
                           |              |     ˅
showing (boolean)  false   `->  true      |   false
                                          |
leaving (boolean)  false        false     `-> true     false
                                                         ˄
Modal              unseen       showing       leaving    | (on animation end)
                                                         |
CSS Animaton                    show          leave -----/

showing is managed by the application using AnimateOut, leaving is managed by AnimateOut. Complete is called immediatly to minimize delays in the application and prioritize user experience, if your complete action must necessarily unmount the AnimateOut itself, then don't use an animation or AnimateOut, just manage mounting as such:

return (
  {showing &&
    <DisplayElement onClose={this.complete} />
  }
)

TODO

Include full-scale integration tests that confirm behavior through the CSS api as well as through javascript unit testing.