using System.Diagnostics.CodeAnalysis; using Connected.Utilities; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; namespace Connected.Components; public partial class TableGroupRow<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T> : UIComponent { protected string HeaderClassname => new CssBuilder("mud-table-row") .AddClass(HeaderClass) .AddClass($"mud-table-row-group-indented-{GroupDefinition?.Level - 1}", (GroupDefinition?.Indentation ?? false) && GroupDefinition?.Level > 1).Build(); protected string FooterClassname => new CssBuilder("mud-table-row") .AddClass(FooterClass) .AddClass($"mud-table-row-group-indented-{GroupDefinition?.Level - 1}", (GroupDefinition?.Indentation ?? false) && GroupDefinition?.Level > 1).Build(); protected string ActionsStylename => new StyleBuilder() .AddStyle("padding-left", "34px", GroupDefinition?.IsParentExpandable ?? false).Build(); [CascadingParameter] public TableContext Context { get; set; } private IEnumerable> _innerGroupItems = null; /// /// The group definition for this grouping level. It's recursive. /// [Parameter] public TableGroupDefinition GroupDefinition { get; set; } IGrouping _items = null; /// /// Inner Items List for the Group /// [Parameter] public IGrouping Items { get => _items; set { _items = value; SyncInnerGroupItems(); } } /// /// Defines Group Header Data Template /// [Parameter] public RenderFragment> HeaderTemplate { get; set; } /// /// Defines Group Header Data Template /// [Parameter] public RenderFragment> FooterTemplate { get; set; } /// /// Add a multi-select checkbox that will select/unselect every item in the table /// [Parameter] public bool IsCheckable { get; set; } [Parameter] public string HeaderClass { get; set; } [Parameter] public string FooterClass { get; set; } [Parameter] public string HeaderStyle { get; set; } [Parameter] public string FooterStyle { get; set; } /// /// Custom expand icon. /// [Parameter] public string ExpandIcon { get; set; } = Icons.Material.Filled.ExpandMore; /// /// Custom collapse icon. /// [Parameter] public string CollapseIcon { get; set; } = Icons.Material.Filled.ChevronRight; /// /// On click event /// [Parameter] public EventCallback OnRowClick { get; set; } private bool _checked; public bool IsChecked { get => _checked; set { if (value != _checked) { _checked = value; if (IsCheckable) Table.OnGroupHeaderCheckboxClicked(value, Items.ToList()); } } } public bool IsExpanded { get; internal set; } = true; protected override Task OnInitializedAsync() { if (GroupDefinition != null) { IsExpanded = GroupDefinition.IsInitiallyExpanded; ((TableContext)Context)?.GroupRows.Add(this); SyncInnerGroupItems(); } return base.OnInitializedAsync(); } private void SyncInnerGroupItems() { if (GroupDefinition.InnerGroup != null) { _innerGroupItems = Table?.GetItemsOfGroup(GroupDefinition.InnerGroup, Items); } } public void Dispose() { ((TableContext)Context)?.GroupRows.Remove(this); } public void SetChecked(bool b, bool notify) { if (notify) IsChecked = b; else { _checked = b; if (IsCheckable) InvokeAsync(StateHasChanged); } } private Table Table { get => (Table)((TableContext)Context)?.Table; } }