@@ -28,6 +28,15 @@ const toLeftAnimation = keyframes`
28
28
}
29
29
` ;
30
30
31
+ const toRightAnimation = keyframes `
32
+ from {
33
+ transform: translate(0, 0);
34
+ }
35
+ to {
36
+ transform: translate(500px, 0);
37
+ }
38
+ ` ;
39
+
31
40
const Wrapper = styled . div `
32
41
position: fixed;
33
42
left: 16px;
@@ -51,6 +60,11 @@ const ToastContainer = styled.div`
51
60
transition: transform 0.3s ease-out;
52
61
transform: translate(0, -${ ( { bottomOffset } ) => bottomOffset } px);
53
62
63
+ ${ is ( 'isRight' ) `
64
+ left: unset;
65
+ right: 0;
66
+ ` } ;
67
+
54
68
${ is ( 'isInvisible' ) `
55
69
visibility: hidden;
56
70
` } ;
@@ -61,9 +75,7 @@ const ToastWrapper = styled.div`
61
75
animation: ${ fromBottomAnimation } 0.4s ease-out;
62
76
` } ;
63
77
64
- ${ is ( 'isHiding' ) `
65
- animation: ${ toLeftAnimation } 0.3s ease-in forwards;
66
- ` } ;
78
+ ${ ( { animation } ) => ( animation ? `animation: ${ animation } 0.3s ease-in forwards` : '' ) } ;
67
79
` ;
68
80
69
81
let instance ;
@@ -112,11 +124,13 @@ export default class ToastsManager extends PureComponent {
112
124
113
125
static propTypes = {
114
126
className : PropTypes . string ,
127
+ anchor : PropTypes . oneOf ( [ 'left' , 'right' ] ) ,
115
128
renderToast : PropTypes . func ,
116
129
} ;
117
130
118
131
static defaultProps = {
119
132
className : undefined ,
133
+ anchor : 'left' ,
120
134
renderToast : undefined ,
121
135
} ;
122
136
@@ -380,9 +394,12 @@ export default class ToastsManager extends PureComponent {
380
394
}
381
395
382
396
renderToasts ( ) {
383
- const { renderToast } = this . props ;
397
+ const { renderToast, anchor } = this . props ;
384
398
const { currentToasts, bottomOffsets } = this . state ;
385
399
400
+ const isRight = anchor === 'right' ;
401
+ const hideAnimation = isRight ? toRightAnimation : toLeftAnimation ;
402
+
386
403
return currentToasts . map ( ( { id, type, text, renderer, isHiding } ) => {
387
404
const bottomOffset = bottomOffsets [ id ] ;
388
405
const isOffsetCalculated = bottomOffset !== undefined ;
@@ -394,9 +411,13 @@ export default class ToastsManager extends PureComponent {
394
411
key = { id }
395
412
ref = { this . toastsRefs [ id ] }
396
413
isInvisible = { ! isOffsetCalculated }
414
+ isRight = { isRight }
397
415
bottomOffset = { bottomOffset }
398
416
>
399
- < ToastWrapper isAppearing = { isOffsetCalculated } isHiding = { isHiding } >
417
+ < ToastWrapper
418
+ isAppearing = { isOffsetCalculated }
419
+ animation = { isHiding ? hideAnimation : null }
420
+ >
400
421
{ render ? (
401
422
render ( { type, text, onClose : ( ) => this . onCloseClick ( id ) } )
402
423
) : (
0 commit comments