A tiny configurable wrapper for animating dom elements as they mount or unmount
- Optional hooks for binding to mount / unmount sequence complete.
- Comes with a simple fade animation but everything can be overriden by providing a custom animationsMap
npm install react-metro
Create a sequence, map it:
// in method renderMetroComponents:// mount / unmountif!thisstateshowMetroComponentsreturn nullconst data = 'cat' 'dog'return Metro
& render it:
<TransitionGroupPlus> // optional arg type="li/div/ul..."this</TransitionGroupPlus>
// override Metro´s default animations settings for each unique item in your items// array, see greensock tweenmax for reference.const animationMap =in:time: 3delay: 0out:time: 14delay: 1willEnter:from: opacity: 0 y: 120 x: 30to: opacity: 1 y: 0 x: 0 ease: "easeInOutElastic"out:time: 14delay: 0willEnter:from: opacity: 0 y: 120 x: -30to: opacity: 1 y: 0 x: 0 ease: "easeInOutElastic";// Metro comes with a simple, fade in / out default. This object passed// in as the third argument in the Metro.sequence overrides the default settings.const defaultAnimationOverride =animation:out:time: 05delay: 0in:time: 1delay: 0willEnter:from: opacity: 0 y: 50to: opacity: 1 y: 0 ease: "easeInOutQuad"willLeave:from:opacity: 1y: 0to: opacity: 0 y: 50 ease: "easeInOutQuad";
wrapperType // dom element, defaults to divonClick // receives props (original array data) and array indexonMount // fires when the mount sequence completesonUnmount // fires when the unmount sequence completes
The real power of Metro shines through it's use of dynamic animationMaps.
The second demo demonstrates the concept of dynamic sequences. This is achieved by altering the sequence´s animationMap on user interaction.
We define an animatonMap to achieve the delayed entrance effect we want. Since the active animationMap is stored in our wrapper component´s local state we can replace our initial map on user interaction, thus making the animation interactive.
Even though the developer has total control of an animation through the use of custom animationMaps, we created a helper method called Metro.generateFocusMap for cases where you want to accentuate a specific item within your sequence without having to write logic.
These presets - today a total of 4: verticalDelayed, dominoForwards, dominoBackwards, dominoMulti, is something that you as a developer are more than welcome to contribute to. Ideas for upcoming presets are stuff like 'checkerBoard' / 'wave' / 'circular' etc...
Each preset should try to incorporate the focus-first logic as they are intended to accentuate a clicked component. Current api for using the method is:
const domino = Metrothis // -> do unmount logic...
PRs are welcomed, to contribute make sure that:
- Branch name references issue number if it adresses a feature / bug fix.
- Branch has already been synced with the upstream repo and any merge-conflicts have been resolved.
- Install eslint and prettier to avoid lint issues while developing
Please be descriptive