/BlazorConfirm

A Blazor Wrapper for JS's Window.confirm() and onbeforeunload as .Net Blazor Component.

Primary LanguageHTMLMIT LicenseMIT

BlazorConfirm

Deprecated Sorry guys, no maintenance. This library is deprecated.

Blazor Confirm Dialog | Blazor Confirm Close Tab

A Blazor wrapper of Window.confirm() and onbeforeunload confirmation as .Net Blazor Component.

The sample project has been published here.

Note: Just as Blazor, this repo is also experimental.

Why confirm?

Remember:

Avoid using dialog boxes for confirmation.

... but in some cases we need them.

ScreenShot and Demo

Because we love screen shots and demos.

Demo: https://ctrl-alt-d.github.io/BlazorConfirm/

BlazorConfig ScreenShot

Changes

  • 0.7.0.1

    • Migrated to Blazor 0.7.0 experimental.
  • 0.6.0.1

    • Handling onbeforeunload
  • version 0.6.0

    • initial version for blazor 0.6.0

Configuration

dotnet add package BlazorConfirm --version 0.7.0.1

Or:

Install-Package BlazorConfirm -Version 0.7.0.1

Configure the dependency injection

Set DI on ConfigureServices of your Startup.cs:

using ctrlaltd.SimpleBlazorComponents;
using Microsoft.AspNetCore.Blazor.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Sample
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            ...
            services.AddSingleton<IBlazorConfirmDialog, BlazorConfirmDialog>(); //Add as singleton.
        }

and add the component to App.cshtml (or to another component always loaded in the application)

@addTagHelper *, BlazorConfirm
<BlazorConfirmContainer />

<Router AppAssembly=typeof(Program).Assembly />

Usage

In a component:

@inject ctrlaltd.SimpleBlazorComponents.IBlazorConfirmDialog blazorConfirmDialog

In a class:

[Inject] 
protected ctrlaltd.SimpleBlazorComponents.IBlazorConfirmDialog blazorConfirmDialog { get; set; }

At this point you can wrap your code into the onSuccessDelegate Dialog:

void IncrementCount()
{
    blazorConfirmDialog.NewDialog( message: "Are you sure do you want to increment the counter?", 
                                   onSuccessDelegate: ( () => {currentCount++;
                                                               StateHasChanged();
                                                               } ) );
}

A sample to confirm exit current page:

blazorConfirmDialog.NewDialog( onSuccessDelegate: (() => {UriHelper.NavigateTo(  "/fetchdata" );}));

Credits

Dani Herrera

License

BlazorConfirm is licensed under MIT license

Special Thanks

Thankyou to @ghidello and https://github.com/sotsera/sotsera.blazor.toaster repo.