-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from IowaComputerGurus/features/new-stuff
Added support for Spinenrs
- Loading branch information
Showing
17 changed files
with
164 additions
and
6 deletions.
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Spinner/SpinnerTagHelperTests.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,59 @@ | ||
using ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Spinner; | ||
using Xunit.Abstractions; | ||
|
||
namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Tests.Spinner; | ||
|
||
[UsesVerify] | ||
public class SpinnerTagHelperTests(ITestOutputHelper output) : LoggingTagHelperTest(output) | ||
{ | ||
[Fact] | ||
public async Task Should_Render_BorderSpinner_Default() | ||
{ | ||
var output = await (new SpinnerTagHelper()).Render(); | ||
output.AssertContainsClass("spinner-border"); | ||
await VerifyTagHelper(output); | ||
} | ||
|
||
[Theory] | ||
[InlineData(SpinnerMode.Border, "spinner-border")] | ||
[InlineData(SpinnerMode.Grow, "spinner-grow")] | ||
public async Task Properly_Sets_Class_For_Spinner(SpinnerMode mode, string expected) | ||
{ | ||
var output = await (new SpinnerTagHelper() { SpinnerMode = mode }).Render(); | ||
output.AssertContainsClass(expected); | ||
await VerifyTagHelper(output).UseParameters(mode); | ||
} | ||
|
||
[Theory] | ||
[InlineData(SpinnerMode.Border, "spinner-border-sm")] | ||
[InlineData(SpinnerMode.Grow, "spinner-grow-sm")] | ||
public async Task Properly_Sets_Class_For_Spinner_Small(SpinnerMode mode, string expected) | ||
{ | ||
var output = await (new SpinnerTagHelper() { SpinnerMode = mode, IsSmall = true}).Render(); | ||
output.AssertContainsClass(expected); | ||
await VerifyTagHelper(output).UseParameters(mode); | ||
} | ||
|
||
[Theory] | ||
[InlineData(BootstrapColor.Info, "text-info")] | ||
[InlineData(BootstrapColor.Success, "text-success")] | ||
[InlineData(BootstrapColor.Danger, "text-danger")] | ||
[InlineData(BootstrapColor.Warning, "text-warning")] | ||
[InlineData(BootstrapColor.Primary, "text-primary")] | ||
[InlineData(BootstrapColor.Secondary, "text-secondary")] | ||
[InlineData(BootstrapColor.Light, "text-light")] | ||
[InlineData(BootstrapColor.Dark, "text-dark")] | ||
public async Task Properly_Sets_Class_For_TextColor(BootstrapColor color, string expected) | ||
{ | ||
var output = await (new SpinnerTagHelper() { Color = color}).Render(); | ||
output.AssertContainsClass(expected); | ||
await VerifyTagHelper(output).UseParameters(color); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Render_Aria_Hidden_WhenSet() | ||
{ | ||
var output = await (new SpinnerTagHelper() { AriaHidden = true }).Render(); | ||
await VerifyTagHelper(output); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...ots/SpinnerTagHelperTests.Properly_Sets_Class_For_Spinner_Small_mode=Border.verified.html
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,2 @@ | ||
| ||
<div class="spinner-border spinner-border-sm"></div> |
2 changes: 2 additions & 0 deletions
2
...shots/SpinnerTagHelperTests.Properly_Sets_Class_For_Spinner_Small_mode=Grow.verified.html
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,2 @@ | ||
| ||
<div class="spinner-grow spinner-grow-sm"></div> |
2 changes: 2 additions & 0 deletions
2
...Snapshots/SpinnerTagHelperTests.Properly_Sets_Class_For_Spinner_mode=Border.verified.html
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,2 @@ | ||
| ||
<div class="HtmlEncode[[spinner-border]]"></div> |
2 changes: 2 additions & 0 deletions
2
...fySnapshots/SpinnerTagHelperTests.Properly_Sets_Class_For_Spinner_mode=Grow.verified.html
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,2 @@ | ||
| ||
<div class="HtmlEncode[[spinner-grow]]"></div> |
2 changes: 2 additions & 0 deletions
2
...pshots/SpinnerTagHelperTests.Properly_Sets_Class_For_TextColor_color=Danger.verified.html
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,2 @@ | ||
| ||
<div class="spinner-border text-danger"></div> |
2 changes: 2 additions & 0 deletions
2
...napshots/SpinnerTagHelperTests.Properly_Sets_Class_For_TextColor_color=Dark.verified.html
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,2 @@ | ||
| ||
<div class="spinner-border text-dark"></div> |
2 changes: 2 additions & 0 deletions
2
...napshots/SpinnerTagHelperTests.Properly_Sets_Class_For_TextColor_color=Info.verified.html
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,2 @@ | ||
| ||
<div class="spinner-border text-info"></div> |
2 changes: 2 additions & 0 deletions
2
...apshots/SpinnerTagHelperTests.Properly_Sets_Class_For_TextColor_color=Light.verified.html
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,2 @@ | ||
| ||
<div class="spinner-border text-light"></div> |
2 changes: 2 additions & 0 deletions
2
...shots/SpinnerTagHelperTests.Properly_Sets_Class_For_TextColor_color=Primary.verified.html
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,2 @@ | ||
| ||
<div class="spinner-border text-primary"></div> |
2 changes: 2 additions & 0 deletions
2
...ots/SpinnerTagHelperTests.Properly_Sets_Class_For_TextColor_color=Secondary.verified.html
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,2 @@ | ||
| ||
<div class="spinner-border text-secondary"></div> |
2 changes: 2 additions & 0 deletions
2
...shots/SpinnerTagHelperTests.Properly_Sets_Class_For_TextColor_color=Success.verified.html
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,2 @@ | ||
| ||
<div class="spinner-border text-success"></div> |
2 changes: 2 additions & 0 deletions
2
...shots/SpinnerTagHelperTests.Properly_Sets_Class_For_TextColor_color=Warning.verified.html
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,2 @@ | ||
| ||
<div class="spinner-border text-warning"></div> |
2 changes: 2 additions & 0 deletions
2
...sts/VerifySnapshots/SpinnerTagHelperTests.Should_Render_Aria_Hidden_WhenSet.verified.html
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,2 @@ | ||
| ||
<div class="HtmlEncode[[spinner-border]]" aria-hidden="HtmlEncode[[true]]"></div> |
2 changes: 2 additions & 0 deletions
2
...s/VerifySnapshots/SpinnerTagHelperTests.Should_Render_BorderSpinner_Default.verified.html
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,2 @@ | ||
| ||
<div class="HtmlEncode[[spinner-border]]"></div> |
76 changes: 76 additions & 0 deletions
76
src/AspNetCore.Utilities.Bootstrap5TagHelpers/Spinner/SpinnerTagHelper.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,76 @@ | ||
using Microsoft.AspNetCore.Mvc.TagHelpers; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
using System.Text.Encodings.Web; | ||
|
||
namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Spinner; | ||
|
||
/// <summary> | ||
/// The options for the spinner mode | ||
/// </summary> | ||
public enum SpinnerMode | ||
{ | ||
/// <summary> | ||
/// Will render with .spinner-border | ||
/// </summary> | ||
Border = 1, | ||
|
||
/// <summary> | ||
/// Will render with .spinner-grow | ||
/// </summary> | ||
Grow = 2 | ||
} | ||
|
||
/// <summary> | ||
/// A tag helper for working with bootstrap spinners | ||
/// </summary> | ||
[HtmlTargetElement("bs-spinner")] | ||
public class SpinnerTagHelper : TagHelper | ||
{ | ||
/// <summary> | ||
/// The mode of the spinner | ||
/// </summary> | ||
public SpinnerMode SpinnerMode { get; set; } = SpinnerMode.Border; | ||
|
||
/// <summary> | ||
/// The size of the spinner | ||
/// </summary> | ||
public bool IsSmall { get; set; } = false; | ||
|
||
/// <summary> | ||
/// If set to true the element will render with an aria-hidden attribute with a value of true | ||
/// </summary> | ||
public bool AriaHidden { get; set; } = false; | ||
|
||
/// <summary> | ||
/// If set will render the spinner with a color | ||
/// </summary> | ||
[HtmlAttributeName("bs-color")] | ||
public BootstrapColor? Color { get; set; } | ||
|
||
/// <summary> | ||
/// Processes the tag helper | ||
/// </summary> | ||
/// <param name="context"></param> | ||
/// <param name="output"></param> | ||
public override void Process(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
//Add | ||
output.TagName = "div"; | ||
var modeClass = SpinnerMode == SpinnerMode.Border ? "spinner-border" : "spinner-grow"; | ||
output.AddClass(modeClass, HtmlEncoder.Default); | ||
if (IsSmall) | ||
{ | ||
output.AddClass($"{modeClass}-sm", HtmlEncoder.Default); | ||
} | ||
|
||
if (Color.HasValue) | ||
{ | ||
output.AddClass($"text-{Color.Value.ToString().ToLowerInvariant()}", HtmlEncoder.Default); | ||
} | ||
|
||
if (AriaHidden) | ||
{ | ||
output.Attributes.Add("aria-hidden", "true"); | ||
} | ||
} | ||
} |