BlazorSpinner is a loading spinner that can be included in Blazor applications. It has a simple service that can be called to "show" or "hide" the spinner.
Demo link: https://red-bay-06d0ccf10.1.azurestaticapps.net
This is a screen shot of the spinner
Review the demo project for details on how to implement the spinner.
- Install the library from Nuget: https://www.nuget.org/packages/BlazorSpinner/
- Add "
@using BlazorSpinner
" in your _Imports.razor - Add "
builder.Services.AddScoped<SpinnerService>();
" in your Program.cs file - Add "
<Spinner></Spinner>
" to your MainLayout.razor file - On any page you want to call the spinner from, inject the SpinnerService into it:
@inject BlazorSpinner.SpinnerService _spinnerService
- Call
_spinnerService.Show()
or_spinnerService.Hide()
to "Show" or "Hide" the spinner.
Call the spinner on any long-running calls or processes (such as API calls).
You can use your own SVG for the loading icon, instead of the default spinner.
- Copy your SVG file into the 'wwwroot' of your application.
- In the MainLayout.razor, set the 'Type' parameter to 'SpinnerType.Icon' for the Spinner component.
- In the MainLayout.razor, set the 'Icon' parameter to the path to your SVG file.
- Example:
<Spinner Type="@SpinnerType.Icon" Icon="loading.svg"></Spinner>
You can use your own SVG for the loading icon, instead of the default spinner.
- In the MainLayout.razor, set the 'Type' parameter to 'SpinnerType.Text' for the Spinner component.
- In the MainLayout.razor, set the 'Text' parameter to the text you want
- Example:
<Spinner Type="@SpinnerType.Text" Text="Processing...""></Spinner>
The 'Loading' component and service have been merged with the 'Spinner' componet and service. Applications that have previously used the 'Loading' component and service need to be updated to use the 'Spinner' component and service.