Skip to content

Instantly share code, notes, and snippets.

@archiewald
Created March 20, 2019 15:11
Show Gist options
  • Save archiewald/7ba390738a75a4e287f863404e789be3 to your computer and use it in GitHub Desktop.
Save archiewald/7ba390738a75a4e287f863404e789be3 to your computer and use it in GitHub Desktop.
[dynamic react element] #react #typescript
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