-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(stepper): split body and content animations (#1288)
*refactor(stepper): split body and content animations --------- Co-authored-by: Radoslav Karaivanov <rkaraivanov@infragistics.com>
- Loading branch information
1 parent
2b08ef2
commit 5fb5ee2
Showing
6 changed files
with
179 additions
and
47 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,127 @@ | ||
import { fadeIn, fadeOut } from '../../animations/presets/fade/index.js'; | ||
import { growVerIn, growVerOut } from '../../animations/presets/grow/index.js'; | ||
import { EaseOut } from '../../animations/easings.js'; | ||
import { | ||
slideInHor, | ||
slideOutHor, | ||
} from '../../animations/presets/slide/index.js'; | ||
import { animation } from '../../animations/types.js'; | ||
type AnimationReferenceMetadata, | ||
animation, | ||
} from '../../animations/types.js'; | ||
|
||
const baseOptions: KeyframeAnimationOptions = { | ||
duration: 320, | ||
easing: EaseOut.Quad, | ||
}; | ||
|
||
const noopAnimation = () => animation([], {}); | ||
export type Animation = 'grow' | 'fade' | 'slide' | 'none'; | ||
export const animations = new Map( | ||
|
||
export type AnimationOptions = { | ||
keyframe: KeyframeAnimationOptions; | ||
step?: object; | ||
}; | ||
|
||
const fadeIn = (options: AnimationOptions = { keyframe: baseOptions }) => | ||
animation([{ opacity: 0 }, { opacity: 1 }], options.keyframe); | ||
|
||
const fadeOut = (options: AnimationOptions = { keyframe: baseOptions }) => | ||
animation([{ opacity: 1 }, { opacity: 0 }], options.keyframe); | ||
|
||
const slideInHor = ( | ||
options: AnimationOptions = { | ||
keyframe: baseOptions, | ||
} | ||
) => | ||
animation( | ||
[{ transform: 'translateX(100%)' }, { transform: 'translateX(0)' }], | ||
options.keyframe | ||
); | ||
|
||
const slideOutHor = ( | ||
options: AnimationOptions = { | ||
keyframe: baseOptions, | ||
} | ||
) => | ||
animation( | ||
[{ transform: 'translateX(0)' }, { transform: 'translateX(-100%)' }], | ||
options.keyframe | ||
); | ||
|
||
const growVerIn = ( | ||
options: AnimationOptions = { | ||
keyframe: baseOptions, | ||
step: {}, | ||
} | ||
) => | ||
animation( | ||
[ | ||
{ opacity: 1, ...options.step }, | ||
{ opacity: 1, height: 'auto' }, | ||
], | ||
options.keyframe | ||
); | ||
|
||
const growVerOut = ( | ||
options: AnimationOptions = { | ||
keyframe: baseOptions, | ||
step: {}, | ||
} | ||
) => | ||
animation( | ||
[ | ||
{ opacity: 1, height: 'auto' }, | ||
{ opacity: 1, ...options.step }, | ||
], | ||
options.keyframe | ||
); | ||
|
||
const noopAnimation = () => animation([], {}); | ||
|
||
const animationPair = (animations: { | ||
in: (options: AnimationOptions) => AnimationReferenceMetadata; | ||
out: (options: AnimationOptions) => AnimationReferenceMetadata; | ||
}) => { | ||
return new Map( | ||
Object.entries({ | ||
in: animations.in, | ||
out: animations.out, | ||
}) | ||
); | ||
}; | ||
|
||
export const bodyAnimations = new Map( | ||
Object.entries({ | ||
grow: animationPair({ | ||
in: growVerIn, | ||
out: growVerOut, | ||
}), | ||
fade: animationPair({ | ||
in: noopAnimation, | ||
out: noopAnimation, | ||
}), | ||
slide: animationPair({ | ||
in: slideInHor, | ||
out: slideOutHor, | ||
}), | ||
none: animationPair({ | ||
in: noopAnimation, | ||
out: noopAnimation, | ||
}), | ||
}) | ||
); | ||
|
||
export const contentAnimations = new Map( | ||
Object.entries({ | ||
grow: new Map( | ||
Object.entries({ | ||
in: growVerIn, | ||
out: growVerOut, | ||
}) | ||
), | ||
fade: new Map( | ||
Object.entries({ | ||
in: fadeIn, | ||
out: fadeOut, | ||
}) | ||
), | ||
slide: new Map( | ||
Object.entries({ | ||
in: slideInHor, | ||
out: slideOutHor, | ||
}) | ||
), | ||
none: new Map( | ||
Object.entries({ | ||
in: noopAnimation, | ||
out: noopAnimation, | ||
}) | ||
), | ||
grow: animationPair({ | ||
in: fadeIn, | ||
out: fadeOut, | ||
}), | ||
fade: animationPair({ | ||
in: fadeIn, | ||
out: fadeOut, | ||
}), | ||
slide: animationPair({ | ||
in: fadeIn, | ||
out: fadeOut, | ||
}), | ||
none: animationPair({ | ||
in: noopAnimation, | ||
out: noopAnimation, | ||
}), | ||
}) | ||
); |
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
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
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
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