BlazorDoodles.Modal 0.1.1

dotnet add package BlazorDoodles.Modal --version 0.1.1
NuGet\Install-Package BlazorDoodles.Modal -Version 0.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorDoodles.Modal" Version="0.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlazorDoodles.Modal --version 0.1.1
#r "nuget: BlazorDoodles.Modal, 0.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BlazorDoodles.Modal as a Cake Addin
#addin nuget:?package=BlazorDoodles.Modal&version=0.1.1

// Install BlazorDoodles.Modal as a Cake Tool
#tool nuget:?package=BlazorDoodles.Modal&version=0.1.1

BlazorDoodles.Modal

A Blazor modal framework without any opinions about styling.

Setup

Add the following to your Blazor project to get started:

Program.cs
builder.Services.AddModalDoodle();
_Imports.razor
@using BlazorDoodles.Modal
App.razor
<Router AppAssembly="@typeof(App).Assembly">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
        <FocusOnNavigate RouteData="@routeData" Selector="h1" />
    </Found>
    <NotFound>
        <PageTitle>Not found</PageTitle>
        <LayoutView Layout="@typeof(MainLayout)">
            <p role="alert">Sorry, there's nothing at this address.</p>
        </LayoutView>
    </NotFound>
</Router>


<ModalDisplay />

Example Usage

Check out the sample project for a more complete picture of usage.

Basic Modal

To use a basic modal, simply add @inherits ModalBase to your modal component:

SimpleModal.razor
@inherits ModalBase


<MyModal>
    <div class="modal-header">
        <h1 class="modal-title fs-5">@Title</h1>
        <button @onclick="Modal.Cancel" type="button" class="btn-close" aria-label="Close"></button>
    </div>
    <div class="modal-body">
        @Text
    </div>
    
    
    <div class="modal-footer">
        <div class="col">
            <button @onclick="Modal.Close" type="button" class="btn btn-primary w-100">
                Confirm
            </button>
        </div>
        <div class="col">
            <button @onclick="Modal.Cancel" type="button" class="btn btn-secondary w-100">
                Cancel
            </button>
        </div>
    </div>
</MyModal>


To launch this modal, use IModalService:

SimpleModalDemo.razor
@inject IModalService ModalService

@code {
    private IModalResult? Result { get; set; }

    private async Task ShowModal()
    {
        Result = await ModalService.Open<SimpleModal>();
    }
}

Returning data

To enable a modal to return custom data, inherit from ModalBase<T>.

FormModal.razor
@inherits ModalBase<PersonModel>

<EditForm Model="NewPerson" OnValidSubmit="() => Modal.Close(NewPerson)">    
    <DataAnnotationsValidator />    
    
</EditForm>

@code {
    private PersonModel NewPerson { get; set; } = new();
}

Now when you launch the modal you'll get back a typed response:

FormModalDemo.razor
@inject IModalService ModalService

@code {
    private List<PersonModel> People { get; set; } = new();

    private IModalResult<PersonModel>? Result { get; set; }

    private async Task ShowModal()
    {
        Result = await ModalService.Open<FormModal, PersonModel>();

        if (!Result.IsCanceled)
            People.Add(Result.Data);
    }
}

Passing parameters

To pass data to a modal, define a class to hold parameter data. You can use validation here too.

ConfirmationModal.razor
@inherits ModalBase

@code {

    [Parameter, EditorRequired] public string Title { get; set; } = default!;
    [Parameter, EditorRequired] public string Text { get; set; } = default!;

    public class Parameters : ModalParameters<ConfirmationModal>
    {
        [Required] public string Title { get; set; } = "Confirm Action";
        [Required] public string Text { get; set; } = "Are you sure you want to do this?";
    }
}

To launch this modal:

ConfirmationModalDemo.razor
@inject IModalService ModalService

@code {
    private ConfirmationModal.Parameters Parameters { get; set; } = new();
    private IModalResult? Result { get; set; }

    private async Task ShowConfirmationModal()
    {
        Result = await ModalService.Open<ConfirmationModal>(Parameters);
    }
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.1 462 11/25/2022
0.1.0 199 11/25/2022