Created
October 12, 2018 02:59
-
-
Save rhostem/88bb66c6c20336eb8d325064170d5522 to your computer and use it in GitHub Desktop.
[React] transition - SlideInFromRight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { Transition } from 'react-transition-group' | |
const defaultDuration = 400 | |
const initialRight = '-1024px' | |
const enteredRight = '0' | |
const defaultStyle = { | |
position: 'relative', | |
transition: `all ${defaultDuration}ms ease-in-out`, | |
opacity: 1, | |
} | |
const transitionStyles = { | |
entering: { position: 'absolute', right: initialRight }, | |
entered: { right: enteredRight }, | |
exiting: { opacity: 0 }, | |
exited: { opacity: 0 }, | |
} | |
type Props = { | |
in: boolean, | |
keyProp: string, | |
duration: number, | |
style?: any, | |
} | |
type State = {} | |
/** | |
* 화면 우측에서 슬라이드 인 | |
* | |
* @class FadeIn | |
* @extends {Component} | |
*/ | |
class FadeIn extends Component { | |
props: Props | |
state: State | |
static defaultProps = {} | |
constructor(props: Props) { | |
super(props) | |
this.state = {} | |
} | |
render() { | |
return ( | |
<Transition | |
key={this.props.keyProp} | |
in={this.props.in} | |
timeout={this.props.duration || defaultDuration} | |
appear | |
unmountOnExit | |
> | |
{status => ( | |
<div | |
style={{ | |
...defaultStyle, | |
...this.props.style, | |
...transitionStyles[status], | |
}} | |
> | |
{this.props.children} | |
</div> | |
)} | |
</Transition> | |
) | |
} | |
} | |
export default FadeIn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment