BlazorModalPlus 1.2.0
dotnet add package BlazorModalPlus --version 1.2.0
NuGet\Install-Package BlazorModalPlus -Version 1.2.0
<PackageReference Include="BlazorModalPlus" Version="1.2.0" />
paket add BlazorModalPlus --version 1.2.0
#r "nuget: BlazorModalPlus, 1.2.0"
// Install BlazorModalPlus as a Cake Addin #addin nuget:?package=BlazorModalPlus&version=1.2.0 // Install BlazorModalPlus as a Cake Tool #tool nuget:?package=BlazorModalPlus&version=1.2.0
BlazorModalPlus
BlazorModalPlus is a Blazor library that provides Bootstrap 5-based modal dialog components. These components are highly customizable and fit a variety of confirmation and dialog use cases. Additionally, multi-language support is added.
Features
BsConfirmDialog:
- Customizable header and footer using
RenderFragment
. - Displays a dialog with a title, message, and dynamically defined buttons.
- Buttons are configured using
ButtonItem
, allowing custom captions, styles and event callbacks.
- Customizable header and footer using
BsSimpleConfirmDialog:
- Simplified for quick confirmations.
- Displays a title, message, and predefined buttons based on
DialogButtons
. - Returns the button action via
EventCallback<DialogButtonResult>
. - Service to support for Globalization and Localization
Both components support light and dark themes using the Parameter DarkMode
.
[!NOTE] The DarkMode is available since Bootstrap version 5.3. If you are using an older version, the DarkMode will not work.
Prerequisites
Version | .NET |
---|---|
1.0.0 | .NET 8 |
Installation
Add BlazorModalPlus to your project via NuGet:
dotnet add package BlazorModalPlus
Add the following to _Imports.razor
@using BlazorModalPlus
Getting Started
[!NOTE] BlazorModalPlus supports the following languages: en-US, es-MX, fr-FR, de-DE, it-IT, ja-JP, pt-PT & zh-CN
To use the components, add the following to your Program.cs
file:
// In this case, we use "es-MX" as the default culture and support both "en-US" and "es-MX".
builder.Services.AddBlazorModalPlusServices(
supportedCultures: new[] { "en-US","es-MX" },
defaultCulture: "es-MX");
...
var localizationOptions = app.Services.GetRequiredService<IOptions<RequestLocalizationOptions>>().Value;
app.UseRequestLocalization(localizationOptions);
The components are based on Bootstrap version 5, then, it is necessary to include the Bootstrap references if it is not included in your project as follows:
<head>
...
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
How to use
BsConfirmDialog
@using BlazorModalPlus
<h3>Dialog Modal</h3>
<button class="btn btn-primary" @onclick="BtnClick">
Show dialog
</button>
<hr />
<p>
@actionMessage
</p>
<BsConfirmDialog @ref="refConfirmDialog">
<HeaderTemplate>
<h4 class="text-primary fw-bold">Dialog Modal</h4>
</HeaderTemplate>
<FooterTemplate>
<InputDate @bind-Value="dateSelected" />
</FooterTemplate>
</BsConfirmDialog>
@code {
BsConfirmDialog? refConfirmDialog;
public DateTime dateSelected { get; set; } = DateTime.Now;
public string actionMessage { get; set; } = string.Empty;
protected async Task BtnClick()
{
if (refConfirmDialog != null)
{
IEnumerable<ButtonItem> buttons = new List<ButtonItem>
{
new ButtonItem("Process", BtnRenderStyle.Primary, null, EventCallback.Factory.Create(this, ProcessActionDialog)),
new ButtonItem("Cancel", BtnRenderStyle.Warning, null, EventCallback.Factory.Create(this, CancelActionDialog))
};
await refConfirmDialog.ShowDialog("Process action?", null, buttons);
}
}
#region Dialog Actions
private async Task ProcessActionDialog()
{
await Task.Run(() => actionMessage = $"Process button pressed with date: {dateSelected.ToShortDateString()} selected");
}
private async Task CancelActionDialog()
{
await Task.Run(() => actionMessage = $"Cancel button pressed with date: {dateSelected.ToShortDateString()} selected");
}
#endregion
}
BsSimpleConfirmDialog
@using BlazorModalPlus
<h3>Simple Dialog Modal</h3>
<button class="btn btn-primary" @onclick="BtnClick">
Show dialog
</button>
<hr />
<p>
@actionMessage
</p>
<BsSimpleConfirmDialog @ref="refConfirmSimple" ConfirmCallback="ConfirmationCallback">
</BsSimpleConfirmDialog>
@code {
BsSimpleConfirmDialog? refConfirmSimple;
public string actionMessage { get; set; } = string.Empty;
protected async Task BtnClick()
{
if (refConfirmSimple != null)
await refConfirmSimple.ShowDialog("You need <b>more</b> information?", "Please confirm", DialogButtons.YesNoCancel);
}
protected async Task ConfirmationCallback(DialogButtonResult result)
{
actionMessage = result switch
{
DialogButtonResult.Yes => "Yes button pressed!",
DialogButtonResult.No => "No button pressed!",
DialogButtonResult.Cancel => "Cancel button pressed!",
_ => string.Empty
};
await Task.CompletedTask;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.11)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.1.1)
- Microsoft.AspNetCore.Localization (>= 2.1.1)
- Microsoft.Extensions.Localization (>= 8.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.