diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/TagHelpers/UseEmptyFallbackTagHelper.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/TagHelpers/UseEmptyFallbackTagHelper.cs new file mode 100644 index 0000000000..a99465d55b --- /dev/null +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/TagHelpers/UseEmptyFallbackTagHelper.cs @@ -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("-"); + } + } +}