Created
March 20, 2019 15:11
-
-
Save archiewald/7ba390738a75a4e287f863404e789be3 to your computer and use it in GitHub Desktop.
[dynamic react element] #react #typescript
This file contains hidden or 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 * as React from 'react'; | |
import * as classNames from 'classnames'; | |
export interface FadeInProps { | |
when: boolean; | |
delay?: number; | |
duration?: number; | |
distance?: string; | |
order?: number; | |
className?: string; | |
wrapperElement?: keyof React.ReactHTML; | |
} | |
export const FadeIn: React.StatelessComponent<FadeInProps> = ({ | |
when, | |
delay = 0, | |
duration = 1200, | |
distance = '100px', | |
order, | |
children, | |
className, | |
wrapperElement = 'div', | |
}) => { | |
const Wrapper = wrapperElement; | |
return ( | |
<Wrapper | |
style={{ | |
transform: when ? `translateY(0)` : `translateY(${distance})`, | |
opacity: when ? 1 : 0, | |
transitionDelay: | |
typeof order !== 'undefined' | |
? `${CASCADE_DELAY * order}ms` | |
: `${delay}ms`, | |
transitionDuration: `${duration}ms`, | |
}} | |
className={classNames(className)} | |
> | |
{children} | |
</Wrapper> | |
); | |
}; | |
export const CASCADE_DELAY = 400; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment