feat: add a service to launch notifications
This commit is contained in:
parent
cbed14ee1e
commit
347a4eeff1
54
src/services/open-notify.service.ts
Normal file
54
src/services/open-notify.service.ts
Normal 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]
|
||||
})
|
||||
;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user