60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
import {Injectable} from '@angular/core';
|
|
import {MatSnackBar} from '@angular/material/snack-bar';
|
|
import {NotificationComponent} from "@component/common/notification/notification.component";
|
|
|
|
export enum NotifyColor {
|
|
Basic,
|
|
Warn,
|
|
Danger,
|
|
Success
|
|
}
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
|
|
export class OpenNotifyService {
|
|
constructor(private _snackBar: MatSnackBar) {
|
|
}
|
|
|
|
colorClass: string = '';
|
|
|
|
set setColorClass(color: NotifyColor) {
|
|
switch (color) {
|
|
case NotifyColor.Warn: {
|
|
this.colorClass = 'yellow-snackbar';
|
|
}
|
|
break;
|
|
case NotifyColor.Danger: {
|
|
this.colorClass = 'red-snackbar';
|
|
}
|
|
break;
|
|
case NotifyColor.Success: {
|
|
this.colorClass = 'green-snackbar';
|
|
}
|
|
break;
|
|
default: {
|
|
this.colorClass = 'snackbar';
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
open(message: string, color: NotifyColor = NotifyColor.Basic, duration: number = 5000) {
|
|
this.setColorClass = color;
|
|
this._snackBar.openFromComponent(NotificationComponent, {
|
|
data: {
|
|
message: message,
|
|
duration: duration,
|
|
className: this.colorClass,
|
|
color: color === NotifyColor.Danger ? "accent" : "primary"
|
|
},
|
|
duration: duration,
|
|
verticalPosition: 'top',
|
|
horizontalPosition: 'center',
|
|
panelClass: [this.colorClass]
|
|
})
|
|
;
|
|
}
|
|
}
|