-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from BlazingMahi/spinner-features
Add feature spinner position
- Loading branch information
Showing
4 changed files
with
137 additions
and
113 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> "; | ||
} | ||
} | ||
} | ||
|
||
} |