|
|
|
@ -12,29 +12,52 @@ namespace Connected.Components;
|
|
|
|
|
|
|
|
|
|
public partial class DialogInstance : UIComponent, IDisposable
|
|
|
|
|
{
|
|
|
|
|
#region Variables
|
|
|
|
|
private DialogOptions _options = new();
|
|
|
|
|
private string _elementId = "dialog_" + Guid.NewGuid().ToString().Substring(0, 8);
|
|
|
|
|
private IKeyInterceptor _keyInterceptor;
|
|
|
|
|
|
|
|
|
|
[Inject] private IKeyInterceptorFactory _keyInterceptorFactory { get; set; }
|
|
|
|
|
|
|
|
|
|
[CascadingParameter(Name = "RightToLeft")] public bool RightToLeft { get; set; }
|
|
|
|
|
[CascadingParameter] private DialogProvider Parent { get; set; }
|
|
|
|
|
[CascadingParameter] private DialogOptions GlobalDialogOptions { get; set; } = new DialogOptions();
|
|
|
|
|
private Dialog _dialog;
|
|
|
|
|
private bool _disposedValue;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
[Category(CategoryTypes.Dialog.Misc)] // Behavior and Appearance
|
|
|
|
|
public DialogOptions Options
|
|
|
|
|
#region Events
|
|
|
|
|
private void HandleBackgroundClick()
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
if (DisableBackdropClick)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_dialog?.OnBackdropClick == null)
|
|
|
|
|
{
|
|
|
|
|
if (_options == null)
|
|
|
|
|
_options = new DialogOptions();
|
|
|
|
|
return _options;
|
|
|
|
|
Cancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
set => _options = value;
|
|
|
|
|
|
|
|
|
|
_dialog?.OnBackdropClick.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Cancels all dialogs in dialog provider collection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void CancelAll()
|
|
|
|
|
{
|
|
|
|
|
Parent?.DismissAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Register(Dialog dialog)
|
|
|
|
|
{
|
|
|
|
|
if (dialog == null)
|
|
|
|
|
return;
|
|
|
|
|
_dialog = dialog;
|
|
|
|
|
//AdditionalClassList = dialog.AdditionalClassList;
|
|
|
|
|
TitleContent = dialog.TitleContent;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Content
|
|
|
|
|
[Parameter]
|
|
|
|
|
[Category(CategoryTypes.Dialog.Behavior)]
|
|
|
|
|
public string Title { get; set; }
|
|
|
|
@ -46,10 +69,129 @@ public partial class DialogInstance : UIComponent, IDisposable
|
|
|
|
|
[Parameter]
|
|
|
|
|
[Category(CategoryTypes.Dialog.Behavior)]
|
|
|
|
|
public RenderFragment Content { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
[Category(CategoryTypes.Dialog.Behavior)]
|
|
|
|
|
public Guid Id { get; set; }
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Styling
|
|
|
|
|
public void ForceRender()
|
|
|
|
|
{
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
private string SetPosition()
|
|
|
|
|
{
|
|
|
|
|
DialogPosition position;
|
|
|
|
|
|
|
|
|
|
if (Options.Position.HasValue)
|
|
|
|
|
{
|
|
|
|
|
position = Options.Position.Value;
|
|
|
|
|
}
|
|
|
|
|
else if (GlobalDialogOptions.Position.HasValue)
|
|
|
|
|
{
|
|
|
|
|
position = GlobalDialogOptions.Position.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
position = DialogPosition.Center;
|
|
|
|
|
}
|
|
|
|
|
return $"dialog-{position.ToDescription()}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool SetHideHeader()
|
|
|
|
|
{
|
|
|
|
|
if (Options.NoHeader.HasValue)
|
|
|
|
|
return Options.NoHeader.Value;
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.NoHeader.HasValue)
|
|
|
|
|
return GlobalDialogOptions.NoHeader.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetCloseButton()
|
|
|
|
|
{
|
|
|
|
|
if (Options.CloseButton.HasValue)
|
|
|
|
|
return Options.CloseButton.Value;
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.CloseButton.HasValue)
|
|
|
|
|
return GlobalDialogOptions.CloseButton.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetDisableBackdropClick()
|
|
|
|
|
{
|
|
|
|
|
if (Options.DisableBackdropClick.HasValue)
|
|
|
|
|
return Options.DisableBackdropClick.Value;
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.DisableBackdropClick.HasValue)
|
|
|
|
|
return GlobalDialogOptions.DisableBackdropClick.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetCloseOnEscapeKey()
|
|
|
|
|
{
|
|
|
|
|
if (Options.CloseOnEscapeKey.HasValue)
|
|
|
|
|
return Options.CloseOnEscapeKey.Value;
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.CloseOnEscapeKey.HasValue)
|
|
|
|
|
return GlobalDialogOptions.CloseOnEscapeKey.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
private string SetMaxWidth()
|
|
|
|
|
{
|
|
|
|
|
MaxWidth maxWidth;
|
|
|
|
|
|
|
|
|
|
if (Options.MaxWidth.HasValue)
|
|
|
|
|
{
|
|
|
|
|
maxWidth = Options.MaxWidth.Value;
|
|
|
|
|
}
|
|
|
|
|
else if (GlobalDialogOptions.MaxWidth.HasValue)
|
|
|
|
|
{
|
|
|
|
|
maxWidth = GlobalDialogOptions.MaxWidth.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
maxWidth = MaxWidth.Small;
|
|
|
|
|
}
|
|
|
|
|
return $"dialog-width-{maxWidth.ToDescription()}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetFullWidth()
|
|
|
|
|
{
|
|
|
|
|
if (Options.FullWidth.HasValue)
|
|
|
|
|
return Options.FullWidth.Value;
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.FullWidth.HasValue)
|
|
|
|
|
return GlobalDialogOptions.FullWidth.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetFulScreen()
|
|
|
|
|
{
|
|
|
|
|
if (Options.FullScreen.HasValue)
|
|
|
|
|
return Options.FullScreen.Value;
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.FullScreen.HasValue)
|
|
|
|
|
return GlobalDialogOptions.FullScreen.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected string Classname =>
|
|
|
|
|
new CssBuilder("dialog")
|
|
|
|
|
.AddClass(DialogMaxWidth, !FullScreen)
|
|
|
|
|
.AddClass("dialog-width-full", FullWidth && !FullScreen)
|
|
|
|
|
.AddClass("dialog-fullscreen", FullScreen)
|
|
|
|
|
.AddClass("dialog-rtl", RightToLeft)
|
|
|
|
|
.AddClass(_dialog?.AdditionalClassList)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Custom close icon.
|
|
|
|
@ -66,35 +208,22 @@ public partial class DialogInstance : UIComponent, IDisposable
|
|
|
|
|
private bool CloseButton { get; set; }
|
|
|
|
|
private bool FullScreen { get; set; }
|
|
|
|
|
private bool FullWidth { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
ConfigureInstance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
if (firstRender)
|
|
|
|
|
{
|
|
|
|
|
//Since CloseOnEscapeKey is the only thing to be handled, turn interceptor off
|
|
|
|
|
if (CloseOnEscapeKey)
|
|
|
|
|
[CascadingParameter(Name = "RightToLeft")] public bool RightToLeft { get; set; }
|
|
|
|
|
[Parameter]
|
|
|
|
|
[Category(CategoryTypes.Dialog.Misc)] // Behavior and Appearance
|
|
|
|
|
public DialogOptions Options
|
|
|
|
|
{
|
|
|
|
|
_keyInterceptor = _keyInterceptorFactory.Create();
|
|
|
|
|
|
|
|
|
|
await _keyInterceptor.Connect(_elementId, new KeyInterceptorOptions()
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
TargetClass = "dialog",
|
|
|
|
|
Keys = {
|
|
|
|
|
new KeyOptions { Key="Escape", SubscribeDown = true },
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
_keyInterceptor.KeyDown += HandleKeyDown;
|
|
|
|
|
}
|
|
|
|
|
if (_options == null)
|
|
|
|
|
_options = new DialogOptions();
|
|
|
|
|
return _options;
|
|
|
|
|
}
|
|
|
|
|
await base.OnAfterRenderAsync(firstRender);
|
|
|
|
|
set => _options = value;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Behavior
|
|
|
|
|
internal void HandleKeyDown(KeyboardEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
switch (args.Key)
|
|
|
|
@ -175,157 +304,34 @@ public partial class DialogInstance : UIComponent, IDisposable
|
|
|
|
|
//AdditionalClassList = Classname;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string SetPosition()
|
|
|
|
|
{
|
|
|
|
|
DialogPosition position;
|
|
|
|
|
|
|
|
|
|
if (Options.Position.HasValue)
|
|
|
|
|
{
|
|
|
|
|
position = Options.Position.Value;
|
|
|
|
|
}
|
|
|
|
|
else if (GlobalDialogOptions.Position.HasValue)
|
|
|
|
|
{
|
|
|
|
|
position = GlobalDialogOptions.Position.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
position = DialogPosition.Center;
|
|
|
|
|
}
|
|
|
|
|
return $"dialog-{position.ToDescription()}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string SetMaxWidth()
|
|
|
|
|
{
|
|
|
|
|
MaxWidth maxWidth;
|
|
|
|
|
|
|
|
|
|
if (Options.MaxWidth.HasValue)
|
|
|
|
|
{
|
|
|
|
|
maxWidth = Options.MaxWidth.Value;
|
|
|
|
|
}
|
|
|
|
|
else if (GlobalDialogOptions.MaxWidth.HasValue)
|
|
|
|
|
{
|
|
|
|
|
maxWidth = GlobalDialogOptions.MaxWidth.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
maxWidth = MaxWidth.Small;
|
|
|
|
|
}
|
|
|
|
|
return $"dialog-width-{maxWidth.ToDescription()}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetFullWidth()
|
|
|
|
|
{
|
|
|
|
|
if (Options.FullWidth.HasValue)
|
|
|
|
|
return Options.FullWidth.Value;
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.FullWidth.HasValue)
|
|
|
|
|
return GlobalDialogOptions.FullWidth.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetFulScreen()
|
|
|
|
|
{
|
|
|
|
|
if (Options.FullScreen.HasValue)
|
|
|
|
|
return Options.FullScreen.Value;
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.FullScreen.HasValue)
|
|
|
|
|
return GlobalDialogOptions.FullScreen.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected string Classname =>
|
|
|
|
|
new CssBuilder("dialog")
|
|
|
|
|
.AddClass(DialogMaxWidth, !FullScreen)
|
|
|
|
|
.AddClass("dialog-width-full", FullWidth && !FullScreen)
|
|
|
|
|
.AddClass("dialog-fullscreen", FullScreen)
|
|
|
|
|
.AddClass("dialog-rtl", RightToLeft)
|
|
|
|
|
.AddClass(_dialog?.AdditionalClassList)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
private bool SetHideHeader()
|
|
|
|
|
{
|
|
|
|
|
if (Options.NoHeader.HasValue)
|
|
|
|
|
return Options.NoHeader.Value;
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.NoHeader.HasValue)
|
|
|
|
|
return GlobalDialogOptions.NoHeader.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetCloseButton()
|
|
|
|
|
{
|
|
|
|
|
if (Options.CloseButton.HasValue)
|
|
|
|
|
return Options.CloseButton.Value;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.CloseButton.HasValue)
|
|
|
|
|
return GlobalDialogOptions.CloseButton.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetDisableBackdropClick()
|
|
|
|
|
#region Lifecycle
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
if (Options.DisableBackdropClick.HasValue)
|
|
|
|
|
return Options.DisableBackdropClick.Value;
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.DisableBackdropClick.HasValue)
|
|
|
|
|
return GlobalDialogOptions.DisableBackdropClick.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
ConfigureInstance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetCloseOnEscapeKey()
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
if (Options.CloseOnEscapeKey.HasValue)
|
|
|
|
|
return Options.CloseOnEscapeKey.Value;
|
|
|
|
|
|
|
|
|
|
if (GlobalDialogOptions.CloseOnEscapeKey.HasValue)
|
|
|
|
|
return GlobalDialogOptions.CloseOnEscapeKey.Value;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleBackgroundClick()
|
|
|
|
|
if (firstRender)
|
|
|
|
|
{
|
|
|
|
|
if (DisableBackdropClick)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_dialog?.OnBackdropClick == null)
|
|
|
|
|
//Since CloseOnEscapeKey is the only thing to be handled, turn interceptor off
|
|
|
|
|
if (CloseOnEscapeKey)
|
|
|
|
|
{
|
|
|
|
|
Cancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dialog?.OnBackdropClick.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Dialog _dialog;
|
|
|
|
|
private bool _disposedValue;
|
|
|
|
|
_keyInterceptor = _keyInterceptorFactory.Create();
|
|
|
|
|
|
|
|
|
|
public void Register(Dialog dialog)
|
|
|
|
|
await _keyInterceptor.Connect(_elementId, new KeyInterceptorOptions()
|
|
|
|
|
{
|
|
|
|
|
if (dialog == null)
|
|
|
|
|
return;
|
|
|
|
|
_dialog = dialog;
|
|
|
|
|
//AdditionalClassList = dialog.AdditionalClassList;
|
|
|
|
|
TitleContent = dialog.TitleContent;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
TargetClass = "dialog",
|
|
|
|
|
Keys = {
|
|
|
|
|
new KeyOptions { Key="Escape", SubscribeDown = true },
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
_keyInterceptor.KeyDown += HandleKeyDown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ForceRender()
|
|
|
|
|
{
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Cancels all dialogs in dialog provider collection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void CancelAll()
|
|
|
|
|
{
|
|
|
|
|
Parent?.DismissAll();
|
|
|
|
|
await base.OnAfterRenderAsync(firstRender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
@ -350,4 +356,6 @@ public partial class DialogInstance : UIComponent, IDisposable
|
|
|
|
|
Dispose(disposing: true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|