-
Notifications
You must be signed in to change notification settings - Fork 0
/
DxModalPopupService.cs
31 lines (26 loc) · 1.04 KB
/
DxModalPopupService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using DynamicPopup.Models;
using Microsoft.AspNetCore.Components;
namespace DynamicPopup.Services {
public class DxModalPopupService : IDxModalPopupService {
public event Func<DxPopupModel, Task>? ShownAsync;
public event Func<DxPopupModel, Task>? ClosedAsync;
public List<DxPopupModel> Modals { get; private set; } = new List<DxPopupModel>();
public void Result(DxPopupModel popup) {
popup.Result();
Modals.Remove(popup);
}
public async Task CloseModal(DxPopupModel popup) {
if (ClosedAsync != null) {
await ClosedAsync(popup);
}
}
public async Task ShowModal<TComponent>(Dictionary<string, object>? attributes = null) where TComponent : ComponentBase {
if (ShownAsync != null) {
DxPopupModel model = new DxPopupModel(typeof(TComponent), attributes);
Modals.Add(model);
await ShownAsync(model);
await model.Task;
}
}
}
}