@@ -2,14 +2,17 @@ import {Directive, HostBinding, ElementRef, AfterViewInit, Renderer} from "@angu
22
33export interface ISuiAnimation {
44 name :string ;
5- classes ?:string [ ] ;
65 duration ?:number ;
7- static ?:boolean ;
86 display ?:string ;
97 direction ?:string ;
108 callback ?:( ) => any ;
119}
1210
11+ interface ISuiConfiguredAnimation extends ISuiAnimation {
12+ classes ?:string [ ] ;
13+ static ?:boolean ;
14+ }
15+
1316@Directive ( {
1417 selector : '[suiTransition]' ,
1518 exportAs : 'transition'
@@ -37,7 +40,7 @@ export class SuiTransition {
3740 this . renderer . setElementClass ( this . el . nativeElement , "animating" , value ) ;
3841 }
3942
40- private animationTimeout :number ;
43+ private animationTimeout :any ;
4144
4245 private _isVisible = null ;
4346
@@ -62,33 +65,40 @@ export class SuiTransition {
6265 this . renderer . setElementClass ( this . el . nativeElement , "hidden" , value ) ;
6366 }
6467
65- private queue :ISuiAnimation [ ] = [ ] ;
68+ private queue :ISuiConfiguredAnimation [ ] = [ ] ;
6669
6770 private queueFirst ( ) {
6871 return this . queue . slice ( 0 , 1 ) . pop ( ) ;
6972 }
7073
74+ private queueLast ( ) {
75+ return this . queue . slice ( - 1 ) . pop ( ) ;
76+ }
77+
7178 public animate ( animation :ISuiAnimation ) {
7279 animation = Object . assign ( { } , animation ) ;
73- animation . classes = animation . name . split ( " " ) ;
74- if ( ! animation . duration ) {
75- animation . duration = 250 ;
80+ let anim = animation as ISuiConfiguredAnimation ;
81+
82+ anim . classes = animation . name . split ( " " ) ;
83+ if ( ! anim . duration ) {
84+ anim . duration = 250 ;
7685 }
77- if ( ! animation . display ) {
78- animation . display = 'block' ;
86+ if ( ! anim . display ) {
87+ anim . display = 'block' ;
7988 }
80- if ( ! animation . static ) {
81- animation . static = [ "jiggle" , "flash" , "shake" , "pulse" , "tada" , "bounce" ] . indexOf ( animation . name ) != - 1 ;
89+ if ( ! anim . static ) {
90+ anim . static = [ "jiggle" , "flash" , "shake" , "pulse" , "tada" , "bounce" ] . indexOf ( anim . name ) != - 1 ;
8291 }
83- if ( ! animation . direction ) {
84- animation . direction = this . isVisible ? "out" : "in" ;
85- let queueLast = this . queueFirst ( ) ;
92+ if ( ! anim . direction ) {
93+ anim . direction = this . isVisible ? "out" : "in" ;
94+ let queueLast = this . queueLast ( ) ;
8695 if ( queueLast ) {
87- animation . direction = queueLast . direction == "in" ? "out" : "in"
96+ anim . direction = queueLast . direction == "in" ? "out" : "in"
8897 }
8998 }
9099
91100 this . queue . push ( animation ) ;
101+
92102 this . performAnimation ( ) ;
93103 }
94104
@@ -115,7 +125,7 @@ export class SuiTransition {
115125 this . animationTimeout = setTimeout ( ( ) => this . finishAnimation ( animation ) , animation . duration ) ;
116126 }
117127
118- private finishAnimation ( animation :ISuiAnimation ) {
128+ private finishAnimation ( animation :ISuiConfiguredAnimation ) {
119129 this . isAnimating = false ;
120130 animation . classes . forEach ( c => this . renderer . setElementClass ( this . el . nativeElement , c , false ) ) ;
121131 this . renderer . setElementClass ( this . el . nativeElement , animation . direction , false ) ;
0 commit comments