Aggiunta componente MultiButton
This commit is contained in:
@@ -183,6 +183,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-3">
|
||||
<div class="card">
|
||||
<div class="card-header"><h4>Test RadioButtons</h4></div>
|
||||
<div class="card-body">
|
||||
<div>Multi</div>
|
||||
<MultiButton ListValues="@ListButtons" EC_ValueChanged="SaveRBLSel"></MultiButton>
|
||||
<div>Single</div>
|
||||
<MultiButton ListValues="@ListChecks" ClassSel="btn-warning" ClassDesel="btn-secondary opacity-50" EC_ValueChanged="SaveRBLSel" MultiSel="false"></MultiButton>
|
||||
<hr />
|
||||
<p>@valSel</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
@@ -201,6 +214,11 @@
|
||||
|
||||
@code {
|
||||
|
||||
protected void SaveRBLSel(MultiButton.ItemData newVal)
|
||||
{
|
||||
valSel = $"{newVal.Text}: sel: {newVal.Selected}";
|
||||
}
|
||||
|
||||
Toggler.SelectGlobalToggle TogFilter { get; set; } = new Toggler.SelectGlobalToggle();
|
||||
protected string textToCopy = $"{Guid.NewGuid()}";
|
||||
protected decimal valDecimale = 12345;
|
||||
@@ -233,14 +251,42 @@
|
||||
NavMan.LocationChanged += LocationChanged;
|
||||
// toggler!
|
||||
TogFilter = new()
|
||||
{
|
||||
isActive = true,
|
||||
leftString = "opzione sx",
|
||||
rightString = "opzione dx"
|
||||
};
|
||||
{
|
||||
isActive = true,
|
||||
leftString = "opzione sx",
|
||||
rightString = "opzione dx"
|
||||
};
|
||||
|
||||
//test input
|
||||
numero = rnd.Next(100, 300);
|
||||
|
||||
// preparo buttons
|
||||
ListButtons = new List<MultiButton.ItemData>();
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
ListButtons.Add(new MultiButton.ItemData()
|
||||
{
|
||||
CodItem = $"B{i:00}",
|
||||
Ordinal = i,
|
||||
Selected = false,
|
||||
Text = $"Btn_{i:00}",
|
||||
Tooltip = $"Toggle Button {i:00}"
|
||||
});
|
||||
}
|
||||
|
||||
// preparo checks
|
||||
ListChecks = new List<MultiButton.ItemData>();
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
ListChecks.Add(new MultiButton.ItemData()
|
||||
{
|
||||
CodItem = $"B{i:00}",
|
||||
Ordinal = i,
|
||||
Selected = false,
|
||||
Text = $"Chk_{i:00}",
|
||||
Tooltip = $"Switch {i:00}"
|
||||
});
|
||||
}
|
||||
}
|
||||
async void LocationChanged(object sender, LocationChangedEventArgs e)
|
||||
{
|
||||
@@ -253,4 +299,10 @@
|
||||
{
|
||||
NavMan.LocationChanged -= LocationChanged;
|
||||
}
|
||||
|
||||
|
||||
private List<MultiButton.ItemData>? ListButtons = null;
|
||||
private string valSel = "";
|
||||
private List<MultiButton.ItemData>? ListChecks = null;
|
||||
private string checkSel = "";
|
||||
}
|
||||
|
||||
@@ -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