diff --git a/BlazorBootstrap.Demo.RCL/Components/Shared/Demo.razor.cs b/BlazorBootstrap.Demo.RCL/Components/Shared/Demo.razor.cs index 5ff08a85e..d751bfebc 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Shared/Demo.razor.cs +++ b/BlazorBootstrap.Demo.RCL/Components/Shared/Demo.razor.cs @@ -101,9 +101,7 @@ public void ResetCopyStatusJS() #endregion #region Properties, Indexers - - protected override string? ClassNames => BuildClassNames(Class, ("bd-example-snippet bd-code-snippet", true)); - + [Inject] protected IJSRuntime JS { get; set; } = default!; [Parameter] public LanguageCode LanguageCode { get; set; } = LanguageCode.Razor; diff --git a/BlazorBootstrap.Demo.RCL/Components/Shared/Section.razor b/BlazorBootstrap.Demo.RCL/Components/Shared/Section.razor index f09066915..5fdaba8c6 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Shared/Section.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Shared/Section.razor @@ -3,8 +3,8 @@
@if (Size == HeadingSize.H2) diff --git a/BlazorBootstrap.Demo.RCL/Enums/LanguageCode.cs b/BlazorBootstrap.Demo.RCL/Enums/LanguageCode.cs deleted file mode 100644 index 5ff099558..000000000 --- a/BlazorBootstrap.Demo.RCL/Enums/LanguageCode.cs +++ /dev/null @@ -1,68 +0,0 @@ -namespace BlazorBootstrap.Demo.RCL; - -/// -/// -/// -public enum LanguageCode -{ - /// - /// ASP.NET (C#) - aspnet - /// - AspNet, - - /// - /// C# - csharp, cs, dotnet - /// - CSharp, - - /// - /// CSS - css - /// - Css, - - /// - /// HTML - html - /// - HTML, - - /// - /// JavaScript - javascript, js - /// - JavaScript, - - /// - /// JSON - json - /// - JSON, - - /// - /// JSONP - jsonp - /// - JSONP, - - /// - /// Markdown - md - /// - Markdown, - - /// - /// PowerShell - powershell - /// - PowerShell, - - /// - /// Razor C# - cshtml, razor - /// - Razor, - - /// - /// Text - none - /// - Text, - - /// - /// YAML - yaml, yml - /// - YAML -} - diff --git a/BlazorBootstrap.Demo.RCL/Extensions/EnumExtensions.cs b/BlazorBootstrap.Demo.RCL/Extensions/EnumExtensions.cs index f84671155..d6ea6e76b 100644 --- a/BlazorBootstrap.Demo.RCL/Extensions/EnumExtensions.cs +++ b/BlazorBootstrap.Demo.RCL/Extensions/EnumExtensions.cs @@ -8,15 +8,15 @@ public static class EnumExtensions LanguageCode.AspNet => "language-aspnet", LanguageCode.CSharp => "language-csharp", LanguageCode.Css => "language-css", - LanguageCode.HTML => "language-html", + LanguageCode.Html => "language-html", LanguageCode.JavaScript => "language-js", - LanguageCode.JSON => "language-json", - LanguageCode.JSONP => "language-jsonp", + LanguageCode.Json => "language-json", + LanguageCode.Jsonp => "language-jsonp", LanguageCode.Markdown => "language-md", LanguageCode.PowerShell => "language-powershell", LanguageCode.Razor => "language-razor", - LanguageCode.Text => "language-none", - LanguageCode.YAML => "language-yaml", + LanguageCode.StructuredText => "language-none", + LanguageCode.Yaml => "language-yaml", _ => null }; @@ -26,15 +26,15 @@ public static class EnumExtensions LanguageCode.AspNet => "ASP.NET", LanguageCode.CSharp => "C#", LanguageCode.Css => "CSS", - LanguageCode.HTML => "HTML", + LanguageCode.Html => "HTML", LanguageCode.JavaScript => "JS", - LanguageCode.JSON => "JSON", - LanguageCode.JSONP => "JSONP", + LanguageCode.Json => "JSON", + LanguageCode.Jsonp => "JSONP", LanguageCode.Markdown => "Markdown", LanguageCode.PowerShell => "PowerShell", LanguageCode.Razor => "Razor", - LanguageCode.Text => "Text", - LanguageCode.YAML => "yaml", + LanguageCode.StructuredText => "Text", + LanguageCode.Yaml => "yaml", _ => null }; } diff --git a/blazorbootstrap/Components/Accordion/Accordion.razor b/blazorbootstrap/Components/Accordion/Accordion.razor index 812567fbe..e5f3ba429 100644 --- a/blazorbootstrap/Components/Accordion/Accordion.razor +++ b/blazorbootstrap/Components/Accordion/Accordion.razor @@ -2,7 +2,7 @@ @inherits BlazorBootstrapComponentBase -
+
@if (ChildContent != null) { @ChildContent diff --git a/blazorbootstrap/Components/Accordion/Accordion.razor.cs b/blazorbootstrap/Components/Accordion/Accordion.razor.cs index b698ba673..106d5dc30 100644 --- a/blazorbootstrap/Components/Accordion/Accordion.razor.cs +++ b/blazorbootstrap/Components/Accordion/Accordion.razor.cs @@ -13,15 +13,7 @@ public partial class Accordion : BlazorBootstrapComponentBase #endregion #region Methods - - /// - protected override async ValueTask DisposeAsyncCore(bool disposing) - { - if (disposing) items = null; - - await base.DisposeAsyncCore(disposing); - } - + /// /// Hides the by index. /// @@ -188,7 +180,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(OnHiding): OnHiding = (EventCallback)parameter.Value; break; case nameof(OnShowing): OnShowing = (EventCallback)parameter.Value; break; case nameof(OnShown): OnShown = (EventCallback)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; default: AdditionalAttributes![parameter.Name] = parameter.Value; break; @@ -200,13 +191,7 @@ public override Task SetParametersAsync(ParameterView parameters) #endregion - #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, - (BootstrapClass.Accordion, true), - (BootstrapClass.AccordionFlush, Flush)); + #region Properties, Indexers /// /// If , accordion items stay open when another item is opened. @@ -233,8 +218,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [Parameter] - public bool Flush { get; set; } + [Parameter] public bool Flush { get; set; } /// /// This event is fired when an accordion item has been hidden from the user (will wait for CSS transitions to complete). diff --git a/blazorbootstrap/Components/Accordion/AccordionItem.razor b/blazorbootstrap/Components/Accordion/AccordionItem.razor index ef05d710c..52b1d2edb 100644 --- a/blazorbootstrap/Components/Accordion/AccordionItem.razor +++ b/blazorbootstrap/Components/Accordion/AccordionItem.razor @@ -1,7 +1,7 @@ @namespace BlazorBootstrap @inherits BlazorBootstrapComponentBase -
+

public partial class Badge : BlazorBootstrapComponentBase { - #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, - (BootstrapClass.Badge, true), - (Color.ToBadgeColorClass(), Color != BadgeColor.None), - (IndicatorType.ToBadgeIndicatorClass(), IndicatorType != BadgeIndicatorType.None), - (Position.ToPositionClass(), Position != Position.None), - (Placement.ToBadgePlacementClass(), Placement != BadgePlacement.None), - ("p-2", ChildContent is null)); + #region Properties, Indexers /// /// Gets or sets the content to be rendered within the component. @@ -25,8 +15,7 @@ public partial class Badge : BlazorBootstrapComponentBase /// /// Default value is . /// - [Parameter] - public RenderFragment? ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } /// /// Gets or sets the badge color. @@ -34,8 +23,7 @@ public partial class Badge : BlazorBootstrapComponentBase /// /// Default value is . /// - [Parameter] - public BadgeColor Color { get; set; } = BadgeColor.Secondary; + [Parameter] public BadgeColor Color { get; set; } = BadgeColor.Secondary; /// /// Gets or sets the badge indicator. @@ -43,8 +31,7 @@ public partial class Badge : BlazorBootstrapComponentBase /// /// Default value is . /// - [Parameter] - public BadgeIndicatorType IndicatorType { get; set; } = BadgeIndicatorType.None; + [Parameter] public BadgeIndicatorType IndicatorType { get; set; } = BadgeIndicatorType.None; /// /// Gets or sets the badge placement. @@ -52,8 +39,7 @@ public partial class Badge : BlazorBootstrapComponentBase /// /// Default value is . /// - [Parameter] - public BadgePlacement Placement { get; set; } = BadgePlacement.None; + [Parameter] public BadgePlacement Placement { get; set; } = BadgePlacement.None; /// /// Gets or sets the badge position. @@ -61,8 +47,7 @@ public partial class Badge : BlazorBootstrapComponentBase /// /// Default value is . /// - [Parameter] - public Position Position { get; set; } = Position.None; + [Parameter] public Position Position { get; set; } = Position.None; /// /// Gets or sets the visually hidden text. @@ -70,8 +55,7 @@ public partial class Badge : BlazorBootstrapComponentBase /// /// Default value is . /// - [Parameter] - public string VisuallyHiddenText { get; set; } = default!; + [Parameter] public string VisuallyHiddenText { get; set; } = default!; #endregion @@ -95,7 +79,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(IndicatorType): IndicatorType = (BadgeIndicatorType)parameter.Value; break; case nameof(Placement): Placement = (BadgePlacement)parameter.Value; break; case nameof(Position): Position = (Position)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; case nameof(VisuallyHiddenText): VisuallyHiddenText = (string)parameter.Value; break; default: AdditionalAttributes![parameter.Name] = parameter.Value; diff --git a/blazorbootstrap/Components/Breadcrumb/Breadcrumb.razor b/blazorbootstrap/Components/Breadcrumb/Breadcrumb.razor index 500fd4c74..76e0d6162 100644 --- a/blazorbootstrap/Components/Breadcrumb/Breadcrumb.razor +++ b/blazorbootstrap/Components/Breadcrumb/Breadcrumb.razor @@ -3,7 +3,7 @@ @if (Items != null && Items.Any()) { - /// The default loading template - protected virtual RenderFragment ProvideDefaultLoadingTemplate() => builder => + private RenderFragment ProvideDefaultLoadingTemplate() => builder => { - builder.AddMarkupContent(0, $" {LoadingText}"); + builder.AddMarkupContent(0, $" {LoadingText}"); }; private void SetAttributes() @@ -185,9 +188,9 @@ private void SetAttributes() if (Target != Target.None) if (!AdditionalAttributes.TryGetValue("target", out _)) - AdditionalAttributes.Add("target", Target.ToTargetString()!); + AdditionalAttributes.Add("target", EnumExtensions.TargetStringMap[Target]); else - AdditionalAttributes["target"] = Target.ToTargetString()!; + AdditionalAttributes["target"] = EnumExtensions.TargetStringMap[Target]; if (Disabled) { @@ -218,25 +221,24 @@ private void SetAttributes() } // button enabled (and) tooltip text not empty - if (!Disabled && !string.IsNullOrWhiteSpace(TooltipTitle)) + if (!Disabled && !String.IsNullOrWhiteSpace(TooltipTitle)) { // Ref: https://getbootstrap.com/docs/5.2/components/buttons/#toggle-states // The below code creates an issue when the `button` or `a` element has a tooltip. if (!AdditionalAttributes.TryGetValue("data-bs-placement", out _)) - AdditionalAttributes.Add("data-bs-placement", TooltipPlacement.ToTooltipPlacementName()); + AdditionalAttributes.Add("data-bs-placement", EnumExtensions.TooltipPlacementNameMap[TooltipPlacement]); AdditionalAttributes["title"] = TooltipTitle; - AdditionalAttributes["data-bs-custom-class"] = TooltipColor.ToTooltipColorClass()!; + AdditionalAttributes["data-bs-custom-class"] = EnumExtensions.TooltipColorClassMap[TooltipColor]!; } - // button disabled (or) tooltip text empty - else + else // button disabled (or) tooltip text empty { AdditionalAttributes.Remove("data-bs-toggle"); AdditionalAttributes.Remove("data-bs-placement"); AdditionalAttributes.Remove("title"); - AdditionalAttributes.Remove("data-bs-custom-class", out _); + AdditionalAttributes.Remove("data-bs-custom-class"); } } @@ -264,7 +266,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Outline): Outline = (bool)parameter.Value; break; case nameof(Position): Position = (Position)parameter.Value; break; case nameof(Size): Size = (ButtonSize)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; case nameof(TabIndex): TabIndex = (int?)parameter.Value; break; case nameof(Target): Target = (Target)parameter.Value; break; case nameof(To): To = (string?)parameter.Value; break; @@ -273,10 +274,10 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(TooltipTitle): TooltipTitle = (string)parameter.Value; break; case nameof(Type): Type = (ButtonType)parameter.Value; - ButtonTypeString = Type.ToButtonTypeString(); + ButtonTypeString = EnumExtensions.ButtonTypeStringMap[Type]; break; default: - AdditionalAttributes![parameter.Name] = parameter.Value; + AdditionalAttributes[parameter.Name] = parameter.Value; break; } } @@ -300,20 +301,7 @@ public override Task SetParametersAsync(ParameterView parameters) #endregion #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, - (BootstrapClass.Button, true), - (Color.ToButtonColorClass(), Color != ButtonColor.None && !Outline), - (Color.ToButtonOutlineColorClass(), Color != ButtonColor.None && Outline), - (Size.ToButtonSizeClass(), Size != ButtonSize.None), - (BootstrapClass.ButtonDisabled, Disabled && Type == ButtonType.Link), - (BootstrapClass.ButtonActive, Active), - (BootstrapClass.ButtonBlock, Block), - (BootstrapClass.ButtonLoading!, Loading && LoadingTemplate is not null), - (Position.ToPositionClass(), Position != Position.None)); - + /// /// Gets or sets the button active state. /// @@ -341,7 +329,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// Default value is . /// [Parameter] - public RenderFragment? ChildContent { get; set; } = default!; + public RenderFragment? ChildContent { get; set; } /// /// Gets or sets the button color. @@ -377,7 +365,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// Default value is . /// [Parameter] - public RenderFragment? LoadingTemplate { get; set; } = default!; + public RenderFragment? LoadingTemplate { get; set; } /// /// Gets or sets the loading text. @@ -481,6 +469,59 @@ public override Task SetParametersAsync(ParameterView parameters) public ButtonType Type { get; set; } = ButtonType.Button; #endregion + + + /// + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + var btnClasses = new StringBuilder(BootstrapClass.Button); + btnClasses.Append(' ').Append(Outline ? EnumExtensions.ButtonOutlineColorClassMap[Color] : EnumExtensions.ButtonColorClassMap[Color]); + + btnClasses.Append(' ').Append(EnumExtensions.ButtonSizeClassMap[Size]); + if (Disabled && Type == ButtonType.Link) + { + btnClasses.Append(' ').Append(BootstrapClass.ButtonDisabled); + } + + if (Active) + { + btnClasses.Append(' ').Append(BootstrapClass.ButtonActive); + } + + if (Block) + { + btnClasses.Append(' ').Append(BootstrapClass.ButtonBlock); + } + + if (Loading && LoadingTemplate is not null) + { + btnClasses.Append(' ').Append(BootstrapClass.ButtonLoading); + } + + btnClasses.Append(' ').Append(EnumExtensions.PositionClassMap[Position]); + btnClasses.Append(' ').Append(Class); + + + builder.OpenElement(0, Type == ButtonType.Link ? "a" : "button"); + builder.AddAttribute(1, "type", ButtonTypeString); + builder.AddAttribute(2, "id", Id); + builder.AddAttribute(3, "class", btnClasses.ToString()); + builder.AddAttribute(4, "disabled", Disabled); + builder.AddMultipleAttributes(5, AdditionalAttributes); + + builder.AddElementReferenceCapture(6, (value) => { Element = value; }); + if (Loading && LoadingTemplate is not null) + { + builder.AddContent(7, LoadingTemplate); + } + else if (ChildContent != null) + { + builder.AddContent(16, ChildContent); + } + builder.CloseElement(); + } + + // TODO: Review // - Disable text wrapping: https://getbootstrap.com/docs/5.1/components/buttons/#disable-text-wrapping diff --git a/blazorbootstrap/Components/Button/Button.razor b/blazorbootstrap/Components/Button/Button.razor deleted file mode 100644 index 5fc412bd4..000000000 --- a/blazorbootstrap/Components/Button/Button.razor +++ /dev/null @@ -1,44 +0,0 @@ -@namespace BlazorBootstrap -@inherits BlazorBootstrapComponentBase - -@if (Type == ButtonType.Link) -{ - - - @if (Loading && LoadingTemplate is not null) - { - @LoadingTemplate - } - else if (ChildContent != null) - { - @ChildContent - } - - -} -else -{ - -} diff --git a/blazorbootstrap/Components/Callout/Callout.razor b/blazorbootstrap/Components/Callout/Callout.razor index 399b547d3..6dc98d756 100644 --- a/blazorbootstrap/Components/Callout/Callout.razor +++ b/blazorbootstrap/Components/Callout/Callout.razor @@ -1,7 +1,7 @@ @namespace BlazorBootstrap @inherits BlazorBootstrapComponentBase -
+
@if (!HideHeading) {
diff --git a/blazorbootstrap/Components/Callout/Callout.razor.cs b/blazorbootstrap/Components/Callout/Callout.razor.cs index e3cf9072d..6b5731e1a 100644 --- a/blazorbootstrap/Components/Callout/Callout.razor.cs +++ b/blazorbootstrap/Components/Callout/Callout.razor.cs @@ -34,7 +34,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Heading): Heading = (string)parameter.Value; break; case nameof(HideHeading): HideHeading = (bool)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; default: AdditionalAttributes![parameter.Name] = parameter.Value; break; @@ -60,13 +59,7 @@ public override Task SetParametersAsync(ParameterView parameters) #endregion #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, - (BootstrapClass.Callout, true), - (Color.ToCalloutColorClass(), true)); - + /// /// Gets or sets the content to be rendered within the component. /// diff --git a/blazorbootstrap/Components/Card/Card.razor b/blazorbootstrap/Components/Card/Card.razor index e42f73c22..584877a18 100644 --- a/blazorbootstrap/Components/Card/Card.razor +++ b/blazorbootstrap/Components/Card/Card.razor @@ -1,7 +1,7 @@ @namespace BlazorBootstrap @inherits BlazorBootstrapComponentBase -
+
@if (ChildContent != null) { @ChildContent diff --git a/blazorbootstrap/Components/Card/Card.razor.cs b/blazorbootstrap/Components/Card/Card.razor.cs index b7294ad9c..cd5f68529 100644 --- a/blazorbootstrap/Components/Card/Card.razor.cs +++ b/blazorbootstrap/Components/Card/Card.razor.cs @@ -7,14 +7,7 @@ public partial class Card : BlazorBootstrapComponentBase { #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, - (BootstrapClass.Card, true), - (TextAlignment.ToTextAlignmentClass(), true), - (Color.ToCardColorClass(), true)); - + /// /// Gets or sets the content to be rendered within the component. /// @@ -22,7 +15,7 @@ public partial class Card : BlazorBootstrapComponentBase /// Default value is . /// [Parameter] - public RenderFragment? ChildContent { get; set; } = default!; + public RenderFragment? ChildContent { get; set; } /// /// Gets or sets the card color. @@ -61,7 +54,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Class): Class = (string)parameter.Value; break; case nameof(Color): Color = (CardColor)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; case nameof(TextAlignment): TextAlignment = (Alignment)parameter.Value; break; default: diff --git a/blazorbootstrap/Components/Card/CardBody.razor b/blazorbootstrap/Components/Card/CardBody.razor index e42f73c22..28794f82e 100644 --- a/blazorbootstrap/Components/Card/CardBody.razor +++ b/blazorbootstrap/Components/Card/CardBody.razor @@ -1,7 +1,7 @@ @namespace BlazorBootstrap @inherits BlazorBootstrapComponentBase -
+
@if (ChildContent != null) { @ChildContent diff --git a/blazorbootstrap/Components/Card/CardBody.razor.cs b/blazorbootstrap/Components/Card/CardBody.razor.cs index 71f69b2bc..a9a37d29b 100644 --- a/blazorbootstrap/Components/Card/CardBody.razor.cs +++ b/blazorbootstrap/Components/Card/CardBody.razor.cs @@ -6,11 +6,7 @@ public partial class CardBody : BlazorBootstrapComponentBase { #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, (BootstrapClass.CardBody, true)); - + /// /// Gets or sets the content to be rendered within the component. /// @@ -18,7 +14,7 @@ public partial class CardBody : BlazorBootstrapComponentBase /// Default value is . /// [Parameter] - public RenderFragment? ChildContent { get; set; } = default!; + public RenderFragment? ChildContent { get; set; } #endregion @@ -37,7 +33,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Class): Class = (string)parameter.Value; break; case nameof(ChildContent): ChildContent = (RenderFragment)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; default: AdditionalAttributes![parameter.Name] = parameter.Value; break; diff --git a/blazorbootstrap/Components/Card/CardFooter.razor b/blazorbootstrap/Components/Card/CardFooter.razor index e42f73c22..df893823a 100644 --- a/blazorbootstrap/Components/Card/CardFooter.razor +++ b/blazorbootstrap/Components/Card/CardFooter.razor @@ -1,7 +1,7 @@ @namespace BlazorBootstrap @inherits BlazorBootstrapComponentBase -
+
@if (ChildContent != null) { @ChildContent diff --git a/blazorbootstrap/Components/Card/CardFooter.razor.cs b/blazorbootstrap/Components/Card/CardFooter.razor.cs index f5a5b1ad4..8c15e6dc9 100644 --- a/blazorbootstrap/Components/Card/CardFooter.razor.cs +++ b/blazorbootstrap/Components/Card/CardFooter.razor.cs @@ -6,11 +6,7 @@ ///
public partial class CardFooter : BlazorBootstrapComponentBase { - #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, (BootstrapClass.CardFooter, true)); + #region Properties, Indexers /// /// Gets or sets the content to be rendered within the component. @@ -19,7 +15,7 @@ public partial class CardFooter : BlazorBootstrapComponentBase /// Default value is . /// [Parameter] - public RenderFragment? ChildContent { get; set; } = default!; + public RenderFragment? ChildContent { get; set; } #endregion @@ -37,7 +33,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Class): Class = (string)parameter.Value; break; case nameof(ChildContent): ChildContent = (RenderFragment)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; default: AdditionalAttributes![parameter.Name] = parameter.Value; diff --git a/blazorbootstrap/Components/Card/CardGroup.razor b/blazorbootstrap/Components/Card/CardGroup.razor index 2a3b89ab2..aef56e2b8 100644 --- a/blazorbootstrap/Components/Card/CardGroup.razor +++ b/blazorbootstrap/Components/Card/CardGroup.razor @@ -1,7 +1,7 @@ @namespace BlazorBootstrap @inherits BlazorBootstrapComponentBase -
+
@if (ChildContent != null) { @ChildContent diff --git a/blazorbootstrap/Components/Card/CardGroup.razor.cs b/blazorbootstrap/Components/Card/CardGroup.razor.cs index 7bcd10c5a..1ac7d4416 100644 --- a/blazorbootstrap/Components/Card/CardGroup.razor.cs +++ b/blazorbootstrap/Components/Card/CardGroup.razor.cs @@ -7,11 +7,7 @@ public partial class CardGroup : BlazorBootstrapComponentBase { #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, (BootstrapClass.CardGroup, true)); - + /// /// Gets or sets the content to be rendered within the component. /// @@ -19,7 +15,7 @@ public partial class CardGroup : BlazorBootstrapComponentBase /// Default value is . /// [Parameter] - public RenderFragment? ChildContent { get; set; } = default!; + public RenderFragment? ChildContent { get; set; } #endregion @@ -37,7 +33,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Class): Class = (string)parameter.Value; break; case nameof(ChildContent): ChildContent = (RenderFragment)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; default: AdditionalAttributes![parameter.Name] = parameter.Value; diff --git a/blazorbootstrap/Components/Card/CardHeader.razor b/blazorbootstrap/Components/Card/CardHeader.razor index e42f73c22..b24f8dae8 100644 --- a/blazorbootstrap/Components/Card/CardHeader.razor +++ b/blazorbootstrap/Components/Card/CardHeader.razor @@ -1,7 +1,7 @@ @namespace BlazorBootstrap @inherits BlazorBootstrapComponentBase -
+
@if (ChildContent != null) { @ChildContent diff --git a/blazorbootstrap/Components/Card/CardHeader.razor.cs b/blazorbootstrap/Components/Card/CardHeader.razor.cs index 7aef3c3c3..50d0860b3 100644 --- a/blazorbootstrap/Components/Card/CardHeader.razor.cs +++ b/blazorbootstrap/Components/Card/CardHeader.razor.cs @@ -7,18 +7,12 @@ public partial class CardHeader : BlazorBootstrapComponentBase { #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, - (BootstrapClass.CardHeader, true), - (Color.ToCardColorClass(), true)); - + /// /// Gets or sets the content to be rendered within the component. /// [Parameter] - public RenderFragment? ChildContent { get; set; } = default!; + public RenderFragment? ChildContent { get; set; } /// /// Gets or sets the card header color. @@ -47,7 +41,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(ChildContent): ChildContent = (RenderFragment)parameter.Value; break; case nameof(Color): Color = (CardColor)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; default: AdditionalAttributes![parameter.Name] = parameter.Value; break; diff --git a/blazorbootstrap/Components/Card/CardLink.razor b/blazorbootstrap/Components/Card/CardLink.razor index d0ff48bc6..3296de797 100644 --- a/blazorbootstrap/Components/Card/CardLink.razor +++ b/blazorbootstrap/Components/Card/CardLink.razor @@ -1,7 +1,7 @@ @namespace BlazorBootstrap @inherits BlazorBootstrapComponentBase - + @if (ChildContent != null) { @ChildContent diff --git a/blazorbootstrap/Components/Card/CardLink.razor.cs b/blazorbootstrap/Components/Card/CardLink.razor.cs index 1e47b2849..7cd654745 100644 --- a/blazorbootstrap/Components/Card/CardLink.razor.cs +++ b/blazorbootstrap/Components/Card/CardLink.razor.cs @@ -21,7 +21,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Class): Class = (string)parameter.Value; break; case nameof(Disabled): Disabled = (bool)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; case nameof(TabIndex): TabIndex = (int?)parameter.Value; break; case nameof(Target): Target = (Target)parameter.Value; break; case nameof(To): To = (string)parameter.Value; break; @@ -43,7 +42,7 @@ private void SetAttributes() if (Target != Target.None) if (!AdditionalAttributes.TryGetValue("target", out _)) - AdditionalAttributes.Add("target", Target.ToTargetString()!); + AdditionalAttributes.Add("target", EnumExtensions.TargetStringMap[Target]); if (Disabled) { @@ -72,18 +71,11 @@ private void SetAttributes() #endregion #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, - (BootstrapClass.CardLink, true), - (BootstrapClass.Disabled, Disabled)); - + /// /// Gets or sets the content to be rendered within the component. /// - [Parameter] - public RenderFragment? ChildContent { get; set; } = default!; + [Parameter] public RenderFragment? ChildContent { get; set; } /// /// If , disables the card link. @@ -91,8 +83,7 @@ private void SetAttributes() /// /// Default value is . /// - [Parameter] - public bool Disabled { get; set; } + [Parameter] public bool Disabled { get; set; } /// /// Gets or sets the card link tab index. @@ -100,8 +91,7 @@ private void SetAttributes() /// /// Default value is . /// - [Parameter] - public int? TabIndex { get; set; } + [Parameter] public int? TabIndex { get; set; } /// /// Gets or sets the card link target. @@ -109,8 +99,7 @@ private void SetAttributes() /// /// Default value is . /// - [Parameter] - public Target Target { get; set; } = Target.None; + [Parameter] public Target Target { get; set; } = Target.None; /// /// Gets or sets the link href attribute. @@ -118,8 +107,7 @@ private void SetAttributes() /// /// Default value is . /// - [Parameter] - public string? To { get; set; } + [Parameter] public string? To { get; set; } #endregion diff --git a/blazorbootstrap/Components/Card/CardSubTitle.razor.cs b/blazorbootstrap/Components/Card/CardSubTitle.cs similarity index 69% rename from blazorbootstrap/Components/Card/CardSubTitle.razor.cs rename to blazorbootstrap/Components/Card/CardSubTitle.cs index 1e3435cae..c0a352c5f 100644 --- a/blazorbootstrap/Components/Card/CardSubTitle.razor.cs +++ b/blazorbootstrap/Components/Card/CardSubTitle.cs @@ -1,16 +1,14 @@ -namespace BlazorBootstrap; +using Microsoft.AspNetCore.Components.Rendering; + +namespace BlazorBootstrap; /// /// This component represents the subtitle of a .
/// If no subtitle is required, it can be omitted from the card implementation. ///
-public partial class CardSubTitle : BlazorBootstrapComponentBase +public sealed class CardSubTitle : BlazorBootstrapComponentBase { - #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, (BootstrapClass.CardSubTitle, true)); + #region Properties, Indexers /// /// Gets or sets the content to be rendered within the component. @@ -45,7 +43,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Class): Class = (string)parameter.Value; break; case nameof(ChildContent): ChildContent = (RenderFragment)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; case nameof(Size): Size = (HeadingSize)parameter.Value; break; default: AdditionalAttributes![parameter.Name] = parameter.Value; @@ -57,4 +54,19 @@ public override Task SetParametersAsync(ParameterView parameters) } #endregion + + /// + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.OpenElement(0, Enum.GetName(Size)!.ToLowerInvariant()); + builder.AddAttribute(1, "id", Id); + builder.AddAttribute(2, "class", $"{BootstrapClass.CardSubTitle} {Class}"); + builder.AddMultipleAttributes(3, AdditionalAttributes); + builder.AddElementReferenceCapture(4, (value) => Element = value); + if (ChildContent != null) + { + builder.AddContent(5, ChildContent); + } + builder.CloseElement(); + } } diff --git a/blazorbootstrap/Components/Card/CardSubTitle.razor b/blazorbootstrap/Components/Card/CardSubTitle.razor deleted file mode 100644 index 6a02f862b..000000000 --- a/blazorbootstrap/Components/Card/CardSubTitle.razor +++ /dev/null @@ -1,57 +0,0 @@ -@namespace BlazorBootstrap -@inherits BlazorBootstrapComponentBase - -@if (Size == HeadingSize.H1) -{ -

- @if (ChildContent != null) - { - @ChildContent - } -

-} -else if (Size == HeadingSize.H2) -{ -

- @if (ChildContent != null) - { - @ChildContent - } -

-} -else if (Size == HeadingSize.H3) -{ -

- @if (ChildContent != null) - { - @ChildContent - } -

-} -else if (Size == HeadingSize.H4) -{ -

- @if (ChildContent != null) - { - @ChildContent - } -

-} -else if (Size == HeadingSize.H5) -{ -
- @if (ChildContent != null) - { - @ChildContent - } -
-} -else if (Size == HeadingSize.H6) -{ -
- @if (ChildContent != null) - { - @ChildContent - } -
-} diff --git a/blazorbootstrap/Components/Card/CardText.razor b/blazorbootstrap/Components/Card/CardText.razor index f06950815..e591ee39c 100644 --- a/blazorbootstrap/Components/Card/CardText.razor +++ b/blazorbootstrap/Components/Card/CardText.razor @@ -1,7 +1,7 @@ @namespace BlazorBootstrap @inherits BlazorBootstrapComponentBase -

+

@if (ChildContent != null) { @ChildContent diff --git a/blazorbootstrap/Components/Card/CardText.razor.cs b/blazorbootstrap/Components/Card/CardText.razor.cs index 4d9262ad9..72daefc47 100644 --- a/blazorbootstrap/Components/Card/CardText.razor.cs +++ b/blazorbootstrap/Components/Card/CardText.razor.cs @@ -6,17 +6,12 @@ ///

public partial class CardText : BlazorBootstrapComponentBase { - #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, (BootstrapClass.CardText, true)); + #region Properties, Indexers /// /// Gets or sets the content to be rendered within the component. /// - [Parameter] - public RenderFragment? ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } #endregion @@ -36,7 +31,7 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Class): Class = (string)parameter.Value; break; case nameof(ChildContent): ChildContent = (RenderFragment)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; + default: AdditionalAttributes![parameter.Name] = parameter.Value; break; diff --git a/blazorbootstrap/Components/Card/CardTitle.razor.cs b/blazorbootstrap/Components/Card/CardTitle.cs similarity index 64% rename from blazorbootstrap/Components/Card/CardTitle.razor.cs rename to blazorbootstrap/Components/Card/CardTitle.cs index 8dec9f48c..2f5f22173 100644 --- a/blazorbootstrap/Components/Card/CardTitle.razor.cs +++ b/blazorbootstrap/Components/Card/CardTitle.cs @@ -1,22 +1,19 @@ -namespace BlazorBootstrap; +using Microsoft.AspNetCore.Components.Rendering; + +namespace BlazorBootstrap; /// /// This component represents the title of a .
/// If no title is required, it can be omitted from the card implementation. ///
-public partial class CardTitle : BlazorBootstrapComponentBase +public sealed class CardTitle : BlazorBootstrapComponentBase { #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, (BootstrapClass.CardTitle, true)); - + /// /// Gets or sets the content to be rendered within the component. /// - [Parameter] - public RenderFragment? ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } ///
/// Gets or sets the card title size. @@ -24,8 +21,7 @@ public partial class CardTitle : BlazorBootstrapComponentBase /// /// Default value is . /// - [Parameter] - public HeadingSize Size { get; set; } = HeadingSize.H5; + [Parameter] public HeadingSize Size { get; set; } = HeadingSize.H5; #endregion @@ -44,7 +40,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Class): Class = (string)parameter.Value; break; case nameof(ChildContent): ChildContent = (RenderFragment)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value; break; - case nameof(Style): Style = (string)parameter.Value; break; case nameof(Size): Size = (HeadingSize)parameter.Value; break; default: AdditionalAttributes![parameter.Name] = parameter.Value; @@ -55,4 +50,19 @@ public override Task SetParametersAsync(ParameterView parameters) return base.SetParametersAsync(ParameterView.Empty); } #endregion + + /// + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.OpenElement(0, Enum.GetName(Size)!.ToLowerInvariant()); + builder.AddAttribute(1, "id", Id); + builder.AddAttribute(2, "class", $"{BootstrapClass.CardTitle} {Class}"); + builder.AddMultipleAttributes(3, AdditionalAttributes); + builder.AddElementReferenceCapture(4, (value) => Element = value); + if (ChildContent != null) + { + builder.AddContent(5, ChildContent); + } + builder.CloseElement(); + } } diff --git a/blazorbootstrap/Components/Card/CardTitle.razor b/blazorbootstrap/Components/Card/CardTitle.razor deleted file mode 100644 index 616e1df24..000000000 --- a/blazorbootstrap/Components/Card/CardTitle.razor +++ /dev/null @@ -1,39 +0,0 @@ -@namespace BlazorBootstrap -@inherits BlazorBootstrapComponentBase - -@if (Size == HeadingSize.H1) -{ -

- @ChildContent -

-} -else if (Size == HeadingSize.H2) -{ -

- @ChildContent -

-} -else if (Size == HeadingSize.H3) -{ -

- @ChildContent -

-} -else if (Size == HeadingSize.H4) -{ -

- @ChildContent -

-} -else if (Size == HeadingSize.H5) -{ -
- @ChildContent -
-} -else if (Size == HeadingSize.H6) -{ -
- @ChildContent -
-} diff --git a/blazorbootstrap/Components/Carousel/Carousel.razor b/blazorbootstrap/Components/Carousel/Carousel.razor index e25954893..3e952cb81 100644 --- a/blazorbootstrap/Components/Carousel/Carousel.razor +++ b/blazorbootstrap/Components/Carousel/Carousel.razor @@ -2,7 +2,7 @@ @inherits BlazorBootstrapComponentBase -
+
@if (ShowIndicators && HasItems) {
@@ -11,9 +11,9 @@ foreach (var item in items) { var j = i; - bool isActiveItem = (i == activeIndex); - string? itemClass = isActiveItem ? "active" : null; - string? label = item.Label ?? $"Slide {i + 1}"; + var isActiveItem = (i == activeIndex); + var itemClass = isActiveItem ? "active" : null; + var label = item.Label ?? $"Slide {i + 1}"; diff --git a/blazorbootstrap/Components/Dropdown/DropdownActionButton.razor.cs b/blazorbootstrap/Components/Dropdown/DropdownActionButton.razor.cs index 41ea5de18..f7110bd1d 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownActionButton.razor.cs +++ b/blazorbootstrap/Components/Dropdown/DropdownActionButton.razor.cs @@ -35,7 +35,7 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Disabled): Disabled = (bool)parameter.Value!; break; case nameof(Id): Id = (string)parameter.Value!; break; case nameof(Size): Size = (DropdownSize)parameter.Value!; break; - case nameof(Style): Style = (string)parameter.Value; break; + case nameof(TabIndex): TabIndex = (int?)parameter.Value!; break; default: AdditionalAttributes[parameter.Name] = parameter.Value; break; } @@ -47,19 +47,11 @@ public override Task SetParametersAsync(ParameterView parameters) #endregion #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, - (BootstrapClass.Button, true), - (Color.ToDropdownButtonColorClass(), Color != DropdownColor.None), - (Size.ToDropdownButtonSizeClass(), Size != DropdownSize.None)); - + /// /// Gets or sets the content to be rendered within the component. /// - [Parameter] - public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } /// /// Gets or sets the dropdown action button color. @@ -67,8 +59,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [CascadingParameter(Name = "Color")] - public DropdownColor Color { get; set; } = DropdownColor.None; + [CascadingParameter(Name = "Color")] public DropdownColor Color { get; set; } = DropdownColor.None; /// /// Gets or sets the disabled. @@ -76,8 +67,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [CascadingParameter(Name = "Disabled")] - public bool Disabled { get; set; } + [CascadingParameter(Name = "Disabled")] public bool Disabled { get; set; } /// /// Gets or sets the dropdown action button size. @@ -85,8 +75,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [CascadingParameter(Name = "Size")] - public DropdownSize Size { get; set; } = DropdownSize.None; + [CascadingParameter(Name = "Size")] public DropdownSize Size { get; set; } = DropdownSize.None; /// /// Gets or sets the dropdown action button tab index. @@ -94,8 +83,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [Parameter] - public int? TabIndex { get; set; } + [Parameter] public int? TabIndex { get; set; } #endregion } diff --git a/blazorbootstrap/Components/Dropdown/DropdownDivider.razor b/blazorbootstrap/Components/Dropdown/DropdownDivider.razor index 87d0fe85f..524026cb8 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownDivider.razor +++ b/blazorbootstrap/Components/Dropdown/DropdownDivider.razor @@ -2,5 +2,5 @@ @inherits BlazorBootstrapComponentBase
  • -
    +
  • diff --git a/blazorbootstrap/Components/Dropdown/DropdownDivider.razor.cs b/blazorbootstrap/Components/Dropdown/DropdownDivider.razor.cs index 9f1d244d2..174830686 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownDivider.razor.cs +++ b/blazorbootstrap/Components/Dropdown/DropdownDivider.razor.cs @@ -6,15 +6,7 @@ namespace BlazorBootstrap; /// Renders a divider within a component, to separate different sections. ///
    public partial class DropdownDivider : BlazorBootstrapComponentBase -{ - #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, (BootstrapClass.DropdownDivider, true)); - - #endregion - +{ #region Methods /// @@ -29,7 +21,6 @@ public override Task SetParametersAsync(ParameterView parameters) { case nameof(Class): Class = (string)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value!; break; - case nameof(Style): Style = (string)parameter.Value; break; default: AdditionalAttributes[parameter.Name] = parameter.Value; break; } } diff --git a/blazorbootstrap/Components/Dropdown/DropdownHeader.razor b/blazorbootstrap/Components/Dropdown/DropdownHeader.razor index c996850e4..399e662fe 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownHeader.razor +++ b/blazorbootstrap/Components/Dropdown/DropdownHeader.razor @@ -2,7 +2,7 @@ @inherits BlazorBootstrapComponentBase
  • -
    +
    @if (ChildContent != null) { @ChildContent diff --git a/blazorbootstrap/Components/Dropdown/DropdownHeader.razor.cs b/blazorbootstrap/Components/Dropdown/DropdownHeader.razor.cs index 17351820d..0e54fc4cb 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownHeader.razor.cs +++ b/blazorbootstrap/Components/Dropdown/DropdownHeader.razor.cs @@ -3,16 +3,11 @@ public partial class DropdownHeader : BlazorBootstrapComponentBase { #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, (BootstrapClass.DropdownHeader, true)); - + /// /// Gets or sets the content to be rendered within the component. /// - [Parameter] - public RenderFragment? ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } #endregion @@ -32,7 +27,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(ChildContent): ChildContent = (RenderFragment)parameter.Value; break; case nameof(Class): Class = (string)parameter.Value; break; case nameof(Id): Id = (string)parameter.Value!; break; - case nameof(Style): Style = (string)parameter.Value; break; default: AdditionalAttributes[parameter.Name] = parameter.Value; break; } } diff --git a/blazorbootstrap/Components/Dropdown/DropdownItem.razor.cs b/blazorbootstrap/Components/Dropdown/DropdownItem.cs similarity index 80% rename from blazorbootstrap/Components/Dropdown/DropdownItem.razor.cs rename to blazorbootstrap/Components/Dropdown/DropdownItem.cs index 0b66d46e7..e02da0c9e 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownItem.razor.cs +++ b/blazorbootstrap/Components/Dropdown/DropdownItem.cs @@ -1,9 +1,12 @@ -namespace BlazorBootstrap; +using Microsoft.AspNetCore.Components.Rendering; +using System.Text; + +namespace BlazorBootstrap; /// /// Represents an item in a /// -public partial class DropdownItem : BlazorBootstrapComponentBase +public sealed class DropdownItem : BlazorBootstrapComponentBase { #region Fields and Constants @@ -109,7 +112,7 @@ private void SetAttributes() if (Target != Target.None) if (!AdditionalAttributes.TryGetValue("target", out _)) - AdditionalAttributes.Add("target", Target.ToTargetString()!); + AdditionalAttributes.Add("target", EnumExtensions.TargetStringMap[Target]); if (Disabled) { @@ -162,7 +165,6 @@ public override Task SetParametersAsync(ParameterView parameters) case nameof(Class): Class = (string)parameter.Value!; break; case nameof(Disabled): Disabled = (bool)parameter.Value!; break; case nameof(Id): Id = (string)parameter.Value!; break; - case nameof(Style): Style = (string)parameter.Value!; break; case nameof(TabIndex): TabIndex = (int?)parameter.Value!; break; case nameof(Target): Target = (Target)parameter.Value!; break; case nameof(To): To = (string?)parameter.Value!; break; @@ -177,14 +179,7 @@ public override Task SetParametersAsync(ParameterView parameters) #endregion - #region Properties, Indexers - - /// - protected override string? ClassNames => - BuildClassNames(Class, - (BootstrapClass.DropdownItem, true), - (BootstrapClass.Active, Active), - (BootstrapClass.Disabled, Disabled)); + #region Properties, Indexers /// /// Gets or sets the dropdown item active state. @@ -192,8 +187,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [Parameter] - public bool Active { get; set; } + [Parameter] public bool Active { get; set; } /// /// Gets or sets the content to be rendered within the component. @@ -201,8 +195,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [Parameter] - public RenderFragment? ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } /// /// If , dropdown item will be disabled. @@ -210,8 +203,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [Parameter] - public bool Disabled { get; set; } + [Parameter] public bool Disabled { get; set; } /// /// Gets or sets the dropdown item tab index. @@ -219,8 +211,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [Parameter] - public int? TabIndex { get; set; } + [Parameter] public int? TabIndex { get; set; } /// /// Gets or sets the target of dropdown item (if is ). @@ -228,8 +219,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [Parameter] - public Target Target { get; set; } = Target.None; + [Parameter] public Target Target { get; set; } = Target.None; /// /// Get or sets the link href attribute (if is ). @@ -237,8 +227,7 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [Parameter] - public string? To { get; set; } + [Parameter] public string? To { get; set; } /// /// Gets or sets the dropdown item type. @@ -246,8 +235,37 @@ public override Task SetParametersAsync(ParameterView parameters) /// /// Default value is . /// - [Parameter] - public DropdownItemType Type { get; set; } = DropdownItemType.Button; + [Parameter] public DropdownItemType Type { get; set; } = DropdownItemType.Button; #endregion + + /// + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + var classBuilder = new StringBuilder(BootstrapClass.DropdownItem); + if (Active) + { + classBuilder.Append(' ').Append(BootstrapClass.Active); + } + + if (Disabled) + { + classBuilder.Append(' ').Append(BootstrapClass.Disabled); + } + + classBuilder.Append(' ').Append(Class); + + builder.OpenElement(0, "li"); + builder.OpenElement(1, Type == DropdownItemType.Link ? "a" : "button"); + builder.AddAttribute(2, "id", Id); + builder.AddAttribute(3, "class", classBuilder.ToString()); + builder.AddMultipleAttributes(4, AdditionalAttributes); + builder.AddElementReferenceCapture(5, value => Element = value); + if (ChildContent != null) + { + builder.AddContent(6, ChildContent); + } + builder.CloseElement(); + builder.CloseElement(); + } } diff --git a/blazorbootstrap/Components/Dropdown/DropdownItem.razor b/blazorbootstrap/Components/Dropdown/DropdownItem.razor deleted file mode 100644 index ff3b5aa74..000000000 --- a/blazorbootstrap/Components/Dropdown/DropdownItem.razor +++ /dev/null @@ -1,33 +0,0 @@ -@namespace BlazorBootstrap -@inherits BlazorBootstrapComponentBase - -
  • - @if (Type == DropdownItemType.Link) - { - - @if (ChildContent != null) - { - @ChildContent - } - - } - else - { - - } -
  • diff --git a/blazorbootstrap/Components/Dropdown/DropdownMenu.razor b/blazorbootstrap/Components/Dropdown/DropdownMenu.razor index 30c6b4548..2b0324c33 100644 --- a/blazorbootstrap/Components/Dropdown/DropdownMenu.razor +++ b/blazorbootstrap/Components/Dropdown/DropdownMenu.razor @@ -1,7 +1,7 @@ @namespace BlazorBootstrap @inherits BlazorBootstrapComponentBase -