From 9df7951e28fa9d275beac1882e64e8a07272fd67 Mon Sep 17 00:00:00 2001 From: Mitchel Sellers Date: Mon, 23 Sep 2024 01:42:03 -0500 Subject: [PATCH 1/6] Updated to support proper GitVersion Usage --- .github/workflows/ci-build.yml | 12 +++++++----- .github/workflows/release-build.yml | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 1d81221..eda7608 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -26,14 +26,16 @@ jobs: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Install GitVersion - run: dotnet tool install --global GitVersion.Tool - + uses: gittools/actions/gitversion/setup@v3.0.0 + with: + versionSpec: '6.x' + - name: Determine Version id: gitversion - uses: gittools/actions/gitversion/execute@v0.13.2 + uses: gittools/actions/gitversion/execute@v3.0.0 with: - useConfigFile: true - + useConfigFile: true + - name: Build and analyze env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 5288798..983611a 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -22,17 +22,19 @@ jobs: - name: Ensure .NET Installed uses: actions/setup-dotnet@v4 with: - dotnet-version: 6.0.x + dotnet-version: 8.0.x - name: Install GitVersion - run: dotnet tool install --global GitVersion.Tool + uses: gittools/actions/gitversion/setup@v3.0.0 + with: + versionSpec: '6.x' - name: Determine Version id: gitversion - uses: gittools/actions/gitversion/execute@v0.13.2 + uses: gittools/actions/gitversion/execute@v3.0.0 with: - useConfigFile: true - + useConfigFile: true + - name: Restore Packages run: dotnet restore "${{ env.solution-path }}" - name: Build From a182b06a61ce3c61ef228b8a3bc3328f0d4a2c2e Mon Sep 17 00:00:00 2001 From: Mitchel Sellers Date: Mon, 23 Sep 2024 01:56:29 -0500 Subject: [PATCH 2/6] Updated to .NET 8 --- ...Core.Utilities.Bootstrap5TagHelpers.Sample.csproj | 2 +- ...tCore.Utilities.Bootstrap5TagHelpers.Tests.csproj | 12 ++++++------ ...sts.Renders_RequiredClassWhenNeeded.verified.html | 8 ++++---- .../AspNetCore.Utilities.Bootstrap5TagHelpers.csproj | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample.csproj b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample.csproj index 7fa31bf..4715caa 100644 --- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample.csproj +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests.csproj b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests.csproj index e2f2716..4d2f15f 100644 --- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests.csproj +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Tests Library @@ -9,16 +9,16 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormInputTagHelperTests.Renders_RequiredClassWhenNeeded.verified.html b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormInputTagHelperTests.Renders_RequiredClassWhenNeeded.verified.html index 08b1847..4b5cc78 100644 --- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormInputTagHelperTests.Renders_RequiredClassWhenNeeded.verified.html +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormInputTagHelperTests.Renders_RequiredClassWhenNeeded.verified.html @@ -1,5 +1,5 @@ - -
- - +
+ + +
\ No newline at end of file diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/AspNetCore.Utilities.Bootstrap5TagHelpers.csproj b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/AspNetCore.Utilities.Bootstrap5TagHelpers.csproj index b145ae1..a4592b1 100644 --- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/AspNetCore.Utilities.Bootstrap5TagHelpers.csproj +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/AspNetCore.Utilities.Bootstrap5TagHelpers.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 ICG.AspNetCore.Utilities.Bootstrap5TagHelpers true true @@ -14,7 +14,7 @@ ICG.AspNetCore.Utilities.Bootstrap5TagHelpers AspNetCore Utilities Bootstrap5 TagHelpers A collection of TagHelpers making Bootstrap5 utilization easier for AspNetCore Projects. - Copyright 2023, IowaComputerGurus, Subject to the MIT License + Copyright 2024, IowaComputerGurus, Subject to the MIT License https://github.com/IowaComputerGurus/aspnetcore.utilities.bootstrap5taghelpers aspnetcore;utility;bootstrap5;ui https://github.com/IowaComputerGurus/aspnetcore.utilities.bootstrap5taghelpers @@ -38,8 +38,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive From fd55546547e3ff842477d303262828f10cdd789a Mon Sep 17 00:00:00 2001 From: Mitchel Sellers Date: Mon, 23 Sep 2024 02:13:57 -0500 Subject: [PATCH 3/6] Fixes #33 by adding better support for min/max values --- .../Views/Home/Index.cshtml | 360 +++++++++--------- .../ProgressTagHelper.cs | 19 +- 2 files changed, 197 insertions(+), 182 deletions(-) diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml index f5d3623..10b927d 100644 --- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml @@ -134,36 +134,36 @@ - - Danger - - - This is a Danger Badge - - - - - <badge badge-color="Danger"> - This is a Danger Badge - </badge> - - - - - Danger Pill - - - I'm a Danger Pill Badge - - - - + + Danger + + + This is a Danger Badge + + + + + <badge badge-color="Danger"> + This is a Danger Badge + </badge> + + + + + Danger Pill + + + I'm a Danger Pill Badge + + + + <badge badge-color="Danger" display-as-pill="True"> I'm a Danger Pill Badge </badge> - - - + + +

