All Projects → dgpedro → react-component-transition

dgpedro / react-component-transition

Licence: MIT license
Easy animations between react component transitions.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-component-transition

Reason Loadable
🔥 Suspense/Lazy for ReasonReact.
Stars: ✭ 88 (+340%)
Mutual labels:  lazy
Itiriri
A library built for ES6 iteration protocol.
Stars: ✭ 155 (+675%)
Mutual labels:  lazy
SwiftTweener
A pure Swift animation engine.
Stars: ✭ 74 (+270%)
Mutual labels:  transitions
Lazybones
😴 A super lazy and fluent Kotlin expressions for initializing lifecycle-aware property.
Stars: ✭ 91 (+355%)
Mutual labels:  lazy
Lazy Rdp
Script for automatic scanning & brute-force RDP
Stars: ✭ 118 (+490%)
Mutual labels:  lazy
React Echarts Modules
这个例子给你提供在react中使用echarts的最优方案
Stars: ✭ 185 (+825%)
Mutual labels:  lazy
Lazy Vue
A small lazy image loader for Vue
Stars: ✭ 63 (+215%)
Mutual labels:  lazy
lazy-load-images.js
Progressive & lazy loading images.
Stars: ✭ 17 (-15%)
Mutual labels:  lazy
Lazy Collections
Collection of fast and lazy operations
Stars: ✭ 146 (+630%)
Mutual labels:  lazy
lazy-kit
A new design system for developing with less effort. See how it looks:
Stars: ✭ 68 (+240%)
Mutual labels:  lazy
Pimg
📷 Mini Image Lazy Loader for P(R)eact and Vue
Stars: ✭ 97 (+385%)
Mutual labels:  lazy
Lazyhub
lazyhub - Terminal UI Client for GitHub using gocui.
Stars: ✭ 133 (+565%)
Mutual labels:  lazy
Vue Cheatsheet
Modified version of the official VueMastery cheatsheet
Stars: ✭ 188 (+840%)
Mutual labels:  lazy
Imlazy
😴 Functional programming with lazy immutable iterables
Stars: ✭ 89 (+345%)
Mutual labels:  lazy
laravelmanthra
Laravel Crud Generator, I have working for years and I can tell you... It's all CRUD 💩💩💩
Stars: ✭ 27 (+35%)
Mutual labels:  lazy
Iter
Simple iterator abstract datatype, intended to iterate efficiently on collections while performing some transformations.
Stars: ✭ 71 (+255%)
Mutual labels:  lazy
Hitchcock
The Master of Suspense 🍿
Stars: ✭ 167 (+735%)
Mutual labels:  lazy
nvim-config
My neovim config
Stars: ✭ 63 (+215%)
Mutual labels:  lazy
UnityGUI
UGUI Panel Systems for navigation, animation and more
Stars: ✭ 80 (+300%)
Mutual labels:  transitions
Lazyblorg
Blogging with Org-mode for very lazy people
Stars: ✭ 226 (+1030%)
Mutual labels:  lazy

react-component-transition

Easy to use react component to apply animations between component transitions, by using Web Animations API.

Demo

https://dgpedro.github.io/react-component-transition/

Install

npm install react-component-transition --save

NOTE

This package was built using react hooks therefore it requires minimum version 16.8.0 of reactjs.


Typescript

Types are included in the package.

Goal

The main goal is to provide an easy and fast way to apply simple animations when transitioning from one component to another, without loosing too much time testing, adjusting, styling, etc... With a couple of code lines, it's possible to make any react page much more interactive and user friendly.

Polyfills

Depending on the browser to support, some polyfills might be needed:

Usage

ComponentTransition

import { ComponentTransition, AnimationTypes } from "react-component-transition";
const Component = () => {

    // ...

    return (
        <ComponentTransition
            enterAnimation={AnimationTypes.scale.enter}
            exitAnimation={AnimationTypes.fade.exit}
        >
            {showDetails ? <Details /> : <Summary />}
        </ComponentTransition>
    );
};

Presets

Presets are components that have enterAnimation and exitAnimation already set, for an easier and cleaner usage.

import { Presets } from "react-component-transition";
const Component = () => {
    
    // ...

    return (
        <Presets.TransitionFade>
            {show && <Details />}
        </Presets.TransitionFade>
    );
};

