Skip to content

Commit

Permalink
Added support for dialog-in-dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
stavroskasidis committed Oct 17, 2020
1 parent b2e86b3 commit 864ce5e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
7 changes: 7 additions & 0 deletions BlazorDialog/BlazorDialogStore.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Linq;

namespace BlazorDialog
{
Expand All @@ -18,6 +20,11 @@ public Dialog GetById(string id)
throw new ArgumentException($"No dialog found for id '{id}'", nameof(id));
}

public int GetVisibleDialogsCount()
{
return registeredDialogs.Count(x => x.Value.GetVisibility());
}

public void Register(Dialog blazorDialog)
{
if (blazorDialog?.Id == null)
Expand Down
11 changes: 9 additions & 2 deletions BlazorDialog/Components/Dialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<CascadingValue Value="this.Input" Name="DialogInput">
@if (!IsCustom)
{
<div class="blazor-dialog-container @(Centered ? "blazor-dialog-centered" : "")">
<div class="blazor-dialog-container @(Centered ? "blazor-dialog-centered" : "")" style="z-index:@(1050 + dialogDepth)">
<div class="blazor-dialog-content-wrapper @ContentWrapperCssClass @AnimationCssClass">
<div class="blazor-dialog-content">
@ChildContent
Expand Down Expand Up @@ -152,7 +152,7 @@
}

bool isShowingChanged = false;

int dialogDepth = 0;
protected override async Task OnParametersSetAsync()
{
if (isShowingChanged && IsShowing == true && !isShowing)
Expand All @@ -163,6 +163,7 @@
await OnBeforeShow.InvokeAsync(args);
}
this.isShowing = true;
dialogDepth = dialogStore.GetVisibleDialogsCount();
if (OnAfterShow.HasDelegate)
{
var args = new DialogAfterShowEventArgs(this);
Expand Down Expand Up @@ -225,6 +226,7 @@
await OnBeforeShow.InvokeAsync(args);
}
this.isShowing = true;
dialogDepth = dialogStore.GetVisibleDialogsCount();
await InvokeAsync(() => StateHasChanged());
if (OnAfterShow.HasDelegate)
{
Expand Down Expand Up @@ -263,4 +265,9 @@
{
await this.Hide<object>(null);
}

public bool GetVisibility()
{
return this.isShowing;
}
}
1 change: 1 addition & 0 deletions BlazorDialog/IBlazorDialogStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface IBlazorDialogStore
void Register(Dialog blazorDialog);
void Unregister(Dialog blazorDialog);
Dialog GetById(string id);
int GetVisibleDialogsCount();
}
}
1 change: 0 additions & 1 deletion BlazorDialog/wwwroot/styles.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.blazor-dialog-container {
position: fixed;
z-index: 1050;
left: 0;
top: 0;
width: 100%; /* Full width */
Expand Down
29 changes: 16 additions & 13 deletions TestApps/BlazorDialog.TestAppsCommon/IndexCommon.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@
<option value="@DialogAnimation.Zoom">@DialogAnimation.Zoom</option>
<option value="@DialogAnimation.FadeIn">@DialogAnimation.FadeIn</option>
</select>

<Dialog Id="simple-dialog" Size="size" Centered="isCentered" Animation="animation">
<DialogInputProvider TInput="string">
<DialogBody>
<h4>@context.Input</h4>
</DialogBody>
<DialogFooter>
<button type="button" class="btn btn-primary" @onclick="@(() => context.Dialog.Hide("yes"))">Yes</button>
<button type="button" class="btn btn-secondary" @onclick="@(()=> context.Dialog.Hide("no"))">No</button>
</DialogFooter>
</DialogInputProvider>
</Dialog>

<Dialog Id="simple-large-dialog" Size="size" Centered="isCentered" Animation="animation">
<DialogInputProvider TInput="string">
<DialogHeader ShowClose="true">
Expand Down Expand Up @@ -60,6 +47,22 @@
</DialogInputProvider>
</Dialog>

<Dialog Id="simple-dialog" Size="size" Centered="isCentered" Animation="animation">
<DialogInputProvider TInput="string">
<DialogBody>
<h4>@context.Input</h4>
</DialogBody>
<DialogFooter>
<button type="button" class="btn btn-primary" @onclick="@(() => context.Dialog.Hide("yes"))">Yes</button>
<button type="button" class="btn btn-secondary" @onclick="@(()=> context.Dialog.Hide("no"))">No</button>

<button @onclick="SimpleDialogBigOnClick">Simple Dialog Big (dialog in dialog)</button>
</DialogFooter>
</DialogInputProvider>
</Dialog>



<button @onclick="SimpleDialogOnClick">Simple Dialog</button>
<button @onclick="SimpleDialogBigOnClick">Simple Dialog Big</button>

Expand Down

0 comments on commit 864ce5e

Please sign in to comment.