- @if (!ModalOptions.NoHeader)
- {
-
- }
-
- @Content
-
-
}
\ No newline at end of file
diff --git a/src/Connected.Components/Components/ModalDialog.razor.cs b/src/Connected.Components/Components/ModalDialog.razor.cs
index 70548f9..9c41215 100644
--- a/src/Connected.Components/Components/ModalDialog.razor.cs
+++ b/src/Connected.Components/Components/ModalDialog.razor.cs
@@ -1,5 +1,5 @@
using Connected.Models.Modal;
-using Connected.Services.Modal;
+using Connected.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
@@ -19,7 +19,6 @@ public partial class ModalDialog : IDisposable
protected ModalOptions? ModalOptions { get; set; }
-
protected override void OnInitialized()
{
ModalService.OnShow += ShowModal;
@@ -51,15 +50,23 @@ public partial class ModalDialog : IDisposable
{
if (button.CloseDialogOnClick)
{
- IsVisible = false;
- Title = "";
- Content = null;
+ CloseModal();
}
button.OnClickEvent.Delegate.DynamicInvoke(button.OnClickEvent.args);
}
StateHasChanged();
}
+ public void CloseModal()
+ {
+ IsVisible = false;
+ Title = "";
+ Content = null;
+ StateHasChanged();
+ }
+
+
+
public void Dispose()
{
if (ModalService is not null)
@@ -71,12 +78,12 @@ public partial class ModalDialog : IDisposable
public void CheckEscape(KeyboardEventArgs args)
{
- if (ModalOptions.CloseOnEscKey)
+ if (!ModalOptions.DisableEscKey)
{
var key = args.Key.ToLower();
if (key.Equals("escape"))
{
- CloseModal(null);
+ CloseModal();
}
}
}
@@ -87,7 +94,7 @@ public partial class ModalDialog : IDisposable
{
if (OverlayClickToClose)
{
- CloseModal(null);
+ CloseModal();
}
}
OverlayClickToClose = true;
diff --git a/src/Connected.Components/Models/Modal/ModalButton.cs b/src/Connected.Components/Models/Modal/ModalButton.cs
index e81f476..476513e 100644
--- a/src/Connected.Components/Models/Modal/ModalButton.cs
+++ b/src/Connected.Components/Models/Modal/ModalButton.cs
@@ -1,10 +1,9 @@
using Connected.Enums;
-using Connected.Services.Modal;
+using Connected.Services;
namespace Connected.Models.Modal;
public class ModalButton
{
- ModalDialogService _dialogService;
public Event OnClickEvent { get; set; }
public ModalButtonType ModalButtonType { get; set; } = ModalButtonType.RegularButton;
public string ButtonText { get; set; }
diff --git a/src/Connected.Components/Models/Modal/ModalOptions.cs b/src/Connected.Components/Models/Modal/ModalOptions.cs
index fa5bea0..4f2443f 100644
--- a/src/Connected.Components/Models/Modal/ModalOptions.cs
+++ b/src/Connected.Components/Models/Modal/ModalOptions.cs
@@ -1,7 +1,7 @@
namespace Connected.Models.Modal;
public class ModalOptions
{
- public bool CloseOnEscKey { get; set; } = true;
+ public bool DisableEscKey { get; set; } = false;
public bool DisableBackdropClick { get; set; } = false;
public bool NoHeader { get; set; } = false;
diff --git a/src/Connected.Components/Services/ModalDialogService.cs b/src/Connected.Components/Services/ModalDialogService.cs
new file mode 100644
index 0000000..5b988ef
--- /dev/null
+++ b/src/Connected.Components/Services/ModalDialogService.cs
@@ -0,0 +1,28 @@
+using Connected.Components;
+using Connected.Models.Modal;
+using Microsoft.AspNetCore.Components;
+
+namespace Connected.Services;
+public class ModalDialogService
+{
+ public event Action
, ModalOptions> OnShow;
+ public event Action OnClose;
+
+ public void ShowDialog(string title, RenderFragment content, List buttons, ModalOptions options)
+ {
+ OnShow?.Invoke(title, content, buttons, options);
+ }
+
+ public void ShowDialog(string title, MarkupString contentMarkup, List buttons, ModalOptions options)
+ {
+ var content = new RenderFragment(x => x.AddContent(1, contentMarkup));
+ OnShow?.Invoke(title, content, buttons, options);
+ }
+
+ public void Close()
+ {
+ OnClose?.Invoke();
+ }
+
+
+}
diff --git a/src/Connected.Components/Services/ServiceCollectionExtensions.cs b/src/Connected.Components/Services/ServiceCollectionExtensions.cs
index 00dfc2a..2f58959 100644
--- a/src/Connected.Components/Services/ServiceCollectionExtensions.cs
+++ b/src/Connected.Components/Services/ServiceCollectionExtensions.cs
@@ -1,5 +1,4 @@
-using Connected.Services.Modal;
-using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection;
namespace Connected.Services;