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

v0.1.13

Published

A higher-order components for React, which generate animation while routing jumps, using the animate.css

Downloads

16

Readme

react-router-animate

A higher-order component for animating when react-router jumping

Install

npm install react-router-animate --save
yarn add react-router-animate

You can install this higher-order component with 'npm/yarn', you need animate.css, so you must import animate.css in you index.js. Download Animate.css and place it in you src . You App should depend on react and react-transition-group.

import 'styles/animate.css'
import wrapperAnimate from 'react-router-animate'; // import hegher-order component called wrapperAnimate

Usage

This higher-order component has four parameters, the component is the first parameter, the second parameter is the animated type, the third parameter is the direction of animation, the fourth parameter is the times of animations, default 1000ms.

export default wrapperAnimate(HomePage,'fade','Left')
# ![Image text]()

Second parameter:
'bounce'、'fade'、'flip'
'lightSpeedIn'、'lightSpeedOut'、'rotate'
'slide'、'zoom'、'hinge'
'jackInTheBox'、'rollIn'、'rollOut'
<font color=Chartreuse>default: 'fade'</font>


Third parameter:
'Left'、'Right'
'Down'、'Up'
'X'、'Y'
<font color=Chartreuse>default: 'Left'</font>
First character upper case
You can use Array as the third parameter when you use 'rotate' as the second parameter to determine the direction of the animation. The first value of the Array is the direction of entry, the second value of the Array is the direction of leave.


Fourth parameter:
Number:  ms
<font color=Chartreuse>default: 1000</font>

animate type

Example

// index.js
import React, {Component} from 'react';
import {render} from 'react-dom';
import {Route, BrowserRouter, withRouter} from 'react-router-dom';
import './animate.css'; 

import HomePage from './components/Homepage';
import AddressPage from './components/AddressPage';

class App extends Component {
  render() {
  /** not with router animate
   * return (
   *  <Switch>
   *    <Route path="/login"` component={Login} />
   *    <Route path="/signup" component={Signup} />
   *    <Redirect to="/login" />
   *   </Switch>
   * );
   **/

  // with animate, useing children to make higher-order components work
    return (
      <div style={{ width: "300px", height: "500px",position: 'relative' }}>
        <div style={{ lineHeight: '50px',background: '#fff',position: 'absolute',zIndex: 100 }}
          onClick={() => {
            this.props.history.push('/home',{num: 0})
          }}
        >Home</div>
        <div style={{ lineHeight: '50px', background: '#fff',position: 'absolute', left: 100,zIndex: 100 }}
          onClick={() => {
            this.props.history.push('/address',{num: 1,})
          }}
        >Address</div>
        <Route exact path='/' children={ props => <HomePage  {...props}/>} />
        <Route path='/home' children={ props => <HomePage {...props} />} />
        <Route path='/address' children={ props => <AddressPage {...props} />} />
      </div>
    );
  }
}

const Appp = withRouter(App);

render(
  <BrowserRouter>
    <Appp />
  </BrowserRouter>,
  document.querySelector("#root")
);


// HomePage.js
import React, {Component} from 'react';
import wrapperAnimate from 'react-router-animate';

class HomePage extends Component {
  render () {
    return (
      <div style={{ width: '100%',height: '100%', lineHeight: '500px', background: 'green',position: 'absolute' }}>
        HomePage
      </div>
    )
  }
}
export default wrapperAnimate(HomePage)
// like export default wrapperAnimate(HomePage,'fade','Left',1000)

// Addresspage.js is the same code as HomePage. Js, then you can run it

You should use this.history.push with num attribute of state parameter to change router, you will don't have better animation without num attribute of state parameter.

FAQ

  • Q1: White screen? You need to add the style position: absolute to each component that goes in and out of the route jump.

  • Q2: Animation acceleration at the end? You parameter and the time in animate.css must be the same, you should change time in animate.css when you add the fourth parameter.