mirror of
https://github.com/JohanLeroy/dialogue-lib.git
synced 2026-01-28 02:07:29 +00:00
first commit
This commit is contained in:
39
src/services/alert.service.ts
Normal file
39
src/services/alert.service.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { Alert } from '../models/alert';
|
||||
|
||||
type AlertParams = Partial<Omit<Alert, 'resolve'>>;
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AlertService {
|
||||
|
||||
private alertSubject = new Subject<Alert>();
|
||||
|
||||
alerts() {
|
||||
return this.alertSubject.asObservable();
|
||||
}
|
||||
|
||||
confirm({
|
||||
type = 'question',
|
||||
title = 'Êtes-vous sûr ?',
|
||||
text = 'Cette action est irréversible.',
|
||||
confirmText = 'Confirmer',
|
||||
cancelText = 'Annuler',
|
||||
timeout,
|
||||
backdropOpacity = 0.1,
|
||||
}: AlertParams): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
this.alertSubject.next({
|
||||
type,
|
||||
title,
|
||||
text,
|
||||
confirmText,
|
||||
cancelText,
|
||||
timeout,
|
||||
backdropOpacity,
|
||||
resolve,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user