Guest User

Untitled

a guest
Nov 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import * as React from 'react'
  2. import { Transition } from 'react-transition-group'
  3.  
  4. const defaultDuration = 200
  5.  
  6. type Props = {
  7. in: boolean
  8. keyProp: string
  9. duration?: number // ms
  10. style?: any
  11. transitionStyle?: any
  12. }
  13. type State = {}
  14.  
  15. class FadeIn extends React.Component<Props, State> {
  16. static defaultProps = {}
  17.  
  18. state: State = {}
  19.  
  20. constructor(props: Props) {
  21. super(props)
  22. }
  23.  
  24. render() {
  25. const defaultStyle = {
  26. transition: `opacity ${this.props.duration || defaultDuration}ms ease-in-out`,
  27. opacity: 0,
  28. }
  29.  
  30. const transitionStyle = {
  31. entering: { opacity: 1 },
  32. entered: { opacity: 1 },
  33. }
  34.  
  35. return (
  36. <Transition
  37. key={this.props.keyProp}
  38. in={this.props.in}
  39. timeout={this.props.duration || defaultDuration}
  40. appear
  41. >
  42. {status => (
  43. <div
  44. style={{
  45. ...defaultStyle,
  46. ...this.props.style,
  47. ...transitionStyle[status],
  48. ...this.props.transitionStyle[status],
  49. }}
  50. >
  51. {this.props.children}
  52. </div>
  53. )}
  54. </Transition>
  55. )
  56. }
  57. }
  58.  
  59. export default FadeIn
Add Comment
Please, Sign In to add comment