Kebechet.Blazor.Components.Popup
1.0.0
Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Kebechet.Blazor.Components.Popup --version 1.0.0
NuGet\Install-Package Kebechet.Blazor.Components.Popup -Version 1.0.0
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="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kebechet.Blazor.Components.Popup --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Kebechet.Blazor.Components.Popup, 1.0.0"
#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=1.0.0 // Install Kebechet.Blazor.Components.Popup as a Cake Tool #tool nuget:?package=Kebechet.Blazor.Components.Popup&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Blazor.Components.Popup
This repo contain PopupWrapper
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.AddPopupWrapperServices();
Usage
- Ideally in
MainLayout.razor
put<PopupWrapper />
component. This component is controlled fromPopupService
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 PopupWrapperService _popupWrapperService
- Create Popup content component. E.g.
YesNoPopup.razor
that implements interfaceIPopupable<T>
with return type you need to get from the Popup. This popup content will be rendered insidePopupWrapper
.- ⚠️ I recommend to always use nullable type like
IPopupable<bool?>
because that way you can differentiate between person clickingNO
/False
and person closing the popup be clicking outside of it. - ⚠️ The child component must have
[Parameter]
at the beginning of theOnReturn
property, otherwise it won't work.
- ⚠️ I recommend to always use nullable type like
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 : IPopupable<bool?>
{
[Parameter] public EventCallback<bool?> OnReturn { get; set; }
public async Task Process(bool val)
{
await OnReturn.InvokeAsync(val);
}
}
- then in your component where you would like to render popup:
- inject
PopupWrapperService
- add functionality to trigger popup. In our case button
onClick
event - and finally use
Show
method to showYesNoPopup
and get result from it
- inject
YourComponent.razor
@inject PopupWrapperService _popupWrapperService
<button @onclick="Test">Trigger popup</button>
@code{
public async Task Test()
{
var isSuccess = await _popupWrapperService.Show(new YesNoPopup(), this);
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 🎉
Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- Microsoft.AspNetCore.Components.Web (>= 7.0.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
First release of the package