Skip to content

Commit bc204c1

Browse files
Merge pull request #47 from IowaComputerGurus/feature/form-check-support
Added support for Alerts Headers #44
2 parents 94df143 + 9652175 commit bc204c1

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,29 @@
7373
</code>
7474
</td>
7575
</tr>
76-
<tr>
77-
<th>Warning Dismissible</th>
78-
<td>
79-
<alert alert-color="Warning" dismissible="true">
80-
This is a dismissible warning alert!
81-
</alert>
82-
</td>
83-
<td>
84-
<code>
85-
&lt;alert alert-color=&quot;Warning&quot; dismissible=&quot;false&quot;&gt;
86-
This is a dismissible warning alert!
87-
&lt;/alert&gt;
88-
</code>
89-
</td>
90-
</tr>
76+
<tr>
77+
<th>Warning Dismissible</th>
78+
<td>
79+
<alert alert-color="Warning" dismissible="true">
80+
This is a dismissible warning alert!
81+
</alert>
82+
</td>
83+
<td>
84+
<code>
85+
&lt;alert alert-color=&quot;Warning&quot; dismissible=&quot;false&quot;&gt;
86+
This is a dismissible warning alert!
87+
&lt;/alert&gt;
88+
</code>
89+
</td>
90+
</tr>
91+
<tr>
92+
<th>Alert With Header</th>
93+
<td>
94+
<alert alert-color="Info" heading-text="This is a Header">
95+
Look at me! I have a header!
96+
</alert>
97+
</td>
98+
</tr>
9199
</tbody>
92100
</table>
93101

src/AspNetCore.Utilities.Bootstrap5TagHelpers/AlertTagHelper.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public class AlertTagHelper : TagHelper
2626
/// </summary>
2727
public bool Dismissible { get; set; } = false;
2828

29+
/// <summary>
30+
/// If supplied this will render as a heading inside the alert.
31+
/// </summary>
32+
public string? HeadingText { get; set; }
33+
2934
/// <summary>
3035
/// Processes the tag helper
3136
/// </summary>
@@ -50,10 +55,21 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
5055
output.AddClass("fade", HtmlEncoder.Default);
5156
output.AddClass("show", HtmlEncoder.Default);
5257
}
58+
5359
output.Attributes.Add("role", "alert");
5460

61+
if (!string.IsNullOrEmpty(HeadingText))
62+
{
63+
var headingBuilder = new TagBuilder("h4");
64+
headingBuilder.AddCssClass("alert-heading");
65+
headingBuilder.InnerHtml.Append(HeadingText);
66+
output.PreContent.AppendHtml(headingBuilder);
67+
}
68+
5569
if (!Dismissible)
70+
{
5671
return;
72+
}
5773

5874
var buttonBuilder = new TagBuilder("button");
5975
buttonBuilder.Attributes.Add("type", "button");
@@ -62,7 +78,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
6278
buttonBuilder.Attributes.Add("aria-label", "Close");
6379

6480
//Get existing content
65-
var existing = await output.GetChildContentAsync();
81+
TagHelperContent existing = await output.GetChildContentAsync();
6682
output.Content.AppendHtml(existing.GetContent());
6783
output.Content.AppendHtml(buttonBuilder);
6884
}

0 commit comments

Comments
 (0)