From bda65ea8b390054c1b9120201120a56469ec41a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Mon, 11 Apr 2022 01:55:05 +0200 Subject: [PATCH 1/8] Add BootstrapSplitButton. --- Models/BootstrapSplitButton.cs | 13 +++++++ Views/BootstrapSplitButton.cshtml | 65 +++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 Models/BootstrapSplitButton.cs create mode 100644 Views/BootstrapSplitButton.cshtml diff --git a/Models/BootstrapSplitButton.cs b/Models/BootstrapSplitButton.cs new file mode 100644 index 00000000..7636f563 --- /dev/null +++ b/Models/BootstrapSplitButton.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Lombiq.HelpfulExtensions.Models; + +public class BootstrapSplitButton +{ + public string Type { get; set; } + public string Text { get; set; } + public string ButtonClasses { get; set; } + public string ToggleClasses { get; set; } + public string DropdownClasses { get; set; } + public IEnumerable<(string Url, string Text)> Options { get; set; } +} diff --git a/Views/BootstrapSplitButton.cshtml b/Views/BootstrapSplitButton.cshtml new file mode 100644 index 00000000..afe7e8f5 --- /dev/null +++ b/Views/BootstrapSplitButton.cshtml @@ -0,0 +1,65 @@ +@using Lombiq.HelpfulExtensions.Models +@using OrchardCore.DisplayManagement +@using OrchardCore.DisplayManagement.Implementation +@{ + if (Model is not IShape shape || shape.As() is not { } viewModel) { return; } + + var classes = $"btn btn-{(string.IsNullOrWhiteSpace(viewModel.Type) ? "primary" : viewModel.Type)}"; + var options = viewModel.Options.AsList(); + var disabled = !options.Any(); +} + +
+ + +
+ +
+ + From dcaf3d7eb2e06098386b5338ed2b4f4359b01839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Mon, 11 Apr 2022 02:17:11 +0200 Subject: [PATCH 2/8] Move boostrap stuff into its own feature. --- .../Bootstrap/Models}/BootstrapAccordionItem.cs | 2 +- .../Bootstrap/Models}/BootstrapSplitButton.cs | 2 +- FeatureIds.cs | 1 + Manifest.cs | 7 +++++++ Views/BootstrapAccordion.cshtml | 2 +- Views/BootstrapSplitButton.cshtml | 2 +- 6 files changed, 12 insertions(+), 4 deletions(-) rename {Models => Extensions/Bootstrap/Models}/BootstrapAccordionItem.cs (74%) rename {Models => Extensions/Bootstrap/Models}/BootstrapSplitButton.cs (82%) diff --git a/Models/BootstrapAccordionItem.cs b/Extensions/Bootstrap/Models/BootstrapAccordionItem.cs similarity index 74% rename from Models/BootstrapAccordionItem.cs rename to Extensions/Bootstrap/Models/BootstrapAccordionItem.cs index f3924f4a..48426910 100644 --- a/Models/BootstrapAccordionItem.cs +++ b/Extensions/Bootstrap/Models/BootstrapAccordionItem.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc.Localization; using OrchardCore.DisplayManagement; -namespace Lombiq.HelpfulExtensions.Models; +namespace Lombiq.HelpfulExtensions.Extensions.Bootstrap.Models; public class BootstrapAccordionItem { diff --git a/Models/BootstrapSplitButton.cs b/Extensions/Bootstrap/Models/BootstrapSplitButton.cs similarity index 82% rename from Models/BootstrapSplitButton.cs rename to Extensions/Bootstrap/Models/BootstrapSplitButton.cs index 7636f563..069178fe 100644 --- a/Models/BootstrapSplitButton.cs +++ b/Extensions/Bootstrap/Models/BootstrapSplitButton.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Lombiq.HelpfulExtensions.Models; +namespace Lombiq.HelpfulExtensions.Extensions.Bootstrap.Models; public class BootstrapSplitButton { diff --git a/FeatureIds.cs b/FeatureIds.cs index ff1218ce..ec1341ca 100644 --- a/FeatureIds.cs +++ b/FeatureIds.cs @@ -11,4 +11,5 @@ public static class FeatureIds public const string Widgets = FeatureIdPrefix + nameof(Widgets); public const string Emails = FeatureIdPrefix + nameof(Emails); public const string Security = FeatureIdPrefix + nameof(Security); + public const string Bootstrap = FeatureIdPrefix + nameof(Bootstrap); } diff --git a/Manifest.cs b/Manifest.cs index 00032188..4179f11e 100644 --- a/Manifest.cs +++ b/Manifest.cs @@ -80,3 +80,10 @@ "OrchardCore.Email", } )] + +[assembly: Feature( + Id = Bootstrap, + Name = "Lombiq Helpful Extensions - Bootstrap Controls", + Category = "Content", + Description = "Adds reusable shapes for various Boostrap controls. These aren't widgets but smaller units you can reuse in your templates." +)] diff --git a/Views/BootstrapAccordion.cshtml b/Views/BootstrapAccordion.cshtml index d8e60eed..33ee69ac 100644 --- a/Views/BootstrapAccordion.cshtml +++ b/Views/BootstrapAccordion.cshtml @@ -1,4 +1,4 @@ -@using Lombiq.HelpfulExtensions.Models +@using Lombiq.HelpfulExtensions.Extensions.Bootstrap.Models @using OrchardCore.Mvc.Utilities @{ diff --git a/Views/BootstrapSplitButton.cshtml b/Views/BootstrapSplitButton.cshtml index afe7e8f5..406eac49 100644 --- a/Views/BootstrapSplitButton.cshtml +++ b/Views/BootstrapSplitButton.cshtml @@ -1,4 +1,4 @@ -@using Lombiq.HelpfulExtensions.Models +@using Lombiq.HelpfulExtensions.Extensions.Bootstrap.Models @using OrchardCore.DisplayManagement @using OrchardCore.DisplayManagement.Implementation @{ From cd318619b89811c6a23afa2a2aa39a4f3fd793e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Mon, 11 Apr 2022 02:17:38 +0200 Subject: [PATCH 3/8] Add tag helper. --- Extensions/Bootstrap/Startup.cs | 20 +++++++ .../BootstrapSplitButtonTagHelper.cs | 53 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Extensions/Bootstrap/Startup.cs create mode 100644 Extensions/Bootstrap/TagHelpers/BootstrapSplitButtonTagHelper.cs diff --git a/Extensions/Bootstrap/Startup.cs b/Extensions/Bootstrap/Startup.cs new file mode 100644 index 00000000..5a44a2a8 --- /dev/null +++ b/Extensions/Bootstrap/Startup.cs @@ -0,0 +1,20 @@ +using Lombiq.HelpfulExtensions.Extensions.Bootstrap.TagHelpers; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; +using OrchardCore.Modules; +using System; + +namespace Lombiq.HelpfulExtensions.Extensions.Bootstrap; + +[Feature(FeatureIds.Bootstrap)] +public class Startup : StartupBase +{ + public override void ConfigureServices(IServiceCollection services) => + services.AddTagHelpers(); + + public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) + { + // No need for anything here yet. + } +} diff --git a/Extensions/Bootstrap/TagHelpers/BootstrapSplitButtonTagHelper.cs b/Extensions/Bootstrap/TagHelpers/BootstrapSplitButtonTagHelper.cs new file mode 100644 index 00000000..4e53a270 --- /dev/null +++ b/Extensions/Bootstrap/TagHelpers/BootstrapSplitButtonTagHelper.cs @@ -0,0 +1,53 @@ +using Microsoft.AspNetCore.Razor.TagHelpers; +using OrchardCore.DisplayManagement; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Lombiq.HelpfulExtensions.Extensions.Bootstrap.TagHelpers; + +[HtmlTargetElement("bootstrap-split-button", Attributes = "options")] +public class BootstrapSplitButtonTagHelper : TagHelper +{ + private readonly IDisplayHelper _displayHelper; + private readonly IShapeFactory _shapeFactory; + + [HtmlAttributeName("type")] + public string Type { get; set; } + + [HtmlAttributeName("text")] + public string Text { get; set; } + + [HtmlAttributeName("button-classes")] + public string ButtonClasses { get; set; } + + [HtmlAttributeName("toggle-classes")] + public string ToggleClasses { get; set; } + + [HtmlAttributeName("dropdown-classes")] + public string DropdownClasses { get; set; } + + [HtmlAttributeName("options")] + public IEnumerable<(string Url, string Text)> Options { get; set; } + + public BootstrapSplitButtonTagHelper(IDisplayHelper displayHelper, IShapeFactory factory) + { + _displayHelper = displayHelper; + _shapeFactory = factory; + } + + public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + { + IShape shape = await _shapeFactory.New.BootstrapSplitButton( + Type: Type, + Text: Text, + ButtonClasses: ButtonClasses, + ToggleClasses: ToggleClasses, + DropdownClasses: DropdownClasses, + Options: Options); + var content = await _displayHelper.ShapeExecuteAsync(shape); + + output.TagName = null; + output.TagMode = TagMode.StartTagAndEndTag; + output.PostContent.SetHtmlContent(content); + } +} From f463b781d8325bd85ae36fd201089768de0823c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Mon, 11 Apr 2022 02:23:58 +0200 Subject: [PATCH 4/8] Add WrapperClasses. --- Extensions/Bootstrap/Models/BootstrapSplitButton.cs | 1 + .../Bootstrap/TagHelpers/BootstrapSplitButtonTagHelper.cs | 4 ++++ Views/BootstrapSplitButton.cshtml | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Extensions/Bootstrap/Models/BootstrapSplitButton.cs b/Extensions/Bootstrap/Models/BootstrapSplitButton.cs index 069178fe..bacf7d9d 100644 --- a/Extensions/Bootstrap/Models/BootstrapSplitButton.cs +++ b/Extensions/Bootstrap/Models/BootstrapSplitButton.cs @@ -6,6 +6,7 @@ public class BootstrapSplitButton { public string Type { get; set; } public string Text { get; set; } + public string WrapperClasses { get; set; } public string ButtonClasses { get; set; } public string ToggleClasses { get; set; } public string DropdownClasses { get; set; } diff --git a/Extensions/Bootstrap/TagHelpers/BootstrapSplitButtonTagHelper.cs b/Extensions/Bootstrap/TagHelpers/BootstrapSplitButtonTagHelper.cs index 4e53a270..3aaace49 100644 --- a/Extensions/Bootstrap/TagHelpers/BootstrapSplitButtonTagHelper.cs +++ b/Extensions/Bootstrap/TagHelpers/BootstrapSplitButtonTagHelper.cs @@ -17,6 +17,9 @@ public class BootstrapSplitButtonTagHelper : TagHelper [HtmlAttributeName("text")] public string Text { get; set; } + [HtmlAttributeName("class")] + public string WrapperClasses { get; set; } + [HtmlAttributeName("button-classes")] public string ButtonClasses { get; set; } @@ -40,6 +43,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu IShape shape = await _shapeFactory.New.BootstrapSplitButton( Type: Type, Text: Text, + WrapperClasses: WrapperClasses, ButtonClasses: ButtonClasses, ToggleClasses: ToggleClasses, DropdownClasses: DropdownClasses, diff --git a/Views/BootstrapSplitButton.cshtml b/Views/BootstrapSplitButton.cshtml index 406eac49..cb49666a 100644 --- a/Views/BootstrapSplitButton.cshtml +++ b/Views/BootstrapSplitButton.cshtml @@ -9,7 +9,7 @@ var disabled = !options.Any(); } -
+
- -
- -
- -