-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tag helper to render empty content as a hyphen
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...ngRecordSystem/src/TeachingRecordSystem.SupportUi/TagHelpers/UseEmptyFallbackTagHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Text.Encodings.Web; | ||
using Microsoft.AspNetCore.Mvc.TagHelpers; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
|
||
namespace TeachingRecordSystem.SupportUi.TagHelpers; | ||
|
||
[HtmlTargetElement("*", Attributes = "use-empty-fallback")] | ||
public class UseEmptyFallbackTagHelper : TagHelper | ||
{ | ||
public override int Order => -1; | ||
|
||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
var content = await output.GetChildContentAsync(); | ||
output.Attributes.RemoveAll("use-empty-fallback"); | ||
|
||
if (content.IsEmptyOrWhiteSpace) | ||
{ | ||
output.AddClass("trs-subtle-emphasis", HtmlEncoder.Default); | ||
output.Content.SetContent("-"); | ||
} | ||
} | ||
} |