@@ -15,6 +15,9 @@ const exitAnimation = (factor: number) => `
1515100% {transform: translate3d(0,${ factor * - 150 } %,-1px) scale(.6); opacity:0;}
1616` ;
1717
18+ const fadeInAnimation = `0%{opacity:0;} 100%{opacity:1;}` ;
19+ const fadeOutAnimation = `0%{opacity:1;} 100%{opacity:0;}` ;
20+
1821const ToastBarBase = styled ( 'div' , React . forwardRef ) `
1922 display: flex;
2023 align-items: center;
@@ -53,28 +56,25 @@ const getAnimationStyle = (
5356) : React . CSSProperties => {
5457 const top = position . includes ( 'top' ) ;
5558 const factor = top ? 1 : - 1 ;
56- return visible
57- ? {
58- animation : `${ keyframes `${ enterAnimation (
59- factor
60- ) } `} 0.35s cubic-bezier(.21,1.02,.73,1) forwards`,
61- }
62- : {
63- animation : `${ keyframes `${ exitAnimation (
64- factor
65- ) } `} 0.4s forwards cubic-bezier(.06,.71,.55,1)`,
66- } ;
59+
60+ const [ enter , exit ] = prefersReducedMotion ( )
61+ ? [ fadeInAnimation , fadeOutAnimation ]
62+ : [ enterAnimation ( factor ) , exitAnimation ( factor ) ] ;
63+
64+ return {
65+ animation : visible
66+ ? `${ keyframes ( enter ) } 0.35s cubic-bezier(.21,1.02,.73,1) forwards`
67+ : `${ keyframes ( exit ) } 0.4s forwards cubic-bezier(.06,.71,.55,1)` ,
68+ } ;
6769} ;
6870
6971export const ToastBar : React . FC < ToastBarProps > = React . memo (
7072 ( { toast, position, style, children } ) => {
7173 const animationStyle : React . CSSProperties = toast ?. height
72- ? prefersReducedMotion ( )
73- ? { }
74- : getAnimationStyle (
75- toast . position || position || 'top-center' ,
76- toast . visible
77- )
74+ ? getAnimationStyle (
75+ toast . position || position || 'top-center' ,
76+ toast . visible
77+ )
7878 : { opacity : 0 } ;
7979
8080 const icon = < ToastIcon toast = { toast } /> ;
0 commit comments