|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
using Connected.Services.Modal;
|
|
|
|
|
using Connected.Models.Modal;
|
|
|
|
|
using Connected.Services.Modal;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
|
|
|
|
|
namespace Connected.Components;
|
|
|
|
|
public partial class ModalDialog: IDisposable
|
|
|
|
|
public partial class ModalDialog : IDisposable
|
|
|
|
|
{
|
|
|
|
|
[Inject] ModalDialogService? ModalService { get; set; }
|
|
|
|
|
|
|
|
|
@ -11,54 +12,51 @@ public partial class ModalDialog: IDisposable
|
|
|
|
|
protected bool IsVisible { get; set; }
|
|
|
|
|
protected string? Title { get; set; }
|
|
|
|
|
protected RenderFragment? Content { get; set; }
|
|
|
|
|
|
|
|
|
|
protected bool OverlayClickToClose { get; set; } = true;
|
|
|
|
|
protected Event? OnOk { get; set; }
|
|
|
|
|
|
|
|
|
|
protected Event? OnClose { get; set; }
|
|
|
|
|
protected List<ModalButton> buttons { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
protected ModalOptions? ModalOptions { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
ModalService.OnShow += ShowModal;
|
|
|
|
|
ModalService.OnClose += CloseModal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
if (IsVisible)
|
|
|
|
|
await root.FocusAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void ShowModal(string title, RenderFragment content, Event OnOk = null, Event OnClose = null, ModalOptions options = null, string CancelButtonText = "Cancel", string OKButtonText = "OK")
|
|
|
|
|
public void ShowModal(string title, RenderFragment content, List<ModalButton> buttons, ModalOptions options)
|
|
|
|
|
{
|
|
|
|
|
Title = title;
|
|
|
|
|
Content = content;
|
|
|
|
|
IsVisible = true;
|
|
|
|
|
|
|
|
|
|
this.OKButtonText = OKButtonText;
|
|
|
|
|
this.CancelButtonText = CancelButtonText;
|
|
|
|
|
|
|
|
|
|
ModalOptions = options;
|
|
|
|
|
|
|
|
|
|
this.OnOk = OnOk;
|
|
|
|
|
this.OnClose = OnClose;
|
|
|
|
|
this.buttons = buttons;
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CloseModal(bool OkClicked = false)
|
|
|
|
|
public void CloseModal(ModalButton? button)
|
|
|
|
|
{
|
|
|
|
|
IsVisible = false;
|
|
|
|
|
Title = "";
|
|
|
|
|
Content = null;
|
|
|
|
|
if (OkClicked)
|
|
|
|
|
{
|
|
|
|
|
if (OnOk is not null)
|
|
|
|
|
OnOk.Delegate.DynamicInvoke(OnOk.args);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (button is not null)
|
|
|
|
|
{
|
|
|
|
|
if (OnClose is not null)
|
|
|
|
|
OnClose.Delegate.DynamicInvoke(OnClose.args);
|
|
|
|
|
if (button.CloseDialogOnClick)
|
|
|
|
|
{
|
|
|
|
|
IsVisible = false;
|
|
|
|
|
Title = "";
|
|
|
|
|
Content = null;
|
|
|
|
|
}
|
|
|
|
|
button.OnClickEvent.Delegate.DynamicInvoke(button.OnClickEvent.args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -71,24 +69,26 @@ public partial class ModalDialog: IDisposable
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string OKButtonText { get; set; } ="OK";
|
|
|
|
|
|
|
|
|
|
public string CancelButtonText { get; set; } = "Cancel";
|
|
|
|
|
|
|
|
|
|
public void CheckEscape(KeyboardEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var key = args.Key.ToLower();
|
|
|
|
|
if (key.Equals("escape"))
|
|
|
|
|
if (ModalOptions.CloseOnEscKey)
|
|
|
|
|
{
|
|
|
|
|
CloseModal();
|
|
|
|
|
var key = args.Key.ToLower();
|
|
|
|
|
if (key.Equals("escape"))
|
|
|
|
|
{
|
|
|
|
|
CloseModal(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CloseIfEnabled(MouseEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (OverlayClickToClose)
|
|
|
|
|
if (!ModalOptions.DisableBackdropClick)
|
|
|
|
|
{
|
|
|
|
|
CloseModal();
|
|
|
|
|
if (OverlayClickToClose)
|
|
|
|
|
{
|
|
|
|
|
CloseModal(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
OverlayClickToClose = true;
|
|
|
|
|
}
|
|
|
|
|