IconSource.Blazor 0.2.1

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

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

IconSource

Source generator for generating icon sets from codepoint files. Currently supporting Blazor (and AvaloniaUI) in .NET 8.

Blazor

Getting started

  • Add NuGet package IconSource.Blazor to the project
  • Add a codepoint file from a icon font as AdditionalFiles into the project
  • Add the assembly attribute IconSource with an icon set name, codepoint file name, and css class to use
  • Add css style for the icon font to your projects css
  • The source generator generates an Icon type with the property Name where the icon can be set
  • The generated icons of the codepoint file are in the class with the name of the icon set

Example

Example for usage with Google Material Symbols with a blazor application.

style.css:

@font-face {
    font-family: "Material Symbols Round";
    font-style: normal;
    font-weight: 400;
    src: url("./material-symbols-rounded.woff2") format('woff2');
}

.material-symbols {
    font-family: "Material Symbols Round";
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
}

IconSource.cs:

using IconSource;

[assembly:IconSource("MaterialIcons", "MaterialSymbols.codepoints", "material-symbols")]

MaterialSymbols.codepoints added to project:

<AdditionalFiles Include="MaterialSymbols.codepoints" />

Example usage as a ButtonWithIcon.razor component:

@using IconSource
<button @onclick="async () => await OnClick.InvokeAsync()">
    @if (Icon is {} icon)
    {
        <Icon Name="Icon" />
    }
    @if (ChildContent is {} childContent)
    {
        <span class="text">@childContent</span>
    }
</button>

@code
{
    [Parameter] public RenderFragment? ChildContent { get; set; }
    [Parameter] public IconName? Icon { get; set; }
    [Parameter] public EventCallback OnClick { get; set; }
}

Example usage of the ButtonWithIcon.razor component:

@using IconSource
<ButtonWithIcon Icon="MaterialIcons.Upload">Upload</ButtonWithIcon>
There are no supported framework assets in this 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.2.1 161 2/19/2024
0.2.0 128 2/1/2024
0.1.0 84 2/1/2024