A Blazor Wrapper for JS's Window.confirm() and onbeforeunload as .Net Blazor Component.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE Update issue templates Oct 28, 2018
ScreenShots initial push Oct 23, 2018
docs Update index.html Nov 16, 2018
src migrated to Blazor 0.7.0 Nov 16, 2018
.gitignore onbeforeunload added Oct 24, 2018
BlazorConfirm.sln initial push Oct 23, 2018
LICENSE Initial commit Oct 23, 2018
README.md Merge branch 'master' of github.com:ctrl-alt-d/BlazorConfirm Nov 16, 2018

README.md

BlazorConfirm

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.