Skip to content

Commit

Permalink
https://github.com/wzxinchen/Blazui/issues/42
Browse files Browse the repository at this point in the history
  • Loading branch information
wzxinchen committed Dec 27, 2019
1 parent 506b20d commit 8a3f7db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 35 deletions.
36 changes: 1 addition & 35 deletions src/Blazui.Component/Button/BButton.razor
Original file line number Diff line number Diff line change
@@ -1,47 +1,13 @@
@inherits BButtonBase
@{
var isPlain = string.Empty;
if (IsPlain)
{
isPlain = "is-plain";
}
var isRound = string.Empty;
if (IsRound)
{
isRound = "is-round";
}
var isDisabled = string.Empty;
if (IsDisabled)
{
isDisabled = "is-disabled";
}

var icon = Icon;
var isLoading = string.Empty;
if (IsLoading)
{
isLoading = "is-loading";
isDisabled = "is-disabled";
icon = "el-icon-loading";
}

var buttonSize = string.Empty;
switch (Size)
{
case ButtonSize.Default:

break;
default:
buttonSize = Size.ToString().ToLower();
break;
}
var cls = $"el-button el-button--{Type.ToString().ToLower()} {isPlain} {isRound} {isDisabled} {isLoading} el-button--{buttonSize}";
if (!string.IsNullOrWhiteSpace(Cls))
{
cls = Cls;
}
}
<button type="button" @onclick="OnButtonClickedAsync" style="@Style" class="@cls">
<button type="button" @onclick="OnButtonClickedAsync" style="@Style" class="@cssClassBuilder">
@if (string.IsNullOrWhiteSpace(icon))
{
<span>@ChildContent</span>
Expand Down
17 changes: 17 additions & 0 deletions src/Blazui.Component/Button/BButtonBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Blazui.Component.Button
{
public class BButtonBase : BComponentBase
{
internal HtmlPropertyBuilder cssClassBuilder;
protected async Task OnButtonClickedAsync(MouseEventArgs e)
{
if (IsDisabled)
Expand Down Expand Up @@ -58,5 +59,21 @@ protected override bool ShouldRender()
{
return true;
}

protected override void OnParametersSet()
{
base.OnParametersSet();
if (IsLoading)
{
IsDisabled = true;
}
cssClassBuilder = HtmlPropertyBuilder.CreateCssClassBuilder()
.Add($"el-button", $"el-button--{Type.ToString().ToLower()}", $"el-button--{Size.ToString().ToLower()}", Cls)
.AddIf(IsPlain, "is-plain")
.AddIf(IsRound, "is-round")
.AddIf(IsDisabled, "is-disabled")
.AddIf(IsLoading, "is-loading")
.AddIf(IsCircle, "is-circle");
}
}
}

0 comments on commit 8a3f7db

Please sign in to comment.