From 49baee26a9c9f1b88b002da1bb7eefaa95816538 Mon Sep 17 00:00:00 2001 From: msynk Date: Thu, 16 Jul 2026 21:18:45 +0330 Subject: [PATCH 1/2] improve BitMessageBox component #12672 --- .../MessageBox/BitMessageBoxService.cs | 29 +++++++++---- .../Extras/MessageBox/BitMessageBoxDemo.razor | 41 +++++++++++++++---- .../MessageBox/BitMessageBoxDemo.razor.cs | 14 +++++++ .../BitMessageBoxDemo.razor.samples.cs | 38 ++++++++++++++--- 4 files changed, 102 insertions(+), 20 deletions(-) diff --git a/src/BlazorUI/Bit.BlazorUI.Extras/Components/MessageBox/BitMessageBoxService.cs b/src/BlazorUI/Bit.BlazorUI.Extras/Components/MessageBox/BitMessageBoxService.cs index 7b923dda89..3475e76e1e 100644 --- a/src/BlazorUI/Bit.BlazorUI.Extras/Components/MessageBox/BitMessageBoxService.cs +++ b/src/BlazorUI/Bit.BlazorUI.Extras/Components/MessageBox/BitMessageBoxService.cs @@ -1,23 +1,38 @@ -namespace Bit.BlazorUI; +namespace Bit.BlazorUI; /// -/// A wrapper serive around the to enhance showing message boxes. +/// A wrapper service around the and to enhance showing message boxes. +/// It works with either of these services when available and prefers the when both are available. /// -public class BitMessageBoxService(BitModalService modalService) +public class BitMessageBoxService(BitProModalService? proModalService = null, BitModalService? modalService = null) { /// - /// Shows a inside a using the . + /// Shows a inside a using the when available, + /// otherwise inside a using the . /// public async Task Show(string title, string body) { - BitModalReference modalRef = default!; + Func closeModal = () => Task.CompletedTask; Dictionary parameters = new() { { nameof(BitMessageBox.Title), title }, { nameof(BitMessageBox.Body), body }, - { nameof(BitMessageBox.OnClose), EventCallback.Factory.Create(this, () => modalRef.Close()) } + { nameof(BitMessageBox.OnClose), EventCallback.Factory.Create(this, () => closeModal()) } }; - modalRef = await modalService.Show(parameters); + if (proModalService is not null) + { + var modalRef = await proModalService.Show(parameters); + closeModal = modalRef.Close; + } + else if (modalService is not null) + { + var modalRef = await modalService.Show(parameters); + closeModal = modalRef.Close; + } + else + { + throw new InvalidOperationException("Neither BitProModalService nor BitModalService is available. Register at least one of them to use BitMessageBoxService."); + } } } diff --git a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor index a39946b5bd..ad6280cc5d 100644 --- a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor +++ b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor @@ -1,4 +1,4 @@ -@page "/components/messagebox" +@page "/components/messagebox" +
The basic usage of the BitMessageBox, rendered inline inside a BitCard.
+
+
Show the BitMessageBox inside a BitModal component and close it using the OnClose event.
+
Show
- + +
Show the BitMessageBox inside a BitProModal component and close it using the OnClose event.
+
+ Show + + + +
+ + +
Show the BitMessageBox as the content of a modal shown by the BitModalService.
+
Show MessageBox
- + +
Show the BitMessageBox as the content of a pro modal shown by the BitProModalService.
+
+ Show MessageBox +
+ + +
+ Show the BitMessageBox with a simple call to the Show method of the BitMessageBoxService. + This service uses the BitProModalService or the BitModalService (whichever is available) to show the message box, + preferring the BitProModalService when both are available. +
+
Show MessageBox
- -
Customize the appearance of BitActionButton using styles and CSS classes.
+ +
Customize the appearance of BitMessageBox using styles and CSS classes.

@@ -63,7 +90,7 @@
- +
Use BitMessageBox in right-to-left (RTL).


@@ -73,4 +100,4 @@
- \ No newline at end of file + diff --git a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor.cs b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor.cs index fe7b10e9c4..0fd824db72 100644 --- a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor.cs +++ b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor.cs @@ -133,6 +133,7 @@ public partial class BitMessageBoxDemo private bool isModalOpen; + private bool isProModalOpen; [AutoInject] private BitModalService modalService { get; set; } = default!; private async Task ShowMessageBox() @@ -147,6 +148,19 @@ private async Task ShowMessageBox() modalRef = await modalService.Show(parameters); } + [AutoInject] private BitProModalService proModalService { get; set; } = default!; + private async Task ShowProMessageBox() + { + BitProModalReference modalRef = default!; + Dictionary parameters = new() + { + { nameof(BitMessageBox.Title), "This is a title" }, + { nameof(BitMessageBox.Body), "This is a body." }, + { nameof(BitMessageBox.OnClose), EventCallback.Factory.Create(this, () => modalRef.Close()) } + }; + modalRef = await proModalService.Show(parameters); + } + [AutoInject] private BitMessageBoxService messageBoxService { get; set; } = default!; private async Task ShowMessageBoxService() { diff --git a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor.samples.cs b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor.samples.cs index 8fe6ec33e1..42532ff1d2 100644 --- a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor.samples.cs +++ b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/MessageBox/BitMessageBoxDemo.razor.samples.cs @@ -1,4 +1,4 @@ -namespace Bit.BlazorUI.Demo.Client.Core.Pages.Components.Extras.MessageBox; +namespace Bit.BlazorUI.Demo.Client.Core.Pages.Components.Extras.MessageBox; public partial class BitMessageBoxDemo { @@ -16,10 +16,18 @@ public partial class BitMessageBoxDemo private bool isModalOpen;"; private readonly string example3RazorCode = @" + isProModalOpen = true"">Show + + isProModalOpen = false"" Title=""This is the Title"" Body=""This is the Body!"" /> +"; + private readonly string example3CsharpCode = @" +private bool isProModalOpen;"; + + private readonly string example4RazorCode = @" Show MessageBox "; - private readonly string example3CsharpCode = @" + private readonly string example4CsharpCode = @" [AutoInject] private BitModalService modalService { get; set; } = default!; private async Task ShowMessageBox() { @@ -33,16 +41,34 @@ private async Task ShowMessageBox() modalRef = await modalService.Show(parameters); }"; - private readonly string example4RazorCode = @" + private readonly string example5RazorCode = @" +Show MessageBox + +"; + private readonly string example5CsharpCode = @" +[AutoInject] private BitProModalService proModalService { get; set; } = default!; +private async Task ShowProMessageBox() +{ + BitProModalReference modalRef = default!; + Dictionary parameters = new() + { + { nameof(BitMessageBox.Title), ""This is a title"" }, + { nameof(BitMessageBox.Body), ""This is a body."" }, + { nameof(BitMessageBox.OnClose), EventCallback.Factory.Create(this, () => modalRef.Close()) } + }; + modalRef = await proModalService.Show(parameters); +}"; + + private readonly string example6RazorCode = @" Show MessageBox"; - private readonly string example4CsharpCode = @" + private readonly string example6CsharpCode = @" [AutoInject] private BitMessageBoxService messageBoxService { get; set; } = default!; private async Task ShowMessageBoxService() { await messageBoxService.Show(""TITLE"", ""BODY""); }"; - private readonly string example5RazorCode = @" + private readonly string example7RazorCode = @"