1.0.4 • Published 5 years ago

@robcc/with-animation v1.0.4

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

@robcc/with-animation npm downloads

HOC that handles animation when mounting and unmounting a React component easily.

Installation

npm install @robcc/with-animation

Usage

withAnimation wraps your custom React component.

import React, { Component } from 'react';
import withAnimation from '@robcc/with-animation';

const Block = (
  <div className="block">
    {this.props.children}
  </div>
);

export default withAnimation(NormalBlock);

The mount property will specify if the component should be mount. Both onMount and onUnmount includes a CSS keyframe that will be executed when the component mounts or unmounts. Additional animations can be made on the component itself.

...

<button className="button" onClick={() => this.setState({ toggle: true });}>
  Toggle Class
</button>

<Block mount={toggle} onMount="in" onUnmount="out" defaultClass="wrapper" animateOnLoad={false}>
  Animated Block
</Block>
// App.css

@keyframes fadeIn {
  0% {
    opacity: 0;
    left: -200px;
  }
  100% {
    opacity: 1;
    left: 0px;
  }
}

@keyframes fadeOut {
  0% {
    opacity: 1;
    left: 0px;
  }
  100% {
    opacity: 0;
    left: 200px;
  }
}

Example

Demo

Properties

propDescription
mountDefines whether the component should be mounted on render. It's true by default.
onMountDefines a keyframe to be executed when the component is mounted.
onUnmountDefines a keyframe to be executed when the component is unmounted.
defaultClassThis sets default classes to the div created by the HOC that will be wrapping the component.
animateOnLoadDefines whether the onMount animation should be executed when the component is first rendered. It's true by default.
1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.0

5 years ago