An animated react-portal powered by react-motion
npm install react-mortalreact-portal is awesome, but it may
be tricky to animate a Portal when entering/leaving the dom. This is whatreact-mortal is solving, by combining it with the power of react-motion.
Check usage example and demo.
```
npm i react-mortal
`javascript`
onClose={handler}
motionStyle={(spring, isVisible) => ({
...motion object to pass
})}
>
{(motion, isVisible) => (
...your component
)}
#### Props
isOpened {Boolean} : Show/hide Portal instance, applying animation
onClose {Function} : Callback called when ESC key is pressed
motionStyle {Function} : Function that returns an object consumed by react-motion. See react-motion docs.
portalProps {Object} : Those props will be passed to the react-portal
onHide {Function} : Callback called when close animation has been finished
Example, to create a open/close animated modal:
`javascript
import React, { Component, PropTypes } from 'react'
import Mortal from 'react-mortal'
class AnimatedModal extends Component {
static propTypes = {
isOpened: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
}
render() {
const { isOpened, onClose } = this.props
return (
onClose={onClose}
motionStyle={(spring, isVisible) => ({
opacity: spring(isVisible ? 1 : 0),
})}
>
{(motion, isVisible, isAnimated) => (
{'modal body'}
LICENSE
`
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004Copyright (C) 2016 Meriadec Pillet
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
``