Code Monkey home page Code Monkey logo

react-hero-transition's Introduction

react-hero-transition

A library to help create beutiful hero transitions for view changes. It tracks mounting and unmounting of components and is therfore not dependant on react-router or any other way of managing different views. It is based on the principle of FLIP animations and uses getBoundingClientRect to calculate the position and size of the old and the new element, the new element is then animated using transforms from the position of the old element.

Transitions can be applied using either react-motion or css transitions. You can also write your own renderer that animates in whatever way you prefer.

Usage

First wrap your app with <TransitionProvider> similarly to the provider of react-redux. Then wrap your "heroes" with the <Hero> component.

A basic example:

<TransitionProvider>
  <Row>
    <Column>
      <Box>
        {position === 0 && <Hero id='position'><Number>0</Number></Hero>}
      </Box>
      {position !== 0 && <button onClick={() => this.setState({position: 0})}>Move here</button>}
    </Column>
    <Column>
      <Box>
        {position === 1 && <Hero id='position'><Number>1</Number></Hero>}
      </Box>
      {position !== 1 && <button onClick={() => this.setState({position: 1})}>Move here</button>}
    </Column>
  </Row>
</TransitionProvider>

API

TransitionProvider

Props

timeout
  • Type: number
  • required: no
  • default value: 100

How much time in ms it may pass between an element beeing removed and added for a hero transition to be run.

renderer
  • Type: Renderer
  • required: no
  • default value: cssTransition

Which renderer to use for performing transitions

Hero

Props

id
  • Type: string
  • required: yes

A hero will transition to another hero with the same id. It should be unique per page but be repeated on the pages it should transition between.

children
  • Type: ReactElement
  • required: no

A hero must either have a render prop or be provided with a single child. The child will be provided a ref and a style prop and must therfore be either a browser element or a class component, not a function component as those can't have refs.

render
  • Type: ({heroIn: boolean}) => ReactElement
  • required: no

If a render function is provided, it will be called with a single argument containing an object with a heroIn property. heroIn will be true if the hero will perform an hero transition and false otherwise. This can be used to for example show a fade in animation instead. The function should return a single rendered ReactElement that corresponds to the same rules as for the children prop.

Example

To start the example run

yarn
yarn start

in the example folder

react-hero-transition's People

Contributors

pajn avatar

Stargazers

I Kadek Adi Gunawan avatar  avatar taroodr avatar Tarek avatar Piotr Bartoszewski avatar Bruno Calou avatar Ben McMahen avatar  avatar duke79 avatar  avatar Johan Alm avatar Kirill Nikolaev avatar yuuki arisawa avatar  avatar Morgan Intrator avatar Timon van Spronsen avatar Travis Arnold avatar Sean Lynch avatar Andric Tham avatar

Watchers

James Cloos avatar  avatar

react-hero-transition's Issues

How To Run

Hi,

I've cloned the repo to my local. But, I don't see the way how to run the app. Would you please add the instruction to README.md? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.