There's a preset available for each AnimationTypes.

ComponentTransitionList

To be used with lists. Simply return a ComponentTransition or any preset in your map function and wrap it all with a ComponentTransitionList.

import { ComponentTransitionList, Presets } from "react-component-transition";
const Component = () => {
    
    // ...

    return (
        <ComponentTransitionList>
            {list.map((listItem, index) =>
                <Presets.TransitionScale key={index}>
                    <ListItem {...listItem} />
                </Presets.TransitionScale>
            )}
        </ComponentTransitionList>
    );
};

With react-router

import { useLocation } from "react-router-dom";
const AppRoutes = () => {
    const location = useLocation();
    return (
        <ComponentTransition
            enterAnimation={AnimationTypes.slideUp.enter}
            exitAnimation={AnimationTypes.slideDown.exit}
        >
            <Switch key={location.key} location={location}>
                <Route ... />
                <Route ... />
                <Route ... />
            </Switch>
        </ComponentTransition>
    );
};
import { BrowserRouter } from "react-router-dom";
const App = () => (
    <BrowserRouter>
        <AppRoutes />
    </BrowserRouter>
);

Custom animation

import { ComponentTransition, AnimationTypes } from "react-component-transition";
const Component = () => {

    // ...

    return (
        <ComponentTransition
            enterAnimation={[
                AnimationTypes.slideUp.enter,
                AnimationTypes.fade.enter,
            ]}
            exitAnimation={[{
                keyframes: [
                    { transform: "translate3d(0,0,0)" },
                    { transform: "translate3d(0,50%,0)" },
                    { transform: "translate3d(0,80%,0)" },
                    { transform: "translate3d(0,90%,0)" },
                    { transform: "translate3d(0,100%,0)" },
                ],
                options: {
                    duration: 500,
                    easing: "cubic-bezier(0.83, 0, 0.17, 1)",
                }
            },
            {
                keyframes: [
                    { opacity: 1 },
                    { opacity: 0.3 },
                    { opacity: 0.1 },
                    { opacity: 0 },
                ],
                options: {
                    duration: 300,
                }
            }]
            }
        >
            <Details key={selectedTab} />
        </ComponentTransition>
    );
};

API

AnimationTypes

AnimationTypes are a set of animations already defined that can be used in enterAnimation and/or exitAnimation props. Availabe ones are:

collapse.(horizontal|vertical)
expand.(horizontal|vertical)
fade.(enter|exit)
rotate.(enter|exit)
rotateX.(enter|exit)
rotateY.(enter|exit)
scale.(enter|exit)
slideDown.(enter|exit)
slideLeft.(enter|exit)
slideRight.(enter|exit)
slideUp.(enter|exit)

For each type of AnimationTypes there's a respective preset.

props

All presets and the ComponentTransition will wrap their children in a div element. This div is the element that will animate when children are unmounting or mounting and is also referenced here as "container".

Name Type Default Description
animateContainer boolean false if true the container will also animate from the exit component size to the enter component size
NOTE: All presets have this prop set to true by default
animateContainerDuration number 300 Duration in milliseconds of the container animation
animateContainerEasing string "ease" Easing of container animation
animateOnMount boolean false if true, applies enterAnimation when component mounts in the initial render
className string undefined CSS class to set in the container element
classNameEnter string undefined CSS class to set in the container element during enterAnimation
classNameExit string undefined CSS class to set in the container element during exitAnimation
disabled boolean false disable all animations
enterAnimation AnimationSettings | AnimationSettings[] undefined Web Animations API parameters to be applied when new component mounts
exitAnimation AnimationSettings | AnimationSettings[] undefined Web Animations API parameters to be applied when current component will unmount
lazy boolean false Will apply enterAnimation and exitAnimation if the component is visible in the viewport by using the Intersection Observer API. If true container element will always be in the DOM
lazyOptions IntersectionOptions undefined Intersection Observer options
onEnterFinished () => void undefined Callback when enterAnimation finishes
onExitFinished () => void undefined Callback when exitAnimation finishes
style React.CSSProperties undefined Inline styles to set in the container element

Examples

Clone the repo first and then:

npm install
npm start
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].