Skip to content

Commit

Permalink
Code cleanup and formatting (#691)
Browse files Browse the repository at this point in the history
* Code cleanup + formatting
  • Loading branch information
gvreddy04 authored Apr 28, 2024
1 parent 3d10693 commit 3b9a839
Show file tree
Hide file tree
Showing 72 changed files with 577 additions and 752 deletions.
13 changes: 6 additions & 7 deletions blazorbootstrap/Components/Accordion/Accordion.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ public partial class Accordion : BlazorBootstrapComponentBase

#region Methods

protected string? ClassNames => new CssClassBuilder(Class)
.AddClass(BootstrapClass.Accordion)
.AddClass(BootstrapClass.AccordionFlush, Flush)
.Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

/// <inheritdoc />
protected override async ValueTask DisposeAsyncCore(bool disposing)
{
Expand Down Expand Up @@ -193,6 +186,12 @@ internal void Add(AccordionItem accordionItem)
[EditorRequired]
public RenderFragment ChildContent { get; set; } = default!;

protected override string? ClassNames =>
new CssClassBuilder(Class)
.AddClass(BootstrapClass.Accordion)
.AddClass(BootstrapClass.AccordionFlush, Flush)
.Build();

/// <summary>
/// Gets or sets the flush.
/// Removes borders and rounded corners to render accordions edge-to-edge with their parent container.
Expand Down
11 changes: 5 additions & 6 deletions blazorbootstrap/Components/Accordion/AccordionItem.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ public partial class AccordionItem : BlazorBootstrapComponentBase

#region Methods

protected string? ClassNames => new CssClassBuilder(Class)
.AddClass(BootstrapClass.AccordionItem)
.Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

protected override void OnInitialized()
{
Id = IdGenerator.GetNextId(); // This is required
Expand Down Expand Up @@ -67,6 +61,11 @@ private async Task OnCollapseShownAsync()

#region Properties, Indexers

protected override string? ClassNames =>
new CssClassBuilder(Class)
.AddClass(BootstrapClass.AccordionItem)
.Build();

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

/// <summary>
Expand Down
17 changes: 8 additions & 9 deletions blazorbootstrap/Components/Alert/Alert.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ public partial class Alert : BlazorBootstrapComponentBase

#region Methods

protected string? ClassNames => new CssClassBuilder(Class)
.AddClass(BootstrapClass.Alert)
.AddClass(Color.ToAlertColorClass(), Color != AlertColor.None)
.AddClass(BootstrapClass.AlertDismisable, Dismissable)
.Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

/// <inheritdoc />
protected override async ValueTask DisposeAsyncCore(bool disposing)
{
Expand Down Expand Up @@ -50,7 +42,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
protected override async Task OnInitializedAsync()
{
objRef ??= DotNetObjectReference.Create(this);

await base.OnInitializedAsync();
}

Expand All @@ -69,6 +61,13 @@ protected override async Task OnInitializedAsync()

#region Properties, Indexers

protected override string? ClassNames =>
new CssClassBuilder(Class)
.AddClass(BootstrapClass.Alert)
.AddClass(Color.ToAlertColorClass(), Color != AlertColor.None)
.AddClass(BootstrapClass.AlertDismisable, Dismissable)
.Build();

/// <summary>
/// Specifies the content to be rendered inside this <see cref="Alert" />.
/// </summary>
Expand Down
25 changes: 10 additions & 15 deletions blazorbootstrap/Components/Badge/Badge.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@

public partial class Badge : BlazorBootstrapComponentBase
{
#region Methods

protected string? ClassNames => new CssClassBuilder(Class)
.AddClass(BootstrapClass.Badge)
.AddClass(Color.ToBadgeColorClass(), Color != BadgeColor.None)
.AddClass(IndicatorType.ToBadgeIndicatorClass(), IndicatorType != BadgeIndicatorType.None)
.AddClass(Position.ToPositionClass(), Position != Position.None)
.AddClass(Placement.ToBadgePlacementClass(), Placement != BadgePlacement.None)
.AddClass("p-2", ChildContent is null)
.Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

#endregion

#region Properties, Indexers

/// <summary>
Expand All @@ -25,6 +10,16 @@ public partial class Badge : BlazorBootstrapComponentBase
[Parameter]
public RenderFragment ChildContent { get; set; } = default!;

protected override string? ClassNames =>
new CssClassBuilder(Class)
.AddClass(BootstrapClass.Badge)
.AddClass(Color.ToBadgeColorClass(), Color != BadgeColor.None)
.AddClass(IndicatorType.ToBadgeIndicatorClass(), IndicatorType != BadgeIndicatorType.None)
.AddClass(Position.ToPositionClass(), Position != Position.None)
.AddClass(Placement.ToBadgePlacementClass(), Placement != BadgePlacement.None)
.AddClass("p-2", ChildContent is null)
.Build();

/// <summary>
/// Gets or sets the badge color.
/// </summary>
Expand Down
4 changes: 0 additions & 4 deletions blazorbootstrap/Components/Breadcrumb/Breadcrumb.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ public partial class Breadcrumb : BlazorBootstrapComponentBase
{
#region Methods

protected string? ClassNames => new CssClassBuilder(Class).Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

protected override ValueTask DisposeAsyncCore(bool disposing)
{
if (disposing)
Expand Down
33 changes: 16 additions & 17 deletions blazorbootstrap/Components/Button/Button.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,18 @@ public partial class Button : BlazorBootstrapComponentBase

private string? previousTo = default!;

private TooltipColor previousTooltipColor = default!;

private string previousTooltipTitle = default!;

private ButtonType previousType;

private bool setButtonAttributesAgain = false;

private TooltipColor previousTooltipColor = default!;

#endregion

#region Methods

protected string? ClassNames => new CssClassBuilder(Class)
.AddClass(BootstrapClass.Button)
.AddClass(Color.ToButtonColorClass(), Color != ButtonColor.None && !Outline)
.AddClass(Color.ToButtonOutlineColorClass(), Color != ButtonColor.None && Outline)
.AddClass(Size.ToButtonSizeClass(), Size != Size.None)
.AddClass(BootstrapClass.ButtonDisabled, Disabled && Type == ButtonType.Link)
.AddClass(BootstrapClass.ButtonActive, Active)
.AddClass(BootstrapClass.ButtonBlock, Block)
.AddClass(BootstrapClass.ButtonLoading!, Loading && LoadingTemplate is not null)
.AddClass(Position.ToPositionClass(), Position != Position.None)
.Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

/// <inheritdoc />
protected override async ValueTask DisposeAsyncCore(bool disposing)
{
Expand Down Expand Up @@ -316,6 +302,19 @@ private void SetAttributes()
[Parameter]
public RenderFragment ChildContent { get; set; } = default!;

protected override string? ClassNames =>
new CssClassBuilder(Class)
.AddClass(BootstrapClass.Button)
.AddClass(Color.ToButtonColorClass(), Color != ButtonColor.None && !Outline)
.AddClass(Color.ToButtonOutlineColorClass(), Color != ButtonColor.None && Outline)
.AddClass(Size.ToButtonSizeClass(), Size != Size.None)
.AddClass(BootstrapClass.ButtonDisabled, Disabled && Type == ButtonType.Link)
.AddClass(BootstrapClass.ButtonActive, Active)
.AddClass(BootstrapClass.ButtonBlock, Block)
.AddClass(BootstrapClass.ButtonLoading!, Loading && LoadingTemplate is not null)
.AddClass(Position.ToPositionClass(), Position != Position.None)
.Build();

/// <summary>
/// Gets or sets the button color.
/// </summary>
Expand All @@ -341,7 +340,7 @@ private void SetAttributes()
public RenderFragment LoadingTemplate { get; set; } = default!;

/// <summary>
/// Gets or sets the loadgin text.
/// Gets or sets the loading text.
/// <see cref="LoadingTemplate" /> takes precedence.
/// </summary>
[Parameter]
Expand Down
29 changes: 14 additions & 15 deletions blazorbootstrap/Components/Callout/Callout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,20 @@ public partial class Callout : BlazorBootstrapComponentBase
{
#region Methods

protected string? ClassNames => new CssClassBuilder(Class)
.AddClass(BootstrapClass.Callout)
.AddClass(Type.ToCalloutTypeClass())
.Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

private string GetHeading()
{
if (!string.IsNullOrWhiteSpace(Heading))
return Heading;

return Type switch
{
CalloutType.Default => "NOTE",
CalloutType.Info => "INFO",
CalloutType.Warning => "WARNING",
CalloutType.Danger => "DANGER",
CalloutType.Tip or CalloutType.Success => "TIP",
_ => ""
};
{
CalloutType.Default => "NOTE",
CalloutType.Info => "INFO",
CalloutType.Warning => "WARNING",
CalloutType.Danger => "DANGER",
CalloutType.Tip or CalloutType.Success => "TIP",

Check warning on line 18 in blazorbootstrap/Components/Callout/Callout.razor.cs

View workflow job for this annotation

GitHub Actions / build

'CalloutType.Tip' is obsolete: 'This enum value is obsolete. Use `Success` instead.'

Check warning on line 18 in blazorbootstrap/Components/Callout/Callout.razor.cs

View workflow job for this annotation

GitHub Actions / build

'CalloutType.Tip' is obsolete: 'This enum value is obsolete. Use `Success` instead.'
_ => ""
};
}

private IconName GetIconName() =>
Expand All @@ -50,6 +43,12 @@ private IconName GetIconName() =>
[Parameter]
public RenderFragment? ChildContent { get; set; }

protected override string? ClassNames =>
new CssClassBuilder(Class)
.AddClass(BootstrapClass.Callout)
.AddClass(Type.ToCalloutTypeClass())
.Build();

private string heading => GetHeading();

/// <summary>
Expand Down
19 changes: 7 additions & 12 deletions blazorbootstrap/Components/Card/Card.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

public partial class Card : BlazorBootstrapComponentBase
{
#region Methods

protected string? ClassNames => new CssClassBuilder(Class)
.AddClass(BootstrapClass.Card)
.AddClass(TextAlignment.ToTextAlignmentClass())
.AddClass(Color.ToCardColorClass())
.Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

#endregion

#region Properties, Indexers

protected override string? ClassNames =>
new CssClassBuilder(Class)
.AddClass(BootstrapClass.Card)
.AddClass(TextAlignment.ToTextAlignmentClass())
.AddClass(Color.ToCardColorClass())
.Build();

/// <summary>
/// Gets or sets the content to be rendered within the component.
/// </summary>
Expand Down
15 changes: 5 additions & 10 deletions blazorbootstrap/Components/Card/CardBody.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

public partial class CardBody : BlazorBootstrapComponentBase
{
#region Methods

protected string? ClassNames => new CssClassBuilder(Class)
.AddClass(BootstrapClass.CardBody)
.Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

#endregion

#region Properties, Indexers

protected override string? ClassNames =>
new CssClassBuilder(Class)
.AddClass(BootstrapClass.CardBody)
.Build();

/// <summary>
/// Gets or sets the content to be rendered within the component.
/// </summary>
Expand Down
15 changes: 5 additions & 10 deletions blazorbootstrap/Components/Card/CardFooter.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

public partial class CardFooter : BlazorBootstrapComponentBase
{
#region Methods

protected string? ClassNames => new CssClassBuilder(Class)
.AddClass(BootstrapClass.CardFooter)
.Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

#endregion

#region Properties, Indexers

protected override string? ClassNames =>
new CssClassBuilder(Class)
.AddClass(BootstrapClass.CardFooter)
.Build();

/// <summary>
/// Gets or sets the content to be rendered within the component.
/// </summary>
Expand Down
15 changes: 5 additions & 10 deletions blazorbootstrap/Components/Card/CardGroup.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

public partial class CardGroup : BlazorBootstrapComponentBase
{
#region Methods

protected string? ClassNames => new CssClassBuilder(Class)
.AddClass(BootstrapClass.CardGroup)
.Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

#endregion

#region Properties, Indexers

protected override string? ClassNames =>
new CssClassBuilder(Class)
.AddClass(BootstrapClass.CardGroup)
.Build();

/// <summary>
/// Gets or sets the content to be rendered within the component.
/// </summary>
Expand Down
17 changes: 6 additions & 11 deletions blazorbootstrap/Components/Card/CardHeader.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

public partial class CardHeader : BlazorBootstrapComponentBase
{
#region Methods

protected string? ClassNames => new CssClassBuilder(Class)
.AddClass(BootstrapClass.CardHeader)
.AddClass(Color.ToCardColorClass())
.Build();

protected string? StyleNames => new CssStyleBuilder(Style).Build();

#endregion

#region Properties, Indexers

protected override string? ClassNames =>
new CssClassBuilder(Class)
.AddClass(BootstrapClass.CardHeader)
.AddClass(Color.ToCardColorClass())
.Build();

/// <summary>
/// Gets or sets the content to be rendered within the component.
/// </summary>
Expand Down
Loading

0 comments on commit 3b9a839

Please sign in to comment.