3.0.0 • Published 6 years ago

react-animation-components v3.0.0

Weekly downloads
440
License
MIT
Repository
github
Last release
6 years ago

react-animation-components

Travis

A set of React components using React Transition Group to provide drop in GPU accelerated animations and wrappers for group effects.

Checkout the Storybook!

Installation

npm install react-animation-components

Make sure you also have installed the following peer dependencies:

    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "react-transition-group": "^2.2.1",
    "prop-types": "^15.6.0"

Animation Components

Props available on all animation components

The following are available on any animation component as well as any valid Transition props. Transitions are set to appear and their timeout is calculated by combining the delay and duration by default but can be overwritten.

KeyDescriptionExampleTypeDefault Value
classNamePasses className to wrapper divsome-classstringundefined
delaySets the animations transitionDelay500number0
durationSets the animations transitionDuration1000number500
stylePasses styles to wrapper div{ display:'flex' }object{}
timingFnSets the animations transitionTimingFunction'ease-in-out'string'ease'

Fade

Transitions the wrapped element's opacity from one value to another

Props

KeyDescriptionExampleTypeDefault Value
enterOpacityThe opacity value when in is true0.85number0
exitOpacityThe opacity value when in is false0.25number0

Examples

import { Fade } from 'react-animation-components'

<Fade in>
  <h1>I'm transitioning to opacity:1</h1>
</Fade>

<Fade in enterOpacity={0.85}>
  <h1>I'm transitioning to opacity:0.85</h1>
</Fade>

<Fade in={false}>
  <h1>I'm transitioning to opacity:0</h1>
</Fade>

<Fade in={false} exitOpacity={0.25}>
  <h1>I'm transitioning to opacity:0.25</h1>
</Fade>

Transform

Transitions the wrapped element from one transform property to another. Any valid transform property will work.

Props

KeyDescriptionExampleTypeDefault Value
enterTransformThe transform value when in is true'translateX(100px)'string'none'
exitTransformThe transform value when in is false'translateX(100px)'string'none'

Examples

import { Transform } from 'react-animation-components'

<Transform enterTransform="translateX(100px)" in>
  <h1>I'm transitioning from my initial position to 100px right when `in` is `true`</h1>
</Transform>

<Transform enterTransform="translateX(100px)" exitTransform="translateX(-100px)" in>
  <h1>
    I'm 100px to the left of my initial position and
    I transition 100px right of my initial when `in` is `true`
  </h1>
</Transform>

<Transform enterTransform="rotate(90deg)" in>
  <h1>I transition from initial positon to rotate 90deg when `in` is `true`</h1>
</Transform>

FadeTransform

Composes Fade and Transform. All top level props are passed to both components. You can also pass props to individual components in the composition.

Props passed to indivudal components via fadeProps or transformProps will override any top level props

Props

KeyDescriptionExampleTypeDefault Value
fadePropsThe props that only Fade recieves.{ enterOpacity: 0.85 }object{}
transformPropsThe props that only Transform recieves.{ enterTransform: 'translateX(100px)' }object{}

Examples

import { FadeTransform } from 'react-animation-components'

<FadeTransform in transformProps={{ enterTransform: 'translateX(100px)' }}>
  <h1>I'm transitioning from my initial position to 100px right when `in` is `true`</h1>
</FadeTransform>

<FadeTransform
    in
    transformProps={{
        enterTransform: 'translateX(100px)',
        exitTransform: 'translateX(-100px)'
    }}
>
  <h1>
    I'm 100px to the left of my initial position and
    I transition 100px right of my initial when `in` is `true`
  </h1>
</FadeTransform>

<FadeTransform
    in
    transformProps={{
        exitTransform: 'translateX(-100px)'
    }}
    fadeProps={{
        enterOpacity: 0.85,
    }}
>
  <h1>I transition from `-100px` horizontally of my initial positon and to 0.85 opacity when `in` is `true`</h1>
</FadeTransform>

Wrapper Components

Wrapper components use the inner animation components onEntered and onExited. Setting those callbacks inside these wrappers will not work

Stagger

Uses TransitionGroup to stagger delay on a set of animation components

Props

KeyDescriptionExampleTypeDefault Value
chunkUsed to limit the stagger into "chunks".5number0
delayThe amount to separate each stagger by1000number100
durationA value to set the inner child animations transition duration800number500
inA boolean to tell the children to mount or unmounttruebooleanfalse
onCompleteA function that is called after the last animation finishesany valid functionfunctionFunction.prototype(noop)
reverseA boolean to tell the component to reverse how delays are appliedtruebooleanfalse

Examples

import { Fade, Stagger } from 'react-animation-components'

const items = ['first', 'second', 'third', 'fourth', 'fifth'];

<Stagger in>
    {items.map(
        item => (
            <Fade>
                <h1>Each {item} will transition in with an incrementally larger delay than the previous</h1>
            </Fade>
        )
    )}
</Stagger>

<Stagger chunk={4} in>
    {items.map(
        item => (
            <Fade>
                <h1>
                  Each {item} will increment in segments of 4.
                  First is 0, Second is 100, Third is 200, Fourth is 0, fifth is 100, and so on
                </h1>
            </Fade>
        )
    )}
</Stagger>

Random

Uses TransitionGroup to randomize delay on a set of animation components

Props

KeyDescriptionExampleTypeDefault Value
durationA value to set the inner child animations transition duration800number500
inA boolean to tell the children to mount or unmounttruebooleanfalse
maxDelayMaximum delay possible5000number1500
minDelayMinimum delay possible100number0
onCompleteA function that is called after the last animation finishesany valid functionfunctionFunction.prototype(noop)
reverseA boolean to tell the component to reverse how delays are appliedtruebooleanfalse

Examples

import { Fade, Random } from 'react-animation-components'

const items = ['first', 'second', 'third', 'fourth', 'fifth'];

<Random in>
    {items.map(
        item => (
            <Fade>
                <h1>Each {item} will randomly FadeIn between 0 and 1500ms</h1>
            </Fade>
        )
    )}
</Random>

<Random minDelay={1000} maxDelay={5000} in>
    {items.map(
        item => (
            <Fade>
                <h1>Each {item} will randomly FadeIn between 1000ms and 5000ms</h1>
            </Fade>
        )
    )}
</Random>

Loop

Loops using the onEntered and onExited callbacks to toggle in on a single animation component.

Props

KeyDescriptionExampleTypeDefault Value
inInitializes the loop when truetrueboolfalse
intervalSets the interval to toggle in. Also sets the duration1000number500
iterationsMaximum number of loops5.5numberInfinity
onCompleteCallback that is called when the iterations have been met. Waits an additional interval to ensure its called when the last iteration has completedany valid functionfunctionFunction.prototype(noop)
onIterateCallback that is called with the current count each time the loop iterates. Count is incremented by 0.5any valid functionfunctionFunction.prototype(noop)

Examples

import { Fade, Loop } from 'react-animation-components'

<Loop in>
    <Fade>
        <h1>I will Fade in and out repeatedly on 500ms intervals</h1>
    </Fade>
</Loop>

<Loop in iterations={5.5}>
    <Fade>
        <h1>I will Fade in and out repeatedly on 500ms intervals 5.5 times</h1>
    </Fade>
</Loop>
3.0.0

6 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago