-
-
Save christiannwamba/11bb8f9c1fc2fdf0ec9d216fbbd22bac to your computer and use it in GitHub Desktop.
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
//BlackBoxAnimated.js | |
import React, { Component } from 'react'; | |
import styled from 'styled-components'; | |
import PropTypes from 'prop-types'; | |
import { Motion, spring } from 'react-motion'; | |
const BlackBox = styled.div` | |
height: ${props => props.heightPercentage}%; | |
width: 100%; | |
background: #000; | |
transform-origin: ${props => props.xDirection} center; | |
`; | |
const BlackBoxAnimated = ({ | |
startAnimation = false, | |
heightPercentage, | |
reverseDirection = false | |
}) => ( | |
<Motion | |
defaultStyle={{ scaleX: 1 }} | |
style={{ scaleX: spring(startAnimation ? 0 : 1) }} | |
> | |
{style => ( | |
<BlackBox | |
heightPercentage={heightPercentage} | |
xDirection={reverseDirection ? `left` : `right`} | |
style={{ | |
transform: `scaleX(${style.scaleX})` | |
}} | |
/> | |
)} | |
</Motion> | |
); | |
BlackBoxAnimated.propTypes = { | |
startAnimation: PropTypes.bool, | |
heightPercentage: PropTypes.number.isRequired, | |
reverseDirection: PropTypes.bool | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment