Skip to content

Commit

Permalink
(not finished) Reworked components to remove useless checks, bloats, …
Browse files Browse the repository at this point in the history
…class name stacks, switch statements replaced with dictionaries. Need some drilling for potential bugs
  • Loading branch information
Lucasharskamp committed Dec 10, 2024
1 parent 25208e8 commit ab28b35
Show file tree
Hide file tree
Showing 168 changed files with 2,992 additions and 2,289 deletions.
4 changes: 1 addition & 3 deletions BlazorBootstrap.Demo.RCL/Components/Shared/Demo.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions BlazorBootstrap.Demo.RCL/Components/Shared/Section.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<section @ref="@Element"
id="@Id"
class="@ClassNames"
style="@StyleNames"
class="@Class"

@attributes="@AdditionalAttributes">

@if (Size == HeadingSize.H2)
Expand Down
68 changes: 0 additions & 68 deletions BlazorBootstrap.Demo.RCL/Enums/LanguageCode.cs

This file was deleted.

20 changes: 10 additions & 10 deletions BlazorBootstrap.Demo.RCL/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand All @@ -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
};
}
2 changes: 1 addition & 1 deletion blazorbootstrap/Components/Accordion/Accordion.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@inherits BlazorBootstrapComponentBase

<CascadingValue Value="@(this)" IsFixed="true">
<div @ref="@Element" id="@Id" class="@ClassNames" style="@StyleNames" @attributes="@AdditionalAttributes">
<div @ref="@Element" id="@Id" class="@BootstrapClass.Accordion @(Flush ? BootstrapClass.AccordionFlush : "") @Class" @attributes="@AdditionalAttributes">
@if (ChildContent != null)
{
@ChildContent
Expand Down
22 changes: 3 additions & 19 deletions blazorbootstrap/Components/Accordion/Accordion.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ public partial class Accordion : BlazorBootstrapComponentBase
#endregion

#region Methods

/// <inheritdoc />
protected override async ValueTask DisposeAsyncCore(bool disposing)
{
if (disposing) items = null;

await base.DisposeAsyncCore(disposing);
}


/// <summary>
/// Hides the <see cref="AccordionItem" /> by index.
/// </summary>
Expand Down Expand Up @@ -188,7 +180,6 @@ public override Task SetParametersAsync(ParameterView parameters)
case nameof(OnHiding): OnHiding = (EventCallback<AccordionEventArgs>)parameter.Value; break;
case nameof(OnShowing): OnShowing = (EventCallback<AccordionEventArgs>)parameter.Value; break;
case nameof(OnShown): OnShown = (EventCallback<AccordionEventArgs>)parameter.Value; break;
case nameof(Style): Style = (string)parameter.Value; break;
default:
AdditionalAttributes![parameter.Name] = parameter.Value;
break;
Expand All @@ -200,13 +191,7 @@ public override Task SetParametersAsync(ParameterView parameters)

#endregion

#region Properties, Indexers

/// <inheritdoc />
protected override string? ClassNames =>
BuildClassNames(Class,
(BootstrapClass.Accordion, true),
(BootstrapClass.AccordionFlush, Flush));
#region Properties, Indexers

/// <summary>
/// If <see langword="true" />, accordion items stay open when another item is opened.
Expand All @@ -233,8 +218,7 @@ public override Task SetParametersAsync(ParameterView parameters)
/// <remarks>
/// Default value is <see langword="false" />.
/// </remarks>
[Parameter]
public bool Flush { get; set; }
[Parameter] public bool Flush { get; set; }

/// <summary>
/// This event is fired when an accordion item has been hidden from the user (will wait for CSS transitions to complete).
Expand Down
2 changes: 1 addition & 1 deletion blazorbootstrap/Components/Accordion/AccordionItem.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@namespace BlazorBootstrap
@inherits BlazorBootstrapComponentBase

<div @ref="@Element" id="@Id" class="@ClassNames" style="@StyleNames" @attributes="@AdditionalAttributes">
<div @ref="@Element" id="@Id" class="@BootstrapClass.AccordionItem @Class" @attributes="@AdditionalAttributes">
<h2 class="accordion-header">
<button class="accordion-button @ButtonCollapsedStateCssClass" type="button" @onclick="(async() => await ToggleAsync())">
@if (TitleTemplate is not null)
Expand Down
10 changes: 2 additions & 8 deletions blazorbootstrap/Components/Accordion/AccordionItem.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public override Task SetParametersAsync(ParameterView parameters)
case nameof(Id): Id = (string)parameter.Value; break;
case nameof(Name): Name = (string)parameter.Value; break;
case nameof(Parent): Parent = (Accordion)parameter.Value; break;
case nameof(Style): Style = (string)parameter.Value; break;
case nameof(Title): Title = (string)parameter.Value; break;
case nameof(TitleTemplate): TitleTemplate = (RenderFragment)parameter.Value; break;
default:
Expand All @@ -95,19 +94,14 @@ public override Task SetParametersAsync(ParameterView parameters)
#endregion

#region Properties, Indexers

/// <inheritdoc />
protected override string? ClassNames =>
BuildClassNames(Class, (BootstrapClass.AccordionItem, true));


/// <summary>
/// Gets or sets the active state.
/// </summary>
/// <remarks>
/// Default value is <see langword="false" />.
/// </remarks>
[Parameter]
public bool Active { get; set; }
[Parameter] public bool Active { get; set; }

private string ButtonCollapsedStateCssClass => isCollapsed ? "collapsed" : string.Empty;

Expand Down
2 changes: 1 addition & 1 deletion blazorbootstrap/Components/Alert/Alert.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@namespace BlazorBootstrap
@inherits BlazorBootstrapComponentBase

<div @ref="@Element" id="@Id" class="@ClassNames" style="@StyleNames" role="alert" @attributes="@AdditionalAttributes">
<div @ref="@Element" id="@Id" class="@BootstrapClass.Alert @EnumExtensions.AlertColorClassMap[Color] @(Dismissable ? BootstrapClass.AlertDismissable : "") @Class" role="alert" @attributes="@AdditionalAttributes">
@if (ChildContent != null)
{
@ChildContent
Expand Down
11 changes: 1 addition & 10 deletions blazorbootstrap/Components/Alert/Alert.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public override Task SetParametersAsync(ParameterView parameters)
case nameof(Id): Id = (string)parameter.Value; break;
case nameof(OnClose): OnClose = (EventCallback)parameter.Value; break;
case nameof(OnClosed): OnClosed = (EventCallback)parameter.Value; break;
case nameof(Style): Style = (string)parameter.Value; break;

default:
AdditionalAttributes![parameter.Name] = parameter.Value;
break;
Expand All @@ -101,14 +99,7 @@ public override Task SetParametersAsync(ParameterView parameters)
#endregion

#region Properties, Indexers

/// <inheritdoc />
protected override string? ClassNames =>
BuildClassNames(Class,
(BootstrapClass.Alert, true),
(Color.ToAlertColorClass(), Color != AlertColor.None),
(BootstrapClass.AlertDismisable, Dismissable));


/// <summary>
/// Gets or sets the content to be rendered within the component.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion blazorbootstrap/Components/Badge/Badge.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@namespace BlazorBootstrap
@inherits BlazorBootstrapComponentBase

<span @ref="@Element" id="@Id" class="@ClassNames" style="@StyleNames" @attributes="@AdditionalAttributes">
<span @ref="@Element" id="@Id" class="@BootstrapClass.Badge @(ChildContent is null ? "p-2" : "") @EnumExtensions.BadgeColorClassMap[Color] @EnumExtensions.BadgeIndicatorClassMap[IndicatorType] @EnumExtensions.PositionClassMap[Position] @EnumExtensions.BadgePlacementClassMap[Placement] @Class" @attributes="@AdditionalAttributes">
@if (ChildContent != null)
{
@ChildContent
Expand Down
31 changes: 7 additions & 24 deletions blazorbootstrap/Components/Badge/Badge.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,55 @@ namespace BlazorBootstrap;
/// </summary>
public partial class Badge : BlazorBootstrapComponentBase
{
#region Properties, Indexers

/// <inheritdoc />
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

/// <summary>
/// Gets or sets the content to be rendered within the component.
/// </summary>
/// <remarks>
/// Default value is <see langword="null" />.
/// </remarks>
[Parameter]
public RenderFragment? ChildContent { get; set; }
[Parameter] public RenderFragment? ChildContent { get; set; }

/// <summary>
/// Gets or sets the badge color.
/// </summary>
/// <remarks>
/// Default value is <see cref="BadgeColor.Secondary" />.
/// </remarks>
[Parameter]
public BadgeColor Color { get; set; } = BadgeColor.Secondary;
[Parameter] public BadgeColor Color { get; set; } = BadgeColor.Secondary;

/// <summary>
/// Gets or sets the badge indicator.
/// </summary>
/// <remarks>
/// Default value is <see cref="BadgeIndicatorType.None" />.
/// </remarks>
[Parameter]
public BadgeIndicatorType IndicatorType { get; set; } = BadgeIndicatorType.None;
[Parameter] public BadgeIndicatorType IndicatorType { get; set; } = BadgeIndicatorType.None;

/// <summary>
/// Gets or sets the badge placement.
/// </summary>
/// <remarks>
/// Default value is <see cref="BadgePlacement.None" />.
/// </remarks>
[Parameter]
public BadgePlacement Placement { get; set; } = BadgePlacement.None;
[Parameter] public BadgePlacement Placement { get; set; } = BadgePlacement.None;

/// <summary>
/// Gets or sets the badge position.
/// </summary>
/// <remarks>
/// Default value is <see cref="Position.None" />.
/// </remarks>
[Parameter]
public Position Position { get; set; } = Position.None;
[Parameter] public Position Position { get; set; } = Position.None;

/// <summary>
/// Gets or sets the visually hidden text.
/// </summary>
/// <remarks>
/// Default value is <see langword="null" />.
/// </remarks>
[Parameter]
public string VisuallyHiddenText { get; set; } = default!;
[Parameter] public string VisuallyHiddenText { get; set; } = default!;

#endregion

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion blazorbootstrap/Components/Breadcrumb/Breadcrumb.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@if (Items != null && Items.Any())
{
<nav @ref="@Element" id="@Id" class="@ClassNames" style="@StyleNames" @attributes="@AdditionalAttributes" aria-label="breadcrumb">
<nav @ref="@Element" id="@Id" class="@Class" @attributes="@AdditionalAttributes" aria-label="breadcrumb">
<ol class="breadcrumb">
@foreach (var item in Items)
{
Expand Down
2 changes: 0 additions & 2 deletions blazorbootstrap/Components/Breadcrumb/Breadcrumb.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,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(Items): Items = (IReadOnlyCollection<BreadcrumbItem>?)parameter.Value; break;
case nameof(Style): Style = (string)parameter.Value; break;

default:
AdditionalAttributes![parameter.Name] = parameter.Value;
break;
Expand Down
Loading

0 comments on commit ab28b35

Please sign in to comment.