Blazor.Avatar 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Blazor.Avatar --version 1.0.4
NuGet\Install-Package Blazor.Avatar -Version 1.0.4
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="Blazor.Avatar" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Blazor.Avatar --version 1.0.4
#r "nuget: Blazor.Avatar, 1.0.4"
#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 Blazor.Avatar as a Cake Addin
#addin nuget:?package=Blazor.Avatar&version=1.0.4

// Install Blazor.Avatar as a Cake Tool
#tool nuget:?package=Blazor.Avatar&version=1.0.4

Blazor Avatar

This Blazor library provides components that render avatar. Currently this library only supports initial avatar.

This library has been tested only with Blazor WebAssembly.

Install

Install package from Nuget.

dotnet add package Blazor.Avatar --version <latest-version>

Register Blazor.Avatar dependencies by calling AddAvatarComponents() in Program.cs.

using Blazor.Avatar;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services
  .AddAvatarComponents()
  .AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

await builder.Build().RunAsync();

Load the dotnet-callback.js script by adding the line below in your wwwroot/index.html file.

<script type="module" src="_content/Blazor.Avatar/js/dotnet-callback.js"></script>

The reason this script is needed because some components can accept C# callback (like Func<> or Action<>), and this script helps serialize these callbacks to JS callbacks.

Usage

You can clone this repo and run the samples/Blazor.Avatar.Samples.WebAssembly project to see how the avatars are generated.

Alternatively you can view the sample project hosted on Github page.

Initial Avatar

Use the InitialAvatar component in your Razor file.

@page "/"
@using Blazor.Avatar.Components.InitialAvatarComponent

<p>Render initial avatar with random color.</p>
<InitialAvatar FirstName="Aaron"
               LastName="Doe" />

<p>Render initial avatar with specify color and size.</p>
<InitialAvatar FirstName="Jane"
               LastName="Smith"
               FillColor="green"
               Size=100 />

<p>
  Render initial avatar with specify style. Note that
  specifying <b>Style="border-radius: 50%; width: 80px; height: 60px"</b>
  will override the <b>Size</b> parameter.
</p>
<InitialAvatar FirstName="gavin"
               LastName="baker"
               Size=150
               Style="border-radius: 50%" />

The above Razor code will be rendered like this: img

Identicon Avatar

This is pretty much a wrapper of this JS library: https://github.com/laurentpayot/minidenticons. This library is currently using version 4.2.1 of this JS minidenticons library.

<PageTitle>Identicon Avatar</PageTitle>

<h1>Identicon Avatar</h1>

<IdenticonAvatar Username="x" 
                 Saturation=58
                 Lightness=22
                 Style="background-color: green; display: list-item; height: 148px; width: 148px;" />

<IdenticonAvatar Username="feeding bird in forest"
                 Saturation=58
                 Lightness=9
                 HashFunc="@(s => 1234)"
                 Style="background-color: grey; height: 300px; width: 300px;" />

DiceBear Avatar

This is a wrapper for DiceBear avatar.

The complete list of available styles are documented in here.

The official DiceBear playground is here.

<DiceBearAvatar AvatarStyle="thumbs" DefaultSeed="john" />

<DiceBearAvatar AvatarStyle="bigSmile" Options="@(new Dictionary<string, object> { { "seed", "jane" }, { "flip", true } })" />
Product 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. 
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
1.0.6 93 4/19/2024
1.0.5 86 4/16/2024
1.0.4 110 3/30/2024
1.0.3 97 3/29/2024
1.0.2 98 3/25/2024
1.0.1 97 3/24/2024
1.0.0 99 3/24/2024