1.1.1 • Published 8 years ago

react-fade v1.1.1

Weekly downloads
163
License
ISC
Repository
github
Last release
8 years ago

npm travis standard

react-fade

Simple fades in React

npm i react-fade

Fade in

Children components will start invisible and fade into a visible state.

<Fade>
  <p>I am so faded</p>
</Fade>

Fade out

Fade out requires some extra code to stay invisble after it's been faded-out. Right now, the recommended way of using <Fade out/> is to utilize the duration property in conjuction with css display or visibilty. For example:

import { default as React, Component } from 'react'
import { default as Fade } from 'react-fade'

const fadeDuration = 10

class FadeExample extends Component {

  state = {
    fadeOut: false,
    visibility: 'visible'
  }

  componentDidUpdate(nextProps, { fadeOut }) {
    if (fadeOut) {
      setTimeout(() => {
        this.setState({
          visibility: 'hidden'
        })
      }, fadeDuration)
    }
  }
  
  render() {
    return (
      <div>
        <Fade
          out={this.state.fadeOut}
          duration={fadeDuration}
          style={{
            visibility: this.state.visibility
          }}
        >
          <p>I am so faded</p>
        </Fade>
        <button onClick={() => this.setState({ fadeOut: true })}>
          Fade out
        </button>
      </div>
    )
  }
}

Props

PropTypeDescription
outboolfades out instead of in - see instructions for usage patterns
durationnumberthe amount of time in seconds that it takes to fade in or out