Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FluentIcon] Add IconSize.Custom value #1342

Merged
merged 5 commits into from
Jan 17, 2024
Merged

Conversation

dvoituron
Copy link
Collaborator

[FluentIcon] Add IconSize.Custom value

You can create your own icons by adding a class like this one:

public static class MyIcons
{
    public class SettingsEmail : Icon { public SettingsEmail() : base("SettingsEmail", IconVariant.Regular, IconSize.Size20, "<svg width=\"20\" height=\"19\" viewBox=\"0 0 20 19\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M15.6251 2.5H4.37508L4.2214 2.50428C2.79712 2.58396 1.66675 3.76414 1.66675 5.20833V13.125L1.67103 13.2787C1.75071 14.7029 2.93089 15.8333 4.37508 15.8333H9.76425C9.91725 15.4818 10.1354 15.1606 10.4087 14.8873L10.7126 14.5833H4.37508L4.25547 14.5785C3.50601 14.5177 2.91675 13.8902 2.91675 13.125V6.97833L9.709 10.5531L9.78908 10.5883C9.95267 10.647 10.135 10.6353 10.2912 10.5531L17.0834 6.9775V9.17258C17.5072 9.14483 17.9362 9.21517 18.3334 9.38358V5.20833L18.3292 5.05465C18.2494 3.63038 17.0693 2.5 15.6251 2.5ZM4.37508 3.75H15.6251L15.7447 3.75483C16.4942 3.81568 17.0834 4.44319 17.0834 5.20833V5.565L10.0001 9.29375L2.91675 5.56583V5.20833L2.92158 5.08873C2.98242 4.33926 3.60994 3.75 4.37508 3.75ZM15.9167 10.5579L10.9979 15.4766C10.7112 15.7633 10.5077 16.1227 10.4093 16.5162L10.0279 18.0418C9.86208 18.7052 10.4631 19.3062 11.1265 19.1403L12.6521 18.7588C13.0455 18.6605 13.4048 18.4571 13.6917 18.1703L18.6103 13.2516C19.3542 12.5078 19.3542 11.3018 18.6103 10.5579C17.8665 9.814 16.6605 9.814 15.9167 10.5579Z\" fill=\"#212121\" /></svg>") { } }
} 

NEW - Using a Custom size
If the size of your customized icon (Viewbox) is not one of the standard IconSize sizes, you can use a IconSize.Custom size.
<FluentIcon Value="@(new MyCircle())" Width="16px" />
<FluentIcon Value="@(new MyCircle().WithColor("red"))" Width="16px" />

public class MyCircle : Microsoft.FluentUI.AspNetCore.Components.Icon
{
    private const string SVG_CONTENT = "<svg version='1.1' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 320'><circle cx='160' cy='160' r='140'/></svg>";

    public MyCircle() : base("MyCircle", IconVariant.Regular, IconSize.Custom, SVG_CONTENT)
    {
        // Default Color (`fill` style)
        WithColor("#F97316");
    }
}

Unit Tests

Unit tests are updated

Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://black-pebble-0dc79cb03-1342.westeurope.3.azurestaticapps.net

@vnbaaij vnbaaij enabled auto-merge (squash) January 17, 2024 13:46
Comment on lines +74 to +94
If the size of your customized icon (Viewbox) is not one of the standard IconSize sizes,
you can use a <b>IconSize.Custom</b> size.
<br />
<ul>
<li>
<FluentIcon Value="@(new MyCircle())" Width="16px" />
<code>&lt;FluentIcon Value="@@(new MyCircle())" Width="16px" /></code>
</li>
<li>
<FluentIcon Value="@(new MyCircle().WithColor("red"))" Width="16px" />
<code>&lt;FluentIcon Value="@@(new MyCircle().WithColor("red"))" Width="16px" /></code>
</li>
<li>
@(new MyCircle().ToMarkup("16px", "blue"))
<code>@@new MyCircle().ToMarkup("16px", "blue")</code>
</li>
<li>
<FluentButton IconStart="@(new MyCircle())" Loading="@ButtonIsLoading" OnClick="@(e => ButtonIsLoading = !ButtonIsLoading)">Refresh</FluentButton>
<code>&lt;FluentButton IconStart="@@(new MyCircle())">Refresh&lt;/FluentButton></code>
</li>
</ul>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you showing IconSize.Custom being used here because of using the Width parameter?

@vnbaaij vnbaaij merged commit 5a48182 into dev Jan 17, 2024
4 checks passed
@vnbaaij vnbaaij deleted the users/dvoituron/icon-custom-size branch January 17, 2024 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants