From 514b318518b7b7298c24011bc318fcf3bc05adc3 Mon Sep 17 00:00:00 2001 From: Hadi Ahmadi Date: Wed, 13 Dec 2023 15:27:43 +0430 Subject: [PATCH] #321 Use resources for Icon --- .../Components/Core/Icon.razor | 70 ++----- .../Previews/Pages/Components.razor | 26 +-- src/FluentCMS.Web.UI/Program.cs | 10 + .../Resources/IconDefinition.cs | 22 ++ src/FluentCMS.Web.UI/Resources/Icons.cs | 6 + src/FluentCMS.Web.UI/Resources/Icons.resx | 189 ++++++++++++++++++ src/FluentCMS.Web.UI/_Imports.razor | 2 + 7 files changed, 256 insertions(+), 69 deletions(-) create mode 100644 src/FluentCMS.Web.UI/Resources/IconDefinition.cs create mode 100644 src/FluentCMS.Web.UI/Resources/Icons.cs create mode 100644 src/FluentCMS.Web.UI/Resources/Icons.resx diff --git a/src/FluentCMS.Web.UI/Components/Core/Icon.razor b/src/FluentCMS.Web.UI/Components/Core/Icon.razor index 6be0a85ab..183c3f090 100644 --- a/src/FluentCMS.Web.UI/Components/Core/Icon.razor +++ b/src/FluentCMS.Web.UI/Components/Core/Icon.razor @@ -1,66 +1,18 @@ @inherits BaseComponent +@using System.Resources; - @switch (Name) - { - case IconNameEnum.Plus: - - break; - case IconNameEnum.Delete: - - break; - case IconNameEnum.InformationFilled: - - break; - case IconNameEnum.Settings: - - break; - case IconNameEnum.Filter: - - break; - case IconNameEnum.Search: - - break; - case IconNameEnum.Edit: - - break; - - } + @IconContent @code { + [Inject(Key = "FluentCMS.Web.UI.Resources.Icons")] + public required ResourceManager ResourceManager { get; set; } + [Parameter] - public IconNameEnum Name { get; set; } = IconNameEnum.Default; + public IconDefinition Name { get; set; } = IconDefinition.Default; + + public MarkupString IconContent { get; set; } = default!; [Parameter] [CssProperty] @@ -69,4 +21,10 @@ [Parameter] [CssProperty] public SizeEnum Size { get; set; } = SizeEnum.Default; + + protected override void OnInitialized() + { + base.OnInitialized(); + IconContent = (MarkupString)(ResourceManager.GetString(Name.IconName) ?? throw new Exception("Invalid Icon Name")); + } } \ No newline at end of file diff --git a/src/FluentCMS.Web.UI/Previews/Pages/Components.razor b/src/FluentCMS.Web.UI/Previews/Pages/Components.razor index a29138c83..367fbf9b7 100644 --- a/src/FluentCMS.Web.UI/Previews/Pages/Components.razor +++ b/src/FluentCMS.Web.UI/Previews/Pages/Components.razor @@ -28,48 +28,48 @@

Icons

- - - + + +

- Default + Default

- Small + Small
- Medium + Medium
- Large + Large

- Primary + Primary

- Secondary + Secondary

- Success + Success

- Danger + Danger

- Info + Info

- Warning + Warning

diff --git a/src/FluentCMS.Web.UI/Program.cs b/src/FluentCMS.Web.UI/Program.cs index 5b41be74f..f71751688 100644 --- a/src/FluentCMS.Web.UI/Program.cs +++ b/src/FluentCMS.Web.UI/Program.cs @@ -2,6 +2,8 @@ using FluentCMS.Api; using FluentCMS.Entities; using FluentCMS.Web.UI; +using FluentCMS.Web.UI.Resources; +using System.Resources; var builder = WebApplication.CreateBuilder(args); @@ -40,6 +42,14 @@ services.AddJwtAuthentication(builder.Configuration); +// register IconResourceManager +services.AddKeyedScoped(typeof(Icons).FullName, (_, _) => +{ + var iconsType = typeof(Icons); + return new ResourceManager(iconsType.FullName!, iconsType.Assembly); +}); + + var app = builder.Build(); if (app.Environment.IsDevelopment()) diff --git a/src/FluentCMS.Web.UI/Resources/IconDefinition.cs b/src/FluentCMS.Web.UI/Resources/IconDefinition.cs new file mode 100644 index 000000000..c7aceb8e7 --- /dev/null +++ b/src/FluentCMS.Web.UI/Resources/IconDefinition.cs @@ -0,0 +1,22 @@ +namespace FluentCMS.Web.UI.Resources; + +// Enum Class for Icons +public class IconDefinition +{ + // home icon + public static readonly IconDefinition Default = new("Default"); + public static readonly IconDefinition Home = new("Home"); + public static readonly IconDefinition Delete = new("Delete"); + public static readonly IconDefinition Plus = new("Plus"); + public static readonly IconDefinition Search = new("Search"); + public static readonly IconDefinition Settings = new("Settings"); + public static readonly IconDefinition Filter = new("Filter"); + public static readonly IconDefinition InformationFilled = new("InformationFilled"); + + private IconDefinition(string iconName) + { + IconName = iconName; + } + + public string IconName { get; } +} \ No newline at end of file diff --git a/src/FluentCMS.Web.UI/Resources/Icons.cs b/src/FluentCMS.Web.UI/Resources/Icons.cs new file mode 100644 index 000000000..5df828f23 --- /dev/null +++ b/src/FluentCMS.Web.UI/Resources/Icons.cs @@ -0,0 +1,6 @@ +namespace FluentCMS.Web.UI.Resources; + +// marker class for Icons.resx +public class Icons +{ +} \ No newline at end of file diff --git a/src/FluentCMS.Web.UI/Resources/Icons.resx b/src/FluentCMS.Web.UI/Resources/Icons.resx new file mode 100644 index 000000000..dc8470485 --- /dev/null +++ b/src/FluentCMS.Web.UI/Resources/Icons.resx @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + + + <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 18 20"> + <path + d="M17 4h-4V2a2 2 0 0 0-2-2H7a2 2 0 0 0-2 2v2H1a1 1 0 0 0 0 2h1v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V6h1a1 1 0 1 0 + 0-2ZM7 2h4v2H7V2Zm1 14a1 1 0 1 1-2 0V8a1 1 0 0 1 2 0v8Zm4 0a1 1 0 0 1-2 0V8a1 1 0 0 1 2 0v8Z" /> + </svg> + + + <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 20 20" fill="currentColor"> + <path fill-rule="evenodd" + d="M3 3a1 1 0 011-1h12a1 1 0 011 1v3a1 1 0 01-.293.707L12 11.414V15a1 1 0 01-.293.707l-2 2A1 1 0 018 17v-5.586L3.293 + 6.707A1 1 0 013 6V3z" + clip-rule="evenodd"></path> + </svg> + + + <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> + <path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25" /> +</svg> + + + <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20"> + <path + d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 + 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"> + </path> + </svg> + + + <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" + viewBox="0 0 18 18"> + <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" + d="M9 1v16M1 9h16" /> + </svg> + + + <svg aria-hidden="true" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> + <path fill-rule="evenodd" clip-rule="evenodd" + d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 + 8z"> + </path> + </svg> + + + <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="mr-2 w-4 h-4" + aria-hidden="true"> + <path fill-rule="evenodd" clip-rule="evenodd" + d="M11.828 2.25c-.916 0-1.699.663-1.85 1.567l-.091.549a.798.798 0 01-.517.608 7.45 7.45 0 00-.478.198.798.798 0 + 01-.796-.064l-.453-.324a1.875 1.875 0 00-2.416.2l-.243.243a1.875 1.875 0 00-.2 2.416l.324.453a.798.798 0 01.064.796 + 7.448 7.448 0 00-.198.478.798.798 0 01-.608.517l-.55.092a1.875 1.875 0 00-1.566 1.849v.344c0 .916.663 1.699 1.567 + 1.85l.549.091c.281.047.508.25.608.517.06.162.127.321.198.478a.798.798 0 01-.064.796l-.324.453a1.875 1.875 0 00.2 + 2.416l.243.243c.648.648 1.67.733 2.416.2l.453-.324a.798.798 0 + 01.796-.064c.157.071.316.137.478.198.267.1.47.327.517.608l.092.55c.15.903.932 1.566 1.849 1.566h.344c.916 0 + 1.699-.663 1.85-1.567l.091-.549a.798.798 0 01.517-.608 7.52 7.52 0 00.478-.198.798.798 0 01.796.064l.453.324a1.875 + 1.875 0 002.416-.2l.243-.243c.648-.648.733-1.67.2-2.416l-.324-.453a.798.798 0 + 01-.064-.796c.071-.157.137-.316.198-.478.1-.267.327-.47.608-.517l.55-.091a1.875 1.875 0 + 001.566-1.85v-.344c0-.916-.663-1.699-1.567-1.85l-.549-.091a.798.798 0 01-.608-.517 7.507 7.507 0 + 00-.198-.478.798.798 0 01.064-.796l.324-.453a1.875 1.875 0 00-.2-2.416l-.243-.243a1.875 1.875 0 + 00-2.416-.2l-.453.324a.798.798 0 01-.796.064 7.462 7.462 0 00-.478-.198.798.798 0 01-.517-.608l-.091-.55a1.875 1.875 + 0 00-1.85-1.566h-.344zM12 15.75a3.75 3.75 0 100-7.5 3.75 3.75 0 000 7.5z"> + </path> + </svg> + + + Spinner + + \ No newline at end of file diff --git a/src/FluentCMS.Web.UI/_Imports.razor b/src/FluentCMS.Web.UI/_Imports.razor index c5a80b376..33a03cc73 100644 --- a/src/FluentCMS.Web.UI/_Imports.razor +++ b/src/FluentCMS.Web.UI/_Imports.razor @@ -14,4 +14,6 @@ @using FluentCMS.Web.UI.Layouts @using FluentCMS.Web.UI.Components.Core @using FluentCMS.Web.UI.Components.Core.Form +@using FluentCMS.Web.UI.Resources + @using static Microsoft.AspNetCore.Components.Web.RenderMode