Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Lombiq.HelpfulExtensions/Extensions/SimpleIcons/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Simple Icons

Adds [Simple Icons](https://simpleicons.org/) icon library integration. All icons are directly available in the _~/Lombiq.HelpfulExtensions/vendors/simple-icons/icons/*.svg_ location.

## Shape and Tag Helper

You can display the icon in a more structured manner using the `SimpleIcon` shape or the `<simple-icon>` Razor tag helper. Use the tag helper from .cshtml files and the shape from Liquid.

```liquid
{% shape "SimpleIcon", Source: 'youtube', IconClasses: 'h-5 w-5 shrink-0', label-classes: 'font-semibold tracking-wide', Size: 24, Title: 'YouTube', ShowLabel: true %}
```

```cshtml
<simple-icon source="youtube"
icon-classes="h-5 w-5 shrink-0"
label-classes="font-semibold tracking-wide"
title="YouTube"
show-label="true"
size="24"></simple-icon>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Lombiq.HelpfulLibraries.OrchardCore.TagHelpers;
using Microsoft.AspNetCore.Razor.TagHelpers;
using OrchardCore.DisplayManagement;
using System.Threading.Tasks;

namespace Lombiq.HelpfulExtensions.Extensions.SimpleIcons;

[HtmlTargetElement("simple-icon")]
public class SimpleIconTagHelper : ShapeTagHelperBase<SimpleIconViewModel>
{
[HtmlAttributeName("source")]
public string Source { get; set; }

[HtmlAttributeName("icon-classes")]
public string IconClasses { get; set; }

[HtmlAttributeName("label-classes")]
public string LabelClasses { get; set; }

[HtmlAttributeName("size")]
public int Size { get; set; }

[HtmlAttributeName("title")]
public string Title { get; set; }

[HtmlAttributeName("show-label")]
public bool ShowLabel { get; set; }

public SimpleIconTagHelper(IDisplayHelper displayHelper, IShapeFactory shapeFactory)
: base(displayHelper, shapeFactory)
{
}

protected override string ShapeType => SimpleIconViewModel.ShapeType;

protected override ValueTask<SimpleIconViewModel> GetViewModelAsync(TagHelperContext context, TagHelperOutput output) =>
ValueTask.FromResult(new SimpleIconViewModel(this));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#nullable enable

using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Views;
using System.Collections.Generic;

namespace Lombiq.HelpfulExtensions.Extensions.SimpleIcons;

public class SimpleIconViewModel : ShapeViewModel
{
public const string ShapeType = "SimpleIcon";

public string? Source { get; set; }
public string? IconClasses { get; set; }
public string? LabelClasses { get; set; }
public int Size { get; set; } = 24;
public string? Title { get; set; }
public bool ShowLabel { get; set; }

public SimpleIconViewModel() => Metadata.Type = ShapeType;

public SimpleIconViewModel(SimpleIconTagHelper helper)
: this()
{
Source = helper.Source;
IconClasses = helper.IconClasses;
LabelClasses = helper.LabelClasses;
Size = helper.Size;
Title = helper.Title;
ShowLabel = helper.ShowLabel;
}

public static SimpleIconViewModel FromShape(IShape shape)
{
if (shape.Properties.GetMaybe("ViewModel") is SimpleIconViewModel shapeViewModel)
{
return shapeViewModel;
}

return new SimpleIconViewModel
{
Source = shape.Properties.GetMaybe(nameof(Source))?.ToString(),
IconClasses = shape.Properties.GetMaybe(nameof(IconClasses))?.ToString(),
LabelClasses = shape.Properties.GetMaybe(nameof(LabelClasses))?.ToString(),
Size = shape.Properties.GetMaybe(nameof(Size)) is int sizeInt ? sizeInt : 24,
Title = shape.Properties.GetMaybe(nameof(Title))?.ToString(),
ShowLabel = shape.Properties.GetMaybe(nameof(ShowLabel)) is true or "true",
};
}
}
11 changes: 11 additions & 0 deletions Lombiq.HelpfulExtensions/Extensions/SimpleIcons/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Modules;

namespace Lombiq.HelpfulExtensions.Extensions.SimpleIcons;

[Feature(FeatureIds.SimpleIcons)]
public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services) =>
services.AddTagHelpers<SimpleIconTagHelper>();
}
1 change: 1 addition & 0 deletions Lombiq.HelpfulExtensions/FeatureIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static class FeatureIds
public const string Security = FeatureIdPrefix + nameof(Security);
public const string ShapeTracing = FeatureIdPrefix + nameof(ShapeTracing);
public const string Shortcodes = FeatureIdPrefix + nameof(Shortcodes);
public const string SimpleIcons = FeatureIdPrefix + nameof(SimpleIcons);
public const string SiteTexts = FeatureIdPrefix + nameof(SiteTexts);
public const string TargetBlank = FeatureIdPrefix + nameof(TargetBlank);
public const string Trumbowyg = FeatureIdPrefix + nameof(Trumbowyg);
Expand Down
11 changes: 11 additions & 0 deletions Lombiq.HelpfulExtensions/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,14 @@
"OrchardCore.Resources",
]
)]

[assembly: Feature(
Id = SimpleIcons,
Name = "Lombiq Helpful Extensions - Simple Icons",
Category = "Content",
Description = "Adds the Simple Icons icon library as a resource and the <simple-icon> tag helper.",
Dependencies =
[
"OrchardCore.DisplayManagement",
]
)]
22 changes: 22 additions & 0 deletions Lombiq.HelpfulExtensions/Views/SimpleIcon.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@model OrchardCore.DisplayManagement.IShape

@using Lombiq.HelpfulExtensions.Extensions.SimpleIcons

@{
var viewModel = SimpleIconViewModel.FromShape(Model);
if (string.IsNullOrEmpty(viewModel.Source))
{
return;
}

var source = viewModel.Source.EndsWith(".svg")
? viewModel.Source
: Href($"~/Lombiq.HelpfulExtensions/vendors/simple-icons/icons/{viewModel.Source}.svg");
}

<img class="@viewModel.IconClasses" src="@source" alt="@viewModel.Title" title="@viewModel.Title" />

@if (viewModel.ShowLabel)
{
<span class="@viewModel.LabelClasses">@viewModel.Title</span>
}
20 changes: 16 additions & 4 deletions Lombiq.HelpfulExtensions/libman.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@
},
{
"library": "trumbowyg@2.31.0",
"files": [ "dist/**/*", "plugins/**/*" ]
"files": [
"dist/**/*",
"plugins/**/*"
]
},
{
"library": "lucide@1.14.0",
"files": [ "dist/umd/lucide.js", "dist/umd/lucide.min.js" ]
"library": "lucide@1.14.0",
"files": [
"dist/umd/lucide.js",
"dist/umd/lucide.min.js"
]
},
{
"library": "simple-icons@16.19.0",
"files": [
"icons/*.svg"
]
}
]
}
}
Loading