mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
43 lines
980 B
Plaintext
43 lines
980 B
Plaintext
|
|
@typeparam T
|
|
|
|
@code {
|
|
[Parameter, EditorRequired]
|
|
public string Label { get; set; } = string.Empty;
|
|
[Parameter, EditorRequired]
|
|
public IEnumerable<T> Options { get; set; } = default!;
|
|
[Parameter, EditorRequired]
|
|
public Func<T?, string?> GetName { get; set; } = default!;
|
|
|
|
[Parameter, EditorRequired]
|
|
public Action<T?> OnSelect { get; set; } = default!;
|
|
|
|
[Parameter, EditorRequired]
|
|
public T? SelectedOption { get; set; }
|
|
|
|
private string htmlLabel => Label.Replace("-", "");
|
|
|
|
private void onSelect(T option)
|
|
{
|
|
SelectedOption = option;
|
|
OnSelect(SelectedOption);
|
|
}
|
|
|
|
private string getButtonClass(T option)
|
|
{
|
|
var partClass = GetName(option) == GetName(SelectedOption) ? "primary" : "outline-primary";
|
|
return $"mx-1 btn btn-{partClass}";
|
|
}
|
|
}
|
|
|
|
<div>
|
|
@foreach(var option in Options)
|
|
{
|
|
<button
|
|
class="@getButtonClass(option)"
|
|
@onclick="() => onSelect(option)"
|
|
>
|
|
@GetName(option)
|
|
</button>
|
|
}
|
|
</div> |