Skip to content

Commit

Permalink
Merge pull request #2 from BlazingMahi/spinner-features
Browse files Browse the repository at this point in the history
Add feature spinner position
  • Loading branch information
tylerwp authored Jan 15, 2021
2 parents 05bea25 + b0eba75 commit 99d5cdc
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 113 deletions.
Binary file added spinner-pos-only.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spinner-pos.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 45 additions & 45 deletions src/BlazingMahi.Mbutton/BlazingMahi.Mbutton.csproj
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
<Authors>Tyler Parkerson</Authors>
<Company />
<Product />
<Version>0.3.0</Version>
<Description>Free Blazor button component that provides the ability to disable the button when clicked.
Other features: Show loading animation on click and set delay after click.</Description>
<Copyright>Copyright 2020 (c) Tyler Parkerson. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/BlazingMahi/Mbutton</PackageProjectUrl>
<RepositoryUrl>https://github.com/BlazingMahi/Mbutton</RepositoryUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>BlazoingMahiLogo.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>0.3.0.0</AssemblyVersion>
<FileVersion>0.3.0.0</FileVersion>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.8" />
</ItemGroup>


<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>


<ItemGroup>
<None Include="..\..\BlazoingMahiLogo.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
<Authors>Tyler Parkerson</Authors>
<Company />
<Product />
<Version>0.4.0</Version>
<Description>Free Blazor button component that provides the ability to disable the button when clicked.
Other features: Show loading animation on click and set delay after click.</Description>
<Copyright>Copyright 2020 (c) Tyler Parkerson. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/BlazingMahi/Mbutton</PackageProjectUrl>
<RepositoryUrl>https://github.com/BlazingMahi/Mbutton</RepositoryUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>BlazoingMahiLogo.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>0.4.0.0</AssemblyVersion>
<FileVersion>0.4.0.0</FileVersion>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.8" />
</ItemGroup>


<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>


<ItemGroup>
<None Include="..\..\BlazoingMahiLogo.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
160 changes: 92 additions & 68 deletions src/BlazingMahi.Mbutton/Mbutton.razor
Original file line number Diff line number Diff line change
@@ -1,68 +1,92 @@
<button type="@Type" class="@Class" disabled="@Disabled" @onclick="ButtonClicked">
@((MarkupString)Spinner) @ChildContent
</button>

@code {

/// <summary>
/// Defaults to button.
/// </summary>
[Parameter]
public string Type { get; set; } = "button";

[Parameter]
public string Class { get; set; }

[Parameter]
public RenderFragment ChildContent { get; set; }

[Parameter]
public bool DisableOnClick { get; set; } = false;

[Parameter]
public EventCallback OnClick { get; set; }

[Parameter]
public bool SpinnerOnDisabled { get; set; } = false;

[Parameter]
public string SpinnerClass { get; set; } = "spinner-border spinner-border-sm";

[Parameter]
public int Delay { get; set; } = 10;

public bool Disabled = false;
public string Spinner = "";

private async Task ButtonClicked()
{
if (DisableOnClick)
{
Disabled = true;
if (SpinnerOnDisabled)
{
Spinner = $@"<span class=""{SpinnerClass}"" aria-hidden=""true""></span>";
}
}
await Task.Delay(Delay);
await OnClick.InvokeAsync("clicked");
}

public void EnableButton()
{
Disabled = false;
if (SpinnerOnDisabled){Spinner = "";}
StateHasChanged();
}

public void DisableButton()
{
Disabled = true;
if (SpinnerOnDisabled)
{
Spinner = $@"<span class=""{SpinnerClass}"" aria-hidden=""true""></span>";
}
StateHasChanged();
}

}
<button type="@Type" class="@Class" disabled="@Disabled" @onclick="ButtonClicked">
@((MarkupString)Spinner) @if (!Hide){ @ChildContent } @((MarkupString)SpinnerRight)
</button>

@code {

[Parameter]
public string Type { get; set; } = "button";

[Parameter]
public string Class { get; set; }

[Parameter]
public RenderFragment ChildContent { get; set; }

[Parameter]
public bool DisableOnClick { get; set; } = false;

[Parameter]
public EventCallback OnClick { get; set; }

[Parameter]
public bool SpinnerOnDisabled { get; set; } = false;

[Parameter]
public string SpinnerClass { get; set; } = "spinner-border spinner-border-sm";

[Parameter]
public int Delay { get; set; } = 10;

[Parameter]
public SpinnerPosition spinnerPosition { get; set; } = SpinnerPosition.Left;

public bool Disabled = false;
public bool Hide = false;
public string Spinner = "";
public string SpinnerRight = "";

public enum SpinnerPosition
{
Left,
Right,
Only
}

private async Task ButtonClicked()
{
if (DisableOnClick)
{
Disabled = true;
SetSpinView();
}
await Task.Delay(Delay);
await OnClick.InvokeAsync("clicked");
}

public void EnableButton()
{
Disabled = false;
if (SpinnerOnDisabled){Spinner = "";SpinnerRight = ""; }
Hide = false;
StateHasChanged();
}

public void DisableButton()
{
Disabled = true;
SetSpinView();
StateHasChanged();
}

void SetSpinView()
{
if (SpinnerOnDisabled)
{
if (spinnerPosition == SpinnerPosition.Right)
{
SpinnerRight = $@" <span class=""{SpinnerClass}"" aria-hidden=""true""></span>";
}
else if (spinnerPosition == SpinnerPosition.Only)
{
Hide = true;
Spinner = $@"<span class=""{SpinnerClass}"" aria-hidden=""true""></span> ";
}
else
{
Spinner = $@"<span class=""{SpinnerClass}"" aria-hidden=""true""></span> ";
}
}
}

}

0 comments on commit 99d5cdc

Please sign in to comment.