Kebechet.Blazor.Components.Popup 4.0.3

dotnet add package Kebechet.Blazor.Components.Popup --version 4.0.3
NuGet\Install-Package Kebechet.Blazor.Components.Popup -Version 4.0.3
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="Kebechet.Blazor.Components.Popup" Version="4.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kebechet.Blazor.Components.Popup --version 4.0.3
#r "nuget: Kebechet.Blazor.Components.Popup, 4.0.3"
#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 Kebechet.Blazor.Components.Popup as a Cake Addin
#addin nuget:?package=Kebechet.Blazor.Components.Popup&version=4.0.3

// Install Kebechet.Blazor.Components.Popup as a Cake Tool
#tool nuget:?package=Kebechet.Blazor.Components.Popup&version=4.0.3

Blazor.Components.Popup

This repo contain PopupContainer component. It's purpose is to simplify Popup usage in Blazor.

Setup

  • Install nuget package Kebechet.Blazor.Components.Popup
  • In your Program.cs add:
builder.Services.AddPopupServices();

Usage

  • Ideally in MainLayout.razor put <PopupContainer /> component. This component is controlled from PopupService and it's purpose is to render popup content.
    • ⚠️ At one time only 1 popup can be rendered.
  • In component where you would like to render popup inject Popup service like:
@inject PopupService _popupService
  • Create Popup content component. E.g. YesNoPopup.razor that implements interface IPopupReturnable<T> with return type you need to get from the Popup. This popup content will be rendered inside PopupContainer.
    • ⚠️ I recommend to always use nullable type like IPopupReturnable<bool?> because that way you can differentiate between person clicking NO/False and person closing the popup be clicking outside of it.
    • ⚠️ The child component must have [Parameter] at the beginning of the OnReturnValue property, otherwise it won't work.

YesNoPopup.razor part

@using Blazor.Components.Popup.Components;

<span>Do you want to save changes ?</span>
<button @onclick="()=>Process(true)">Yes, I do</button>
<button @onclick="()=>Process(false)">No, I don't</button>

YesNoPopup.razor.cs part

using Blazor.Components.Popup.Components;
using Microsoft.AspNetCore.Components;

namespace BlazorApp7.Pages;

public partial class YesNoComponent : IPopupReturnable<bool?>
{
    [Parameter] public EventCallback<bool?> OnReturnValue { get; set; }

    public async Task Process(bool val)
    {
        await OnReturnValue.InvokeAsync(val);
    }
}
  • then in your component where you would like to render popup:
    • inject PopupService
    • add functionality to trigger popup. In our case button onClick event
    • and finally use Show method to show YesNoPopup and get result from it

YourComponent.razor

@inject PopupService _popupService

<button @onclick="Test">Trigger popup</button>

@code{
    public async Task Test()
    {
        var isSuccess =  await _popupService.Show(new YesNoPopup());
        if (isSuccess is null)
        {
            // user closed the popup
        } 
        else if(isSuccess == true)
        {
            // user clicked the button that returns true
        } 
        else if(isSuccess == false){
            // user clicked the button that returns false
        }
    }
}
  • ENJOY 🎉

Future tasks:

Product 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. 
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
4.0.3 382 2/12/2024
4.0.2 82 2/12/2024
4.0.1 223 1/22/2024
4.0.0 76 1/22/2024
3.1.0 80 1/22/2024
3.0.0 84 1/21/2024
2.0.0 143 1/14/2024
1.1.1 111 1/11/2024
1.1.0 117 1/8/2024
1.0.2 119 1/7/2024
1.0.1 97 1/7/2024
1.0.0 406 11/10/2023

Fixed double to string conversion