Take control over what Icons and Emojis are available and get deployed on publishing! #300
Replies: 2 comments 12 replies
-
An aspect of the configuration that could be improved would be to easily identify duplicate entries. Hashsets or flaggable enums could be used instead of arrays, it'd probably make the comparison at publish time faster as well. builder.Services.AddFluentUIComponents(configuration =>
{
configuration!.IconConfiguration.Variants =
IconVariant.Regular |
IconVariant.Filled;
}); Also as far as I understand this are projection rules, meaning that if I specify IconConfiguration Regular & Filled as well as Sie 12 & 14 I'll get 4 variants at least of each icon group that gets imported. Having a matching rule engine instead with lambdas would help trim it down further. builder.Services.AddFluentUIComponents(configuration =>
{
configuration!.IconsMatchingRules.Add((size, group, variant, style) => size == IconSize.Size10 && style == EmojiStyle.Color && variant == IconVariant.Regular && group == EmojiGroup.Activities):
}); Although I'm not sure how that would translate in csproj, maybe it's a capability that can only be used in CSharp? |
Beta Was this translation helpful? Give feedback.
-
UpdateI've made available a 2.1 RC1 package with some changes on how this works. In short, you still to need to add settings to the project file of the project you are using the library in, and you need to change the Longer explanationMost important change: 2 new properties have been added:
As you can probably guess from their names, these enable completely turning off or on publishing icons and/or emoji assets. The default value for BOTH properties is The other properties are still there but the values for the options have changed a bit. The mechanism of specifying sizes/variant and groups/styles has not changed. Only thing is the values now need to be separated by commas (','). Any additional leading/trailing spaces will be trimmed when processing the values. The possible (updated) values per element are:
If publishing icons/emoji is enabled and a property is not given a value/left out of the project file, ALL possible options for that value will be used. For the current demo site the elements look like this:
This translates to 'all icons EXCEPT size 32' and 'all color emoji EXCEPT People & Body group' will be published as static assets (i.e. copied to the Configuring the
|
Beta Was this translation helpful? Give feedback.
-
Introduction
For version 2.1 I'm adding a new
<FluentEmoji>
component to the family (see https://brave-cliff-0c0c93310-259.centralus.azurestaticapps.net/Emoji for examples)! Good news I think, but...it also introduces a new challenge.The Fluent Emoji are a (still growing) collection of familiar, friendly, and modern emoji from Microsoft. At the moment there are over 1500 distinct emoji available in color, flat and high contrast styles and 6 different skin tones (where applicable) divided in 9 groups. At the moment, the collections consist of just over 7.5k emoji in SVG format in total.
Combined with the ~13k Fluent System Icons that are already available through the
<FluentIcon>
component, this means a significant number of static assets get pushed to a server when publishing an application that uses the library. In fact, with Azure Static Web Apps (which we are using for hosting the demo site) I'm not able to publish everything as there currently exists a maximum of 15000 files per application.I therefore needed a way to limit the number of static assets that gets included in a publish action and I'm happy to report I've found a way to do that! As an added bonus you, as the developer using the library in an application, can now control what icons and emojis (yes, emojis is valid for indicating plural) will be available to the application. I'll do a blog pot on how I made it work on the project and package side later. For now, I want to focus on how you can configure things.
Options to filter Icons and Emojis
The icon collection is set up such a way that an icon is made available in different sizes and then for each size there are usually 2 variants ('Filled', 'Regular'). The sizes available are '10', '12', '16', '20', '24', '28', '32', and '48'. Not every icon is available in all sizes and/or all variants.
The emoji collection is, like mentioned above, divided into 9 groups where each emoji is made available in 3 styles ('Color', 'Flat', 'High Contrast'). The groups available are 'Activities', 'Animals & Nature', 'Flags', "Food & Drink', 'Objects', 'People & Body', 'Smileys & Emotion', 'Symbols' and 'Travel & Places'. I think every emoji is available in every style but not 100% sure. For a lot of emoji in the 'People & Body' category there are also 6 different skin tone variants available per style
Due to the way the project file needs to be altered to make this mechanism work, the number of filters you can use is limited. For icons this means you can specify a combination of sizes and variants. For emoji you can specify a combination of groups and styles.
Configuring the application project
You can specify which combination to use by defining
<PropertyGroup>
elements in the.csproj
file for the application you are using the library in. The elements you can use for icons are:<FluentIconSizes>
<FluentIconVariants>
For emoji you can use:
<FluentEmojiGroups>
<FluentEmojiStyles>
In each element you specify one or more values (no spaces, separated by semicolon (;)). The combination of the
<FluentIcon...>
elements determines the icon assets published, the<FluentEmoji...>
elements combination determines the emoji assets published.The possible values per element are:
<FluentIconSizes>
: 10;12;16;20;24;28;32;48<FluentIconVariants>
: filled;regular<FluentEmojiGroups>
: activities;animals_nature;flags;food_drink;objects;people_body;smileys_emotion;symbols;travel_places<FluentEmojiStyles>
: color;flat;high-contrastFor the current demo site the elements look like this:
This translates to 'all color emoji EXCEPT People & Body group' and 'all icons EXCEPT size 32' will be published as static assets.
If you don't specify an element in the project file, by default all possible options for that element will be included in the publish action
Configuring the
AddFluentUIComponents
service collection extensionTo get runtime checks on
<FluentIcon>
and<FluentEmoji>
using actual available assets, you need to configure theAddFluentUIComponents
service collection extension. To enable this a couple of service and configuration classed have been added to the library. In anormal situation, you'd make sure the settings for the configuration here mimic the settings made in the project file.The classes added for configuration are:
IconConfiguration
with propertiesSizes
andVariants
andEmojiConfiguration
with propertiesGroups
andStyles
. All properties are arrays of enumerations which contain all possible options for that specific element.The services added are
IconService
andEmojiService
both classes only contain a (get-only)Configuration
property of their respective configuration type. The services are added in theAddFluentUIComponents
code.You can manipulate the configuration by adding code to the
AddFluentUIComponents
call you make when configuring the SeviceCollection. Usually this is done inProgram.cs
. When using top-level statements, you should see multiplebuilder.Services...
lines in that file. In general such a manipulation looks like this:
For the demo site it looks like this:
Using this configuration, I can for example change the Search functionality in the
EmojiPage
to only show the groups (no 'People & Body') and style (just 'Color') for which the assets are actually published:See https://github.com/microsoft/fast-blazor/blob/emojis/examples/FluentUI.Demo.Shared/Pages/Emoji/EmojiPage.razor#L48-L56 (and line 72-79) in the demo site for how this is done.
When not specifying any configuration options, that same goes as with the project settings. Everything will be available.
Try it out!
To test this functionality, you need version 2.1.0-beta-1 of the package which is available on GitHub now. If you do try this out, please let us know if it works as expected (or not).
Beta Was this translation helpful? Give feedback.
All reactions