ModalDialog - added ModalOptions

pull/10/head
markosteger 2 years ago
parent 4f635b573c
commit 422da4d079

@ -3,9 +3,12 @@
<div class="modal fade show" tabindex="-1" @onclick="@CloseIfEnabled" @onkeydown="@(e => CheckEscape(e))">
<div class="modal-dialog modal-dialog-scrollable modal-dialog-centered" >
<div class="modal-content" @onclick="PreventClose">
<div class="modal-header" >
<h3 class="modal-title">@Title</h3>
@if (!ModalOptions.NoHeader)
{
<div class="modal-header" >
<h3 class="modal-title">@Title</h3>
</div>
}
<div class="modal-body">
@Content
</div>

@ -13,7 +13,11 @@ public partial class ModalDialog: IDisposable
protected RenderFragment? Content { get; set; }
protected bool OverlayClickToClose { get; set; } = true;
protected Event OnConfirm { get; set; }
protected Event? OnOk { get; set; }
protected Event? OnClose { get; set; }
protected ModalOptions? ModalOptions { get; set; }
protected override void OnInitialized()
{
@ -22,7 +26,7 @@ public partial class ModalDialog: IDisposable
}
public void ShowModal(string title, RenderFragment content, Event onConfirm, string CancelButtonText = "Cancel", string OKButtonText = "OK")
public void ShowModal(string title, RenderFragment content, Event OnOk = null, Event OnClose = null, ModalOptions options = null, string CancelButtonText = "Cancel", string OKButtonText = "OK")
{
Title = title;
Content = content;
@ -31,7 +35,10 @@ public partial class ModalDialog: IDisposable
this.OKButtonText = OKButtonText;
this.CancelButtonText = CancelButtonText;
OnConfirm = onConfirm;
ModalOptions = options;
this.OnOk = OnOk;
this.OnClose = OnClose;
StateHasChanged();
}
@ -42,7 +49,16 @@ public partial class ModalDialog: IDisposable
Title = "";
Content = null;
if (OkClicked)
OnConfirm.Delegate.DynamicInvoke(OnConfirm.args);
{
if (OnOk is not null)
OnOk.Delegate.DynamicInvoke(OnOk.args);
}
else
{
if (OnClose is not null)
OnClose.Delegate.DynamicInvoke(OnClose.args);
}
StateHasChanged();
}

@ -3,18 +3,18 @@
namespace Connected.Services.Modal;
public class ModalDialogService
{
public event Action<string, RenderFragment, Event, string, string> OnShow;
public event Action<string, RenderFragment, Event, Event, ModalOptions, string, string> OnShow;
public event Action<bool> OnClose;
public void ShowDialog(string title, RenderFragment content, Event OnConfirm, string CancelButtonText="Cancel", string OKButtonText="OK")
public void ShowDialog(string title, RenderFragment content, Event OnConfirm, Event OnCancel, ModalOptions options, string CancelButtonText="Cancel", string OKButtonText="OK")
{
OnShow?.Invoke(title, content, OnConfirm, OKButtonText, CancelButtonText);
OnShow?.Invoke(title, content, OnConfirm, OnCancel, options, OKButtonText, CancelButtonText);
}
public void ShowDialog(string title, MarkupString contentMarkup, Event OnConfirm, string CancelButtonText = "Cancel", string OKButtonText = "OK")
public void ShowDialog(string title, MarkupString contentMarkup, Event OnConfirm, Event OnCancel, ModalOptions options, string CancelButtonText = "Cancel", string OKButtonText = "OK")
{
var content = new RenderFragment(x => x.AddContent(1, contentMarkup));
OnShow?.Invoke(title, content, OnConfirm, OKButtonText, CancelButtonText);
OnShow?.Invoke(title, content, OnConfirm, OnCancel, options, OKButtonText, CancelButtonText);
}
public void Close(bool OkClicked)

@ -0,0 +1,9 @@
namespace Connected.Services.Modal;
public class ModalOptions
{
public bool CloseOnEscKey { get; set; } = true;
public bool DisableBackdropCLick { get; set; } = false;
public bool NoHeader { get; set; } = false;
}
Loading…
Cancel
Save