feat: add a service to launch notifications

This commit is contained in:
Polianin Nikita 2024-02-13 02:53:39 +03:00
parent cbed14ee1e
commit 347a4eeff1

View File

@ -0,0 +1,54 @@
import {Injectable} from '@angular/core';
import {MatSnackBar} from '@angular/material/snack-bar';
import {NotificationComponent} from "@component/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},
duration: duration,
verticalPosition: 'top',
horizontalPosition: 'center',
panelClass: [this.colorClass]
})
;
}
}