1.1.212 • Published 1 year ago

anim-react v1.1.212

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

React animation

This library makes possible to animate your React component with a few lines of code.

Instalation

From root directory:

npm i anim-react

or

yarn add anim-react

Usage

import { useRef } from 'react';
import { useAnim } from 'anim-react';

const myComponent = () => {
    const refToMyComponent = useRef(null); // create whatever ref
/*
    if you don't planning to interact with animation, you can proceed without "const myComponentAnimation ="
*/
    const myComponentAnimation = useAnim({
        ref: refToMyComponent, // pass ref
        animName: "slideFromLeft" // name of predefined animation config
    })
    return (
        <div ref={refToMyComponent}> MyComponent </div>  
        /* Do not forget to pass ref into your target component. */
    )
}

export default myComponent;

API

useAnim(config) | useAnim | Custom React hook | | :---- | ------ | | config | Object with 3 fields: {   ref,   animName,   userConfig, } | | ref | React ref that you currently passing to target component. - type : React.MutableRefObject<HTMLElement | null> - required Definition example: const ref = useRef(null);| | animName | You can choose one of our predefined animations , and use it without any customisations if you want. - type : String | | userConfig | Object that provides animation definition/customisation : {   isActive,   keyframes,   startInSight,    ...any other JS animation option } Here you can Read more about animation keyframes/options. | | isActive | Here you can define animation activity state (true/false)_: - type : Boolean - default : true | | keyframes | Animation frames that defines which and how style properties would be animated. Read more | | startInSight | If you want to your animation starts when target element becomes visible while scrolling provide true value here. - type : Boolean - default : false | | ...other animation options | Here you can Read more about all animation options. |

Return

const return = useAnim(...); ||| | :---- | ------ | | return | Object with next fields: {   config,   setState,   updateConfig,   hardStop,   setEndCallback, } | | config | Object that contains all current configurations.| | setState | Function that provide possibility to pause and play animation. Usage: setState( boolean ) // true or false or setState(( currentState )=> boolean ) // callback that returns true / false Example: setState( ( prev ) => !prev );| | updateConfig | Function that removing previous animation and starts new with provided in argument new config. Usage: updateConfig( { duration: 2000 } );| | hardStop | Immediate animation cancel Function.| | setEndCallback | Function that takes callback as argument. That callback will be invoked when animation will be finished or canceled. Usage: setEndCallback(() => {   console.log('Animation finished');}); |

Names

Already existing animation names: 1. slideFromLeft 2. slideFromRight 3. slideFromTop 4. slideFromBottom 5. opacityAppear

Npm package GitHub repository

1.1.212

1 year ago

1.1.210

2 years ago

1.1.209

2 years ago

1.1.208

2 years ago

1.1.207

2 years ago

1.1.206

2 years ago

1.1.205

2 years ago

1.1.204

2 years ago

1.1.203

2 years ago

1.1.202

2 years ago

1.1.201

2 years ago

1.1.200

2 years ago

1.1.122

2 years ago

1.1.121

2 years ago

1.1.120

2 years ago

1.1.119

2 years ago

1.1.118

2 years ago

1.1.117

2 years ago

1.1.116

2 years ago

1.1.115

2 years ago

1.1.114

2 years ago

1.1.113

2 years ago

1.1.112

2 years ago

1.1.111

2 years ago

1.1.110

2 years ago

1.1.109

2 years ago

1.1.108

2 years ago

1.1.107

2 years ago

1.1.106

2 years ago

1.1.105

2 years ago

1.1.104

2 years ago

1.1.103

2 years ago

1.1.102

2 years ago

1.1.101

2 years ago

1.0.9993

2 years ago

1.0.9992

2 years ago

1.0.999

2 years ago

1.0.998

2 years ago

1.0.997

2 years ago

1.0.996

2 years ago

1.0.995

2 years ago

1.0.994

2 years ago

1.0.993

2 years ago

1.0.992

2 years ago

1.0.991

2 years ago

1.0.97

2 years ago

1.0.96

2 years ago

1.0.95

2 years ago

1.0.94

2 years ago

1.0.93

2 years ago

1.0.92

2 years ago

1.0.91

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago