-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from stavroskasidis/release/2.0
Release/2.0
- Loading branch information
Showing
76 changed files
with
2,776 additions
and
889 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@inject IBlazorDialogStore store | ||
@namespace BlazorDialog | ||
@implements IDisposable | ||
@foreach (var dialog in store.GetComponentsAsDialogs()) | ||
{ | ||
if (!dialog.Value.Options.IsCustom) | ||
{ | ||
<Dialog Id="@dialog.Key" @key="dialog.Key" Animation="dialog.Value.Options.Animation" BaseZIndex="dialog.Value.Options.BaseZIndex" | ||
Centered="dialog.Value.Options.Centered" CssClass="@dialog.Value.Options.CssClass" Size="dialog.Value.Options.Size" | ||
OnAfterRender="EventUtil.AsNonRenderingEventCallback((bool firstLoad) => OnAfterDialogRender(firstLoad, dialog))"> | ||
<DynamicComponent Type="dialog.Value.Options.ComponentType" Parameters="dialog.Value.Options.Parameters"></DynamicComponent> | ||
</Dialog> | ||
} | ||
else | ||
{ | ||
<Dialog Id="@dialog.Key" @key="dialog.Key" IsCustom="dialog.Value.Options.IsCustom" OnAfterRender="EventUtil.AsNonRenderingEventCallback((bool firstLoad) => OnAfterDialogRender(firstLoad, dialog))"> | ||
<DynamicComponent Type="dialog.Value.Options.ComponentType" Parameters="dialog.Value.Options.Parameters"></DynamicComponent> | ||
</Dialog> | ||
} | ||
} | ||
|
||
@code { | ||
protected override void OnInitialized() | ||
{ | ||
store.OnComponentAsDialogsChanged += Refresh; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
store.OnComponentAsDialogsChanged -= Refresh; | ||
} | ||
|
||
protected async Task Refresh() | ||
{ | ||
await InvokeAsync(StateHasChanged); | ||
} | ||
|
||
protected async Task OnAfterDialogRender(bool firstLoad, KeyValuePair<string,ComponentDialog> dialog) | ||
{ | ||
if (firstLoad) | ||
{ | ||
dialog.Value.RenderTaskCompletionSource.SetResult(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorDialog | ||
{ | ||
//Source: https://gist.github.com/SteveSandersonMS/8a19d8e992f127bb2d2a315ec6c5a373 | ||
//Issue: https://github.com/dotnet/aspnetcore/issues/18919 | ||
internal static class EventUtil | ||
{ | ||
// The repetition in here is because of the four combinations of handlers (sync/async * with/without arg) | ||
public static Action AsNonRenderingEventHandler(Action callback) | ||
=> new SyncReceiver(callback).Invoke; | ||
public static Action<TValue> AsNonRenderingEventHandler<TValue>(Action<TValue> callback) | ||
=> new SyncReceiver<TValue>(callback).Invoke; | ||
public static Func<Task> AsNonRenderingEventHandler(Func<Task> callback) | ||
=> new AsyncReceiver(callback).Invoke; | ||
public static Func<TValue, Task> AsNonRenderingEventHandler<TValue>(Func<TValue, Task> callback) | ||
=> new AsyncReceiver<TValue>(callback).Invoke; | ||
public static EventCallback AsNonRenderingEventCallback(Action callback) => new(new ReceiverBase(), callback); | ||
public static EventCallback<T> AsNonRenderingEventCallback<T>(Action<T> callback) => new(new ReceiverBase(), callback); | ||
public static EventCallback AsNonRenderingEventCallback(Func<Task> callback) => new(new ReceiverBase(), callback); | ||
public static EventCallback<T> AsNonRenderingEventCallback<T>(Func<T, Task> callback) => new(new ReceiverBase(), callback); | ||
|
||
record SyncReceiver(Action callback) : ReceiverBase { public void Invoke() => callback(); } | ||
record SyncReceiver<T>(Action<T> callback) : ReceiverBase { public void Invoke(T arg) => callback(arg); } | ||
record AsyncReceiver(Func<Task> callback) : ReceiverBase { public Task Invoke() => callback(); } | ||
record AsyncReceiver<T>(Func<T, Task> callback) : ReceiverBase { public Task Invoke(T arg) => callback(arg); } | ||
|
||
// By implementing IHandleEvent, we can override the event handling logic on a per-handler basis | ||
// The logic here just calls the callback without triggering any re-rendering | ||
record ReceiverBase : IHandleEvent | ||
{ | ||
public Task HandleEventAsync(EventCallbackWorkItem item, object arg) => item.InvokeAsync(arg); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,79 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Components; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BlazorDialog | ||
{ | ||
public class ComponentAsDialogOptions | ||
{ | ||
public ComponentAsDialogOptions(Type componentType) | ||
{ | ||
ComponentType = componentType; | ||
} | ||
|
||
/// <summary> | ||
/// The type of the rendered component | ||
/// </summary> | ||
public Type ComponentType { get; protected set; } | ||
|
||
/// <summary> | ||
/// The parameters of the rendered component. | ||
/// </summary> | ||
public Dictionary<string, object> Parameters { get; set; } = new(); | ||
|
||
/// <summary> | ||
/// If set to true then all default html/css is removed. Use when custom dialog implementations are needed. | ||
/// </summary> | ||
public bool IsCustom { get; set; } | ||
|
||
/// <summary> | ||
/// Allows you to change the appearing animation. Ignored when the dialog is <see cref="Dialog.IsCustom" />. | ||
/// </summary> | ||
public DialogAnimation Animation { get; set; } = DialogAnimation.None; | ||
|
||
/// <summary> | ||
/// The base z-index of the dialog when shown. Default: 1050 | ||
/// </summary> | ||
public int BaseZIndex { get; set; } = 1050; | ||
|
||
/// <summary> | ||
/// Allows you to set the positioning of the dialog from the top. Ignored when the dialog is <see cref="Dialog.IsCustom" />. | ||
/// </summary> | ||
public bool Centered { get; set; } | ||
|
||
/// <summary> | ||
/// Adds a custom css class to the wrapper of the dialog. | ||
/// </summary> | ||
public string? CssClass { get; set; } | ||
|
||
/// <summary> | ||
/// Allows you to set the dialog size. Ignored when the dialog is <see cref="Dialog.IsCustom" />. | ||
/// </summary> | ||
public DialogSize Size { get; set; } = DialogSize.Normal; | ||
} | ||
|
||
public class ComponentDialog | ||
{ | ||
public ComponentAsDialogOptions Options { get; set; } | ||
public TaskCompletionSource RenderTaskCompletionSource { get; set; } | ||
} | ||
|
||
public interface IBlazorDialogStore | ||
{ | ||
|
||
void Register(Dialog blazorDialog); | ||
void Unregister(Dialog blazorDialog); | ||
Dialog GetById(string id); | ||
int GetVisibleDialogsCount(); | ||
|
||
Task RegisterComponentDialog(string id, ComponentDialog compDialog); | ||
Task UnregisterComponentDialog(string id); | ||
|
||
Dictionary<string, ComponentDialog> GetComponentsAsDialogs(); | ||
|
||
event Func<Task> OnComponentAsDialogsChanged; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@using Microsoft.AspNetCore.Components.Web | ||
@using Microsoft.AspNetCore.Components.Forms | ||
@using Microsoft.AspNetCore.Components.Routing | ||
@using Microsoft.AspNetCore.Components | ||
@using Microsoft.JSInterop |
Oops, something went wrong.