The CSSTransition component or useCSSTransition hook should be used when an
element should have a CSS transition when it mounts, unmounts, or dynamically
based on some flag. The transitions are built into existing react-md
components like the Dialog, Menu, and
Overlay.
Some existing transitions can be found at:
Check out the useTransition hook for additional options and info around the transition stages.
To create a CSS Transition:
transitionIn flagtimeout for the transition which can be a number or an object
enter and exit duration in millisecondsclassNames to apply at the different transition stages which can
be a string or an object
enter,
enterActive, enterDone, exit, exitActive, and exitDone stages${classNames}--${stage}The transitionable component must accept a ref and a className.
This is the same example as above, but using the useCSSTransition hook instead
of the CSSTransition component.
The CSS Transition really shines for temporary elements that should have enter
and exit transitions since it also returns a rendered flag that will be
false once the exit transition has completed. Enable the temporary prop on
the CSSTransition component or useCSSTransition hook to enable this feature.
Instead of unmounting the component while transitionIn is false, another
option is to hide it in the DOM by using display: none. Enable the
exitedHidden option instead of temporary.
The main benefit to this behavior is that the state of the temporary element will not reset since it is never unmounted.
The enter transition will not occur by default if a component mounts with
transitionIn set to true since this is considered an "appear" transition. If
this behavior is desired, enable the appear option which defaults to reusing
all the same styles and timeouts as the enter stages.
If the component only requires a transition on first mount, it is recommended to
use a CSS-only transition instead to reduce the javascript bundle size. Here is
the same example as above but using css instead of the useCSSTransition hook.