Aggiunta componente MultiButton
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<div class="btn-group" role="group">
|
||||
@foreach (var item in ListValuesOrd)
|
||||
{
|
||||
<button type="button" class="btn btn-sm @btnSel(item.Selected)" @onclick="() => ToggleVal(item)" Title="@item.Tooltip">@item.Text</button>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
#region Public Properties
|
||||
|
||||
[Parameter]
|
||||
public string ClassDesel { get; set; } = "btn-secondary";
|
||||
|
||||
[Parameter]
|
||||
public string ClassSel { get; set; } = "btn-primary";
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<ItemData> EC_ValueChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public List<ItemData> ListValues { get; set; } = new List<ItemData>();
|
||||
|
||||
/// <summary>
|
||||
/// Indica se sia possibile selezionare + valori
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool MultiSel { get; set; } = true;
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Classes
|
||||
|
||||
public class ItemData
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public string CodItem { get; set; } = "";
|
||||
public int Ordinal { get; set; } = 0;
|
||||
public bool Selected { get; set; } = false;
|
||||
public string Text { get; set; } = "";
|
||||
public string Tooltip { get; set; } = "";
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
#endregion Public Classes
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected List<ItemData> ListValuesOrd
|
||||
{
|
||||
get => ListValues.OrderBy(x => x.Ordinal).ToList() ?? new List<ItemData>();
|
||||
}
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string btnSel(bool selected)
|
||||
{
|
||||
return selected ? ClassSel : ClassDesel;
|
||||
}
|
||||
|
||||
private async void ToggleVal(ItemData currItem)
|
||||
{
|
||||
currItem.Selected = MultiSel ? !currItem.Selected : true;
|
||||
// se non abilitata sel multipla
|
||||
if (!MultiSel)
|
||||
{
|
||||
// deseleziono gli altri...
|
||||
foreach (var item in ListValues)
|
||||
{
|
||||
if (!item.CodItem.Equals(currItem.CodItem))
|
||||
{
|
||||
item.Selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
await EC_ValueChanged.InvokeAsync(currItem);
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
Reference in New Issue
Block a user