Transitions
These transition components are are built on top of the popular animation library called Framer Motion, which is a powerful and flexible animation library for React that allows you to create smooth and interactive animations with ease. It provides a wide range of features and options for creating animations, including transitions, keyframes, and gesture-based animations.
Each transition component corresponds to a specific animation effect and provides a set of props that can be used to control and customize the animation behavior. These props are derived from the props available in Framer Motion, allowing you to take advantage of the rich animation capabilities provided.
Fade
: creates a smooth fading effect when transitioning a component in or out of view by gradually changes the opacity of the component. The in prop is used to control the visibility of the component, and the unmountOnExit prop can be used to unmount the component when it is not visible.ScaleFade
: combines scaling and fading effects during the transition. It allows you to control the initial scale of the component using the initialScale prop and smoothly fades in or out based on the in prop.Slide
: enables you to create sliding animations for components by specifying the direction of the slide animation using the direction prop, which can be set to 'bottom', 'top', 'left', or 'right'. The component smoothly slides in or out based on the in prop.SlideFade
: combines sliding and fading effects. It smoothly slides the component in or out based on the in prop and applies a fade effect simultaneously. You can customize the slide animation's offset in the y-axis direction using the offsetY prop.Collapse
: used to create expandable and collapsible regions of content with a smooth animation. It allows you to toggle the visibility of the content using the in prop, providing a seamless expand and collapse effect. The animateOpacity prop enables animating the opacity during the transition.These components can be imported as follows:
Examples
Fade
transition
: A prop that allows you to customize the animation transition. It accepts an object with properties like duration, delay, ease, and times. These properties control the duration, delay, easing function, and keyframes for the animation.in
: A boolean value that controls the visibility of the component. It triggers the enter or exit states of the animation.unmountOnExit
: If set to true, the component will unmount when in={false}
and the animation is completed.The following are two examples using Fade. The first is the default behavior. The second shows a custom fade using the transition prop.
<Fade in={isOpen}>
duration: 0.95
Code
ScaleFade
transition
: Similar to the Fade transition, the ScaleFade transition accepts the transition prop to control the animation transition.in
:A boolean value that controls the visibility of the component. It triggers the enter or exit states of the animation.initialScale
: The initial scale of the element. It is a number between 0 and 1. The default value is 0.95. This is the scaled size from which the element will transition from when it enters.reverse
: If set to true, the element will transition back to the exit state when it leaves. The default value is true.unmountOnExit
: If set to true, the component will unmount when in={false}
and the animation is completed.Below is an example of the default settings on ScaleFade as well as an example where you can choose the initialScale size to see the differences between values.
Slide
transition
: The Slide transition also accepts the transition prop to customize the animation transition.direction
: The direction from which the component slides in. It can be set to 'right', 'left', 'top', or 'bottom'. The default value is 'right'.in
: A boolean value that controls the visibility of the component. It triggers the enter or exit states of the animation.unmountOnExit
: If set to true, the component will unmount when in={false}
and the animation is completed.In the example below, you can try out the different directions to see how the component behaves under each circumstance.
SlideFade
SlideFade
: The SlideFade transition component allows you to customize the animation transition using the transition prop.in
: A boolean value that controls the visibility of the component. It triggers the enter or exit states of the animation.offsetX
: The offset on the horizontal or x-axis. It can be a string or number. The default value is 0.offsetY
: The offset on the vertical or y-axis. It can be a string or number. The default value is 8.reverse
: If set to true, the element will be transitioned back to the offset when it leaves. Otherwise, it will only fade out. The default value is true.unmountOnExit
: If set to true, the component will unmount when in= and the animation is completed.In the following examples, you can see the default behavior of the SlideFade component. Then you can experiment with the different values for the offsetX and offsetY properties from -200px to 200px for both X and Y. You can also experiment with the duration settings to see how the animation varies.
offsetX=
offsetY=
Duration=
Collapse
animateOpacity
: If set to true, the opacity of the content will be animated during the transition. The default value is true.startingHeight
: The Collapse transition component accepts the startingHeight prop, which sets the initial height of the collapsed content. This prop is useful when you want the collapsed content to have a specific height instead of collapsing to a height of zero.endingHeight
: The height you want the content to be in its expanded state. It can be a string or number. The default value is "auto".in
: A boolean value that controls the visibility of the component. It triggers the enter or exit states of the animation. unmountOnExit
: If set to true, the component will unmount when in= and the animation is completed.In the following example, you can experiment with the different values for startingHeight, endingHeight, and duration with the Collapse component.
startingHeight=
endingHeight=
Duration:
Did you know?
Creative Idea No. 1
Code
Creative Idea No. 2
Code
Creative Idea No. 3
Code
copyright © 2023 IHeartComponents | evanmarie.com
created with love by the I♥️Components team using
Special thanks to Stefan Bohacek / Generative Placeholders.