Source generator for generating Avalonia UI icon sets from codepoint files.
$ dotnet add package IconSource.AvaloniaSource generator for generating icon sets from codepoint files. Currently supporting Blazor (and AvaloniaUI) in .NET 8.
IconSource.Blazor to the projectAdditionalFiles into the projectIconSource with an icon set name, codepoint file name, and css class to useIcon type with the property Name where the icon can be setExample 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>