File tree Expand file tree Collapse file tree 2 files changed +35
-13
lines changed
Expand file tree Collapse file tree 2 files changed +35
-13
lines changed Original file line number Diff line number Diff line change 11import { ClassNames , keyframes } from '@emotion/react' ;
22import React , { ReactElement } from 'react' ;
3+ import { css } from 'twin.macro' ;
34
45export type Orientation = 'left' | 'right' | 'up' | 'down' | 'none' ;
56
@@ -17,21 +18,38 @@ export const FadeIn = ({
1718 duration = 0.2 ,
1819 distance = 10 ,
1920 children,
20- } : FadeInProps ) : ReactElement => {
21- return (
22- < ClassNames >
23- { ( { css /*cx*/ } ) => {
24- const animation = css `
25- opacity: 0;
26- animation: ${ fadeIn ( orientation , distance ) } ${ duration } s ease-in-out
27- ${ delay } s forwards;
28- ` ;
29- return < div className = { animation } > { children } </ div > ;
30- } }
31- </ ClassNames >
32- ) ;
21+ } : FadeInProps ) : ReactElement => (
22+ < ClassNames >
23+ { ( { css } ) => (
24+ < div
25+ className = { css `
26+ ${ mkFadeInCss ( { orientation, delay, duration, distance } ) }
27+ ` }
28+ >
29+ { children }
30+ </ div >
31+ ) }
32+ </ ClassNames >
33+ ) ;
34+
35+ type MkFadeInCssArgs = {
36+ orientation : Orientation ;
37+ delay : number ;
38+ duration : number ;
39+ distance : number ;
3340} ;
3441
42+ export const mkFadeInCss = ( {
43+ orientation,
44+ delay,
45+ duration,
46+ distance,
47+ } : MkFadeInCssArgs ) => css `
48+ opacity: 0;
49+ animation: ${ fadeIn ( orientation , distance ) } ${ duration } s ease-in-out ${ delay } s
50+ forwards;
51+ ` ;
52+
3553const fadeIn = ( orientation : Orientation , distance : number ) : string => {
3654 return keyframes `
3755 from {
Original file line number Diff line number Diff line change 44export { FadeIn } from './components/FadeIn' ;
55export { ZoomIn } from './components/ZoomIn' ;
66
7+ // --------------------------- CSS
8+
9+ export { mkFadeInCss } from './components/FadeIn' ;
10+
711// --------------------------- Utils
812
913export { getCounter , getIncrementor } from './lib/getCounter' ;
You can’t perform that action at this time.
0 commit comments