Skip to content

Commit

Permalink
feat(blazorui): update BitButtonGroup with new BitColor enum #7967 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
msynk authored Jul 8, 2024
1 parent 92e16d6 commit 9937782
Show file tree
Hide file tree
Showing 10 changed files with 878 additions and 817 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
disabled="@(isEnabled is false)"
aria-disabled="@(isEnabled is false)"
style="@GetStyle(item)"
class="bit-btg-itm@(GetItemClass(i, isEnabled)) @GetClass(item)">
class="bit-btg-itm @GetClass(item)">
@if (template is not null)
{
@template(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public partial class BitButtonGroup<TItem> : BitComponentBase where TItem : clas
{
private bool vertical;
private BitSize? size;
private BitColor? color;
private BitVariant? variant;
private BitSeverity? severity;

private List<TItem> _items = [];
private IEnumerable<TItem> _oldItems = default!;
Expand All @@ -28,17 +28,17 @@ public partial class BitButtonGroup<TItem> : BitComponentBase where TItem : clas
[Parameter] public RenderFragment? ChildContent { get; set; }

/// <summary>
/// The severity of the button group.
/// Defines the general colors available in the bit BlazorUI.
/// </summary>
[Parameter]
public BitSeverity? Severity
public BitColor? Color
{
get => severity;
get => color;
set
{
if (severity == value) return;
if (color == value) return;

severity = value;
color = value;

ClassBuilder.Reset();
}
Expand Down Expand Up @@ -121,6 +121,7 @@ public bool Vertical
}



internal void RegisterOption(BitButtonGroupOption option)
{
var item = (option as TItem)!;
Expand All @@ -137,6 +138,7 @@ internal void UnregisterOption(BitButtonGroupOption option)
}



protected override string RootElementClass => "bit-btg";

protected override void RegisterCssClasses()
Expand All @@ -149,22 +151,25 @@ protected override void RegisterCssClasses()
_ => "bit-btg-fil"
});

ClassBuilder.Register(() => Severity switch
{
BitSeverity.Info => "bit-btg-inf",
BitSeverity.Success => "bit-btg-suc",
BitSeverity.Warning => "bit-btg-war",
BitSeverity.SevereWarning => "bit-btg-swa",
BitSeverity.Error => "bit-btg-err",
_ => string.Empty
ClassBuilder.Register(() => Color switch
{
BitColor.Primary => "bit-btg-pri",
BitColor.Secondary => "bit-btg-sec",
BitColor.Tertiary => "bit-btg-ter",
BitColor.Info => "bit-btg-inf",
BitColor.Success => "bit-btg-suc",
BitColor.Warning => "bit-btg-wrn",
BitColor.SevereWarning => "bit-btg-swr",
BitColor.Error => "bit-btg-err",
_ => "bit-btg-pri"
});

ClassBuilder.Register(() => Size switch
{
BitSize.Small => "bit-btg-sm",
BitSize.Medium => "bit-btg-md",
BitSize.Large => "bit-btg-lg",
_ => string.Empty
_ => "bit-btg-md"
});

ClassBuilder.Register(() => Vertical ? "bit-btg-vrt" : "");
Expand All @@ -183,54 +188,6 @@ protected override Task OnParametersSetAsync()



private string? GetItemClass(int index, bool isEnabled)
{
StringBuilder className = new StringBuilder();

className.Append(Variant switch
{
BitVariant.Fill => " bit-btg-ifl",
BitVariant.Outline => " bit-btg-iot",
BitVariant.Text => " bit-btg-itx",
_ => " bit-btg-ifl"
});

className.Append(Severity switch
{
BitSeverity.Info => " bit-btg-iin",
BitSeverity.Success => " bit-btg-isu",
BitSeverity.Warning => " bit-btg-iwa",
BitSeverity.SevereWarning => " bit-btg-isw",
BitSeverity.Error => " bit-btg-ier",
_ => string.Empty
});

className.Append(Size switch
{
BitSize.Small => " bit-btg-ism",
BitSize.Medium => " bit-btg-imd",
BitSize.Large => " bit-btg-ilg",
_ => string.Empty
});

if (index == 0)
{
className.Append(" bit-btg-ift");
}

if (index == (_items.Count - 1))
{
className.Append(" bit-btg-ilt");
}

if (isEnabled is false)
{
className.Append(" bit-btg-ids");
}

return className.ToString();
}

private async Task HandleOnItemClick(TItem item)
{
if (GetIsEnabled(item) is false) return;
Expand Down Expand Up @@ -260,7 +217,6 @@ private async Task HandleOnItemClick(TItem item)
}
}


private string? GetClass(TItem? item)
{
if (item is null) return null;
Expand Down
Loading

0 comments on commit 9937782

Please sign in to comment.