Skip to content

Commit 699e701

Browse files
committed
refactor(toast): remove: onAnimationEvent() @fadeinout.start @fadeInOut.done, cleanup
1 parent bf8e1ef commit 699e701

File tree

1 file changed

+26
-45
lines changed

1 file changed

+26
-45
lines changed

projects/coreui-angular/src/lib/toast/toast/toast.component.ts

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,59 @@ import {
99
OnDestroy,
1010
OnInit,
1111
Output,
12-
Renderer2,
12+
Renderer2
1313
} from '@angular/core';
1414

15-
import { animate, AnimationEvent, state, style, transition, trigger } from '@angular/animations';
15+
import { animate, state, style, transition, trigger } from '@angular/animations';
1616
import { BooleanInput, coerceBooleanProperty } from '@angular/cdk/coercion';
1717

18+
import { Colors } from '../../coreui.types';
1819
import { ToasterService } from '../toaster/toaster.service';
1920
import { TToasterPlacement } from '../toaster/toaster.component';
20-
import { Colors } from '../../coreui.types';
2121

2222
type AnimateType = ('hide' | 'show');
2323

2424
@Component({
2525
selector: 'c-toast',
26-
template: `<ng-content></ng-content>`,
26+
template: '<ng-content></ng-content>',
2727
styleUrls: ['./toast.component.scss'],
2828
exportAs: 'cToast',
2929
standalone: true,
3030
animations: [
3131
trigger('fadeInOut', [
32-
state('show', style({opacity: 1, height: '*', padding: '*', border: '*', margin: '*'})),
33-
state('hide', style({opacity: 0, height: 0, padding: 0, border: 0, margin: 0})),
34-
state('void', style({opacity: 0, height: 0, padding: 0, border: 0, margin: 0})),
32+
state('show', style({ opacity: 1, height: '*', padding: '*', border: '*', margin: '*' })),
33+
state('hide', style({ opacity: 0, height: 0, padding: 0, border: 0, margin: 0 })),
34+
state('void', style({ opacity: 0, height: 0, padding: 0, border: 0, margin: 0 })),
3535
transition('show => hide', [
36-
animate('{{ time }} {{ easing }}'),
36+
animate('{{ time }} {{ easing }}')
3737
], {
38-
params: {time: '300ms', easing: 'ease-out'}
38+
params: { time: '300ms', easing: 'ease-out' }
3939
}),
4040
transition('hide => show', [animate('{{ time }} {{ easing }}')], {
41-
params: {time: '300ms', easing: 'ease-in'},
41+
params: { time: '300ms', easing: 'ease-in' }
4242
}),
4343
transition('show => void', [animate('{{ time }} {{ easing }}')], {
44-
params: {time: '300ms', easing: 'ease-out'},
44+
params: { time: '300ms', easing: 'ease-out' }
4545
}),
4646
transition('void => show', [animate('{{ time }} {{ easing }}')], {
47-
params: {time: '300ms', easing: 'ease-in'},
48-
}),
49-
]),
50-
],
47+
params: { time: '300ms', easing: 'ease-in' }
48+
})
49+
])
50+
]
5151
})
5252
export class ToastComponent implements OnInit, OnDestroy {
5353

5454
static ngAcceptInputType_visible: BooleanInput;
5555

5656
public dynamic!: boolean;
5757
public placement!: TToasterPlacement;
58-
public hide!: boolean;
58+
59+
constructor(
60+
public hostElement: ElementRef,
61+
public renderer: Renderer2,
62+
public toasterService: ToasterService,
63+
public changeDetectorRef: ChangeDetectorRef
64+
) {}
5965

6066
/**
6167
* Auto hide the toast.
@@ -95,9 +101,11 @@ export class ToastComponent implements OnInit, OnDestroy {
95101
this.changeDetectorRef.markForCheck();
96102
}
97103
}
104+
98105
get visible() {
99106
return this._visible;
100107
}
108+
101109
private _visible = false;
102110

103111
/**
@@ -121,13 +129,6 @@ export class ToastComponent implements OnInit, OnDestroy {
121129
private clockId: any;
122130
private clockTimerId: any;
123131

124-
constructor(
125-
public hostElement: ElementRef,
126-
public renderer: Renderer2,
127-
public toasterService: ToasterService,
128-
public changeDetectorRef: ChangeDetectorRef
129-
) {}
130-
131132
private _clock!: number;
132133

133134
get clock(): number {
@@ -150,16 +151,6 @@ export class ToastComponent implements OnInit, OnDestroy {
150151
return this.visible ? 'show' : 'hide';
151152
}
152153

153-
@HostListener('@fadeInOut.start', ['$event'])
154-
onAnimationStart($event: AnimationEvent): void {
155-
this.onAnimationEvent($event);
156-
}
157-
158-
@HostListener('@fadeInOut.done', ['$event'])
159-
onAnimationDone($event: AnimationEvent): void {
160-
this.onAnimationEvent($event);
161-
}
162-
163154
@HostListener('mouseover') onMouseOver(): void {
164155
this.clearTimer();
165156
}
@@ -183,7 +174,7 @@ export class ToastComponent implements OnInit, OnDestroy {
183174
this.toasterService.setState({
184175
toast: this,
185176
show: this.visible,
186-
placement: this.placement,
177+
placement: this.placement
187178
});
188179
this.clearTimer();
189180
this.setTimer();
@@ -213,7 +204,7 @@ export class ToastComponent implements OnInit, OnDestroy {
213204
this.toasterService.setState({
214205
toast: this,
215206
show: false,
216-
placement: this.placement,
207+
placement: this.placement
217208
});
218209
}
219210

@@ -234,14 +225,4 @@ export class ToastComponent implements OnInit, OnDestroy {
234225
clearInterval(this.clockId);
235226
this.clockId = null;
236227
}
237-
238-
onAnimationEvent(event: AnimationEvent): void {
239-
this.hide = event.phaseName === 'start' && event.toState === 'show';
240-
if (event.phaseName === 'done') {
241-
this.hide = (event.toState === 'hide' || event.toState === 'void');
242-
if (event.toState === 'show') {
243-
this.hide = false;
244-
}
245-
}
246-
}
247228
}

0 commit comments

Comments
 (0)