Button

@@ -171,18 +171,18 @@ - - - - + + + + - - - + + + @@ -324,120 +324,124 @@
ExampleDisplay
ExampleDisplay
Standard Buttons - Info - Danger -
Standard Buttons + Info + Danger +
Outlined Buttons
- - - - + + + + - - + - + - - - + + + - + - + <modal id="testing"> + <modal-header Title="Testing Modal Header"> + <modal-header-dismiss></modal-header-dismiss> + </modal-header> + <modal-body> + <form-input asp-for="FirstName"></form-input> + </modal-body> + <modal-footer> + <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> + </modal-footer> + </modal> + + +
ExampleCode
ExampleCode
- - Launch Demo - +
+ + Launch Demo + - - - - - - - - - Close - - - - - <modal-toggle Target="testing"> - Launch Demo - </modal-toggle> + + + + + + + + + Close + + + + + <modal-toggle Target="testing"> + Launch Demo + </modal-toggle> - <modal id="testing"> - <modal-header Title="Testing Modal Header"> - <modal-header-dismiss></modal-header-dismiss> - </modal-header> - <modal-body> - <form-input asp-for="FirstName"></form-input> - </modal-body> - <modal-footer> - <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> - </modal-footer> - </modal> - -
- - Launch Demo - + <modal id="testing"> + <modal-header Title="Testing Modal Header"> + <modal-header-dismiss></modal-header-dismiss> + </modal-header> + <modal-body> + <form-input asp-for="FirstName"></form-input> + </modal-body> + <modal-footer> + <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> + </modal-footer> + </modal> + +
+ + Launch Demo + - - - - - - - - - Close - - - - - <modal-toggle Target="testing"> - Launch Demo - </modal-toggle> + + + + + + + + + Close + + + + + <modal-toggle Target="testing"> + Launch Demo + </modal-toggle> - <modal id="testing"> - <modal-header Title="Testing Modal Header"> - <modal-header-dismiss></modal-header-dismiss> - </modal-header> - <modal-body> - <form-input asp-for="FirstName"></form-input> - </modal-body> - <modal-footer> - <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> - </modal-footer> - </modal> - -

Progress

- - - - + + + + - - - + + + - - - + + + + + + + - - - - + + + +
DescriptionDisplay
DescriptionDisplay
Simple Progress
Simple Progress
With Background
With Background, Striped
With Background, Striped
With Background, Striped, smaller range
With Background, Striped, Animated
With Background, Striped, Animated, Label
With Background, Striped, Animated, Label
@@ -450,56 +454,56 @@ - - Simple Setup - - - - - - - -

Magic Content

-

Goes here!

-
-
- - - - Static Backdrop - - - - - - - -

Magic Content

-

Goes here!

-
-
- - - - Body Scroll Backdrop - - - - - - - -

Magic Content

-

Goes here!

-
-
- + + Simple Setup + + + + + + + +

Magic Content

+

Goes here!

+
+
+ + + + Static Backdrop + + + + + + + +

Magic Content

+

Goes here!

+
+
+ + + + Body Scroll Backdrop + + + + + + + +

Magic Content

+

Goes here!

+
+
+ Placement @@ -526,6 +530,6 @@ } -@section Scripts{ +@section Scripts { } \ No newline at end of file diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/ProgressTagHelper.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/ProgressTagHelper.cs index 316098b..3d5dfbf 100644 --- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/ProgressTagHelper.cs +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/ProgressTagHelper.cs @@ -40,6 +40,16 @@ public class ProgressTagHelper : TagHelper /// public int ProgressValue { get; set; } = 0; + /// + /// The minimum value for the progress bar + /// + public int MinValue { get; set; } = 0; + + /// + /// The maximum value for the progress bar + /// + public int MaxValue { get; set; } = 100; + /// /// Processes the tag helper /// @@ -48,7 +58,7 @@ public class ProgressTagHelper : TagHelper public override void Process(TagHelperContext context, TagHelperOutput output) { //Validate progress value - if (ProgressValue < 0 || ProgressValue > 100) + if (ProgressValue < MinValue || ProgressValue > MaxValue) throw new ArgumentOutOfRangeException("ProgressValue", "The progress value must be within the range"); //Add @@ -58,13 +68,14 @@ public override void Process(TagHelperContext context, TagHelperOutput output) if (!string.IsNullOrEmpty(AriaLabel)) output.Attributes.Add("aria-label", AriaLabel); output.Attributes.Add("aria-valuenow", ProgressValue.ToString()); - output.Attributes.Add("aria-valuemin", "0"); - output.Attributes.Add("aria-valuemax", "100"); + output.Attributes.Add("aria-valuemin", MinValue.ToString()); + output.Attributes.Add("aria-valuemax", MaxValue.ToString()); //Build the internal tag var barTag = new TagBuilder("div"); barTag.AddCssClass("progress-bar"); - barTag.Attributes.Add("style", $"width: {ProgressValue}%"); + var progress = ((ProgressValue - MinValue) / (MaxValue - (decimal)MinValue)) * 100; + barTag.Attributes.Add("style", $"width: {progress}%"); if (!string.IsNullOrEmpty(ProgressDisplayLabel)) barTag.InnerHtml.Append(ProgressDisplayLabel); if(BackgroundColor.HasValue) From 01e2ae94a9288e468853a5cc9df903ac53054df7 Mon Sep 17 00:00:00 2001 From: Mitchel Sellers Date: Mon, 23 Sep 2024 02:15:40 -0500 Subject: [PATCH 4/6] Added DIV to allowed tags #22 --- .../Card/CardHeaderActionsTagHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Card/CardHeaderActionsTagHelper.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Card/CardHeaderActionsTagHelper.cs index b49567e..6ec0399 100644 --- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Card/CardHeaderActionsTagHelper.cs +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Card/CardHeaderActionsTagHelper.cs @@ -10,7 +10,7 @@ namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Card; /// /// Helper for rendering actions within the header of a card /// -[RestrictChildren("button", "a")] +[RestrictChildren("button", "a", "div")] public class CardHeaderActionsTagHelper : TagHelper { /// From 9ba96c2572134109554abefa83dc7dcb96359dd3 Mon Sep 17 00:00:00 2001 From: Mitchel Sellers Date: Mon, 23 Sep 2024 02:20:04 -0500 Subject: [PATCH 5/6] Fixed versioning --- GitVersion.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/GitVersion.yml b/GitVersion.yml index 9306b18..b0179d5 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,17 +1,18 @@ mode: ContinuousDeployment next-version: 1.0.0 branches: - main: - regex: main - tag: 'alpha' + develop: + regex: develop + label: 'alpha' increment: Patch + prevent-increment: + when-current-commit-tagged: true source-branches: [] pull-request: regex: (pull|pull\-requests|pr)[/-] - tag: 'pr' - tag-number-pattern: '[/-](?\d+)[-/]' + label: 'pr' + label-number-pattern: '[/-](?\d+)[-/]' increment: Patch - prevent-increment-of-merged-branch-version: false is-release-branch: false source-branches: [] ignore: From 30bc5edc36f04291a77d51dfce0bcece737f4053 Mon Sep 17 00:00:00 2001 From: Mitchel Sellers Date: Mon, 23 Sep 2024 11:16:05 -0500 Subject: [PATCH 6/6] Added support fof #8 --- .../Views/Home/Index.cshtml | 40 +++++++++++++ .../Accordion/AccordionBodyTagHelper.cs | 56 ++++++++++++++++++ .../Accordion/AccordionHeaderTagHelper.cs | 56 ++++++++++++++++++ .../Accordion/AccordionItemTagHelper.cs | 57 +++++++++++++++++++ .../Accordion/AccordionTagHelper.cs | 50 ++++++++++++++++ .../Contexts/AccordionContext.cs | 17 ++++++ .../Contexts/AccordionItemContext.cs | 17 ++++++ 7 files changed, 293 insertions(+) create mode 100644 src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionBodyTagHelper.cs create mode 100644 src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionHeaderTagHelper.cs create mode 100644 src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionItemTagHelper.cs create mode 100644 src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionTagHelper.cs create mode 100644 src/AspNetCore.Utilities.Bootstrap5TagHelpers/Contexts/AccordionContext.cs create mode 100644 src/AspNetCore.Utilities.Bootstrap5TagHelpers/Contexts/AccordionItemContext.cs diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml index 10b927d..200c116 100644 --- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml @@ -239,6 +239,46 @@ +

Accordion

+

For rendering Accordions

+ + + + + + + + + + + + + + +
ExampleCode
+ + + + Accordion Item #1 + + + This is the first item's accordion body. It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow. + + + + + Accordion Item #2 + + + This is the second item's accordion body. It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow. + + + + + + +
+

Cards

For rendering bootstrap cards

diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionBodyTagHelper.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionBodyTagHelper.cs new file mode 100644 index 0000000..d72bd60 --- /dev/null +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionBodyTagHelper.cs @@ -0,0 +1,56 @@ +using ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Contexts; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.TagHelpers; +using Microsoft.AspNetCore.Razor.TagHelpers; +using System.Text.Encodings.Web; +using System.Threading.Tasks; + +namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Accordion; + +/// +/// Tag helper for individual items +/// +[HtmlTargetElement("accordion-body", ParentTag = "accordion-item")] +public class AccordionBodyTagHelper : TagHelper +{ + /// + /// Processes the tag helper + /// + /// + /// + /// + public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + { + //Get our context + var accordionContext = (AccordionContext)context.Items[typeof(AccordionContext)]; + var itemContext = (AccordionItemContext)context.Items[typeof(AccordionItemContext)]; + + //Set as a Div + output.TagName = "div"; + + //Add an id attribute + output.Attributes.Add("id", itemContext.ItemId); + + //Setup default items that are always there + output.AddClass("accordion-collapse", HtmlEncoder.Default); + output.AddClass("collapse", HtmlEncoder.Default); + + //If not always open add the parent id + if(!accordionContext.AlwaysOpen) + output.Attributes.Add("data-bs-parent", $"#{accordionContext.Id}"); + + if (itemContext.Expanded) + output.AddClass("show", HtmlEncoder.Default); + + //Create a wrapping div + var wrappingDiv = new TagBuilder("div"); + wrappingDiv.AddCssClass("accordion-body"); + + //Get the child content + var content = (await output.GetChildContentAsync()).GetContent(); + wrappingDiv.InnerHtml.AppendHtml(content); + + //Add to the output + output.Content.AppendHtml(wrappingDiv); + } +} \ No newline at end of file diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionHeaderTagHelper.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionHeaderTagHelper.cs new file mode 100644 index 0000000..4f79ec3 --- /dev/null +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionHeaderTagHelper.cs @@ -0,0 +1,56 @@ +using ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Contexts; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.TagHelpers; +using Microsoft.AspNetCore.Razor.TagHelpers; +using System.Text.Encodings.Web; +using System.Threading.Tasks; + +namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Accordion; + +/// +/// Tag helper for individual items +/// +[HtmlTargetElement("accordion-header", ParentTag = "accordion-item")] +public class AccordionHeaderTagHelper : TagHelper +{ + /// + /// Processes the tag helper + /// + /// + /// + /// + public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + { + //Get our context + var accordionContext = (AccordionContext)context.Items[typeof(AccordionContext)]; + var itemContext = (AccordionItemContext)context.Items[typeof(AccordionItemContext)]; + + //Set as a Div + output.TagName = "h2"; + + //Add default class + output.AddClass("accordion-header", HtmlEncoder.Default); + + //Build wrapping button + var wrappingButton = new TagBuilder("button"); + wrappingButton.AddCssClass("accordion-button"); + wrappingButton.Attributes.Add("type", "button"); + wrappingButton.Attributes.Add("data-bs-toggle", "collapse"); + wrappingButton.Attributes.Add("data-bs-target", $"#{itemContext.ItemId}"); + wrappingButton.Attributes.Add("aria-expanded", itemContext.Expanded.ToString().ToLower()); + wrappingButton.Attributes.Add("aria-controls", itemContext.ItemId); + + //Special behaviors for if it is not open + if (!itemContext.Expanded) + { + wrappingButton.AddCssClass("collapsed"); + } + + //Get the child content + var content = (await output.GetChildContentAsync()).GetContent(); + wrappingButton.InnerHtml.AppendHtml(content); + + //Add to the output + output.Content.AppendHtml(wrappingButton); + } +} \ No newline at end of file diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionItemTagHelper.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionItemTagHelper.cs new file mode 100644 index 0000000..9ed70cf --- /dev/null +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionItemTagHelper.cs @@ -0,0 +1,57 @@ +using ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Contexts; +using Microsoft.AspNetCore.Mvc.TagHelpers; +using Microsoft.AspNetCore.Razor.TagHelpers; +using System; +using System.Text.Encodings.Web; +using System.Threading.Tasks; + +namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Accordion; + +/// +/// Tag helper for individual items +/// +[HtmlTargetElement("accordion-item", ParentTag = "accordion")] +public class AccordionItemTagHelper : TagHelper +{ + /// + /// Should this be rendered as expanded + /// + public bool Expanded { get; set; } + + /// + /// Processes the tag helper + /// + /// + /// + /// + public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + { + var id = output.Attributes["id"]?.Value?.ToString(); + + if (id != null) + { + //Remove the id from the wrapping div + output.Attributes.Remove(output.Attributes["id"]); + } + else + { + id = Guid.NewGuid().ToString(); + } + + //Set as a Div + output.TagName = "div"; + + + //Add wrapping class + output.AddClass("accordion-item", HtmlEncoder.Default); + + + // setup content + var itemContext = new AccordionItemContext() { ItemId = id, Expanded = Expanded }; + context.Items[typeof(AccordionItemContext)] = itemContext; + + var content = (await output.GetChildContentAsync()).GetContent(); + + output.Content.AppendHtml(content); + } +} diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionTagHelper.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionTagHelper.cs new file mode 100644 index 0000000..5ffa9be --- /dev/null +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Accordion/AccordionTagHelper.cs @@ -0,0 +1,50 @@ +using ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Contexts; +using Microsoft.AspNetCore.Mvc.TagHelpers; +using Microsoft.AspNetCore.Razor.TagHelpers; +using System.Text.Encodings.Web; +using System.Threading.Tasks; + +namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Accordion; + +/// +/// A tag helper for rendering a bootstrap card to a view +/// +[RestrictChildren("accordion-item")] +public class AccordionTagHelper : TagHelper +{ + /// + /// Should this render as a Flush accordion + /// + public bool IsFlush { get; set; } = false; + + /// + /// If set to true child items can be opened/closed at any time + /// + public bool AlwaysOpen { get; set; } = false; + + /// + /// Processes the tag helper + /// + /// + /// + /// + public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + { + var id = output.Attributes["id"]?.Value?.ToString(); + + output.TagName = "div"; + + output.AddClass("accordion", HtmlEncoder.Default); + + if (IsFlush) + output.AddClass("accordion-flush", HtmlEncoder.Default); + + // setup content + var accordionContext = new AccordionContext() {Id = id, AlwaysOpen = AlwaysOpen}; + context.Items[typeof(AccordionContext)] = accordionContext; + + var content = (await output.GetChildContentAsync()).GetContent(); + + output.Content.AppendHtml(content); + } +} \ No newline at end of file diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Contexts/AccordionContext.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Contexts/AccordionContext.cs new file mode 100644 index 0000000..6cbca78 --- /dev/null +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Contexts/AccordionContext.cs @@ -0,0 +1,17 @@ +namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Contexts; + +/// +/// Context helper for accordion tag helper +/// +public class AccordionContext +{ + /// + /// The ID of the parent accordion item + /// + public string Id { get; set; } + + /// + /// Should it render as always open + /// + public bool AlwaysOpen { get; set; } +} \ No newline at end of file diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Contexts/AccordionItemContext.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Contexts/AccordionItemContext.cs new file mode 100644 index 0000000..3d264df --- /dev/null +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Contexts/AccordionItemContext.cs @@ -0,0 +1,17 @@ +namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Contexts; + +/// +/// Context for an accordion item +/// +public class AccordionItemContext +{ + /// + /// What is the unique item id for this item + /// + public string ItemId { get; set; } + + /// + /// Should this render as expanded + /// + public bool Expanded { get; set; } +} \ No newline at end of file