@using System.Timers
@code {
///
/// The event to call in the parent when the button is clicked.
///
[Parameter]
public EventCallback OnClick { get; set; }
///
/// The text to display on the button.
///
[Parameter]
public required string ButtonText { get; set; }
///
/// The color theme of the button.
///
[Parameter]
public string Color { get; set; } = "primary";
///
/// Additional CSS classes to apply to the button.
///
[Parameter]
public string AdditionalClasses { get; set; } = "";
///
/// Indicates whether the button is currently in a refreshing state.
///
private bool IsRefreshing;
///
/// Timer used to control the refreshing state duration.
///
private Timer Timer = new();
///
/// Handles the button click event.
///
private async Task HandleClick()
{
if (IsRefreshing) return;
IsRefreshing = true;
await OnClick.InvokeAsync();
Timer = new Timer(500);
Timer.Elapsed += (sender, args) =>
{
IsRefreshing = false;
Timer.Dispose();
InvokeAsync(StateHasChanged);
};
Timer.Start();
}
///
/// Gets the CSS classes for the refresh icon based on the refreshing state.
///
/// A string containing the CSS classes for the icon.
private string GetIconClasses()
{
return $"w-4 h-4 {(IsRefreshing ? "animate-spin-ccw" : "")}";
}
}