KristofferStrube.Blazor.Popper 0.6.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package KristofferStrube.Blazor.Popper --version 0.6.0
NuGet\Install-Package KristofferStrube.Blazor.Popper -Version 0.6.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="KristofferStrube.Blazor.Popper" Version="0.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KristofferStrube.Blazor.Popper --version 0.6.0
#r "nuget: KristofferStrube.Blazor.Popper, 0.6.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 KristofferStrube.Blazor.Popper as a Cake Addin
#addin nuget:?package=KristofferStrube.Blazor.Popper&version=0.6.0

// Install KristofferStrube.Blazor.Popper as a Cake Tool
#tool nuget:?package=KristofferStrube.Blazor.Popper&version=0.6.0

License: MIT GitHub issues GitHub forks GitHub stars NuGet Downloads (official NuGet)

Introduction

A Blazor wrapper for the JavaScript library Popper.js

Demo

The sample project can be demoed at https://kristofferstrube.github.io/Blazor.Popper/

Getting Started

Prerequisites

You need to install .NET 6.0 or newer to use the library.

Download .NET 6

Installation

You can install the package via Nuget with the Package Manager in your IDE or alternatively using the command line:

dotnet add package KristofferStrube.Blazor.Popper

Usage

The package can be used in Blazor WebAssembly projects.

Assets

You first need to reference popper.js since this is only a wrapper. You can do this using your favorite JS package manager (e.g. NPM or Library Manager) or just add the following to the body of your index.html file after the point where you reference _framework/blazor.webassembly.js.

<script src="https://unpkg.com/@popperjs/core@2"></script>

Import

You also need to reference the package in order to use it in your pages. This can be done in _Import.razor by adding the following.

@using KristofferStrube.Blazor.Popper

Add to service collection

An easy way to make Popper available in all your pages is by registering it in the IServiceCollection so that it can be dependency injected in the pages that need it. This is done in Program.cs by adding the following before you build the service collection.

public static async Task Main(string[] args)
{
    var builder = WebAssemblyHostBuilder.CreateDefault(args);
    builder.RootComponents.Add<App>("#app");

    // Other services are added.

    builder.Services.AddScoped<Popper>();

    await builder.Build().RunAsync();
}

Inject in page

In any page that need a popper you can then inject Popper by adding the following to the top of the razor file.

@inject Popper Popper;

Then you can use Popper to create a popper instance between two ElementReference's like so:

<span @ref=reference>reference</span>
<span @ref=popper>popper</span>

@code {
    protected ElementReference reference;
    protected ElementReference popper;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await Popper.CreatePopperAsync(reference, popper, new());
    }
}

This repository was build on top of the work done in the following series of articles:

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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.6.0 1,257 3/5/2024
0.5.1 6,656 2/8/2023
0.5.0 710 2/8/2023
0.4.0 4,583 12/27/2021
0.3.0 1,941 8/9/2021
0.2.4 869 3/8/2021
0.2.2 873 2/10/2021
0.2.1 837 2/6/2021
0.2.0 872 1/23/2021
0.1.2 881 1/22/2021
0.1.1 883 1/22/2021
0.1.0 892 1/22/2021