Path: redb/redb.PropsEditor/Components/PropsEditor.razor Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.PropsEditor/Components/PropsEditor.razor ---- @using redb.PropsEditor.Services @using Microsoft.FluentUI.AspNetCore.Components @inject PropsMetadataService MetadataService @typeparam TProps where TProps : class @* Universal property editor for any Props class *@
@if (ShowHeader) {
@GetTypeName() @if (ShowSaveButton) { @(IsSaving ? "Saving..." : "Save") }
}
@if (Value == null) {
No data to edit.
} else { @* Group properties by GroupName *@ @foreach (var group in GetGroupedProperties()) { @if (string.IsNullOrEmpty(group.Key)) { @* Properties without group *@ @foreach (var prop in group) { } } else { @* Collapsible group *@ var groupName = group.Key; var isExpanded = !collapsedGroups.Contains(groupName);
@(isExpanded ? "▼" : "▶") @groupName
@if (isExpanded) {
@foreach (var prop in group) { }
}
} } }
@code { /// /// The Props object to edit. /// [Parameter] public TProps? Value { get; set; } /// /// Called when the value changes. /// [Parameter] public EventCallback ValueChanged { get; set; } /// /// Called when Save button is clicked. /// [Parameter] public EventCallback OnSave { get; set; } /// /// Whether to show the Save button. /// [Parameter] public bool ShowSaveButton { get; set; } = true; /// /// Whether to show the header with type name. /// [Parameter] public bool ShowHeader { get; set; } = true; /// /// Whether save is in progress. /// [Parameter] public bool IsSaving { get; set; } /// /// Property names that should be read-only (in addition to [PropsReadOnly] attribute). /// [Parameter] public HashSet? ReadOnlyPropertyNames { get; set; } /// /// If set, only these properties will be shown (whitelist mode). /// [Parameter] public HashSet? OnlyShowProperties { get; set; } private HashSet collapsedGroups = []; private IEnumerable? properties; protected override void OnParametersSet() { properties = MetadataService.GetProperties(); // Initialize collapsed groups foreach (var prop in properties.Where(p => p.GroupCollapsed && !string.IsNullOrEmpty(p.GroupName))) { collapsedGroups.Add(prop.GroupName!); } } private string GetTypeName() { return typeof(TProps).Name; } private IEnumerable> GetGroupedProperties() { var filtered = properties ?? []; // Whitelist mode - show only specified properties if (OnlyShowProperties?.Count > 0) { filtered = filtered.Where(p => OnlyShowProperties.Contains(p.Name)); } return filtered .GroupBy(p => p.GroupName) .OrderBy(g => string.IsNullOrEmpty(g.Key) ? 0 : 1) .ThenBy(g => g.Key); } private void ToggleGroup(string groupName) { if (collapsedGroups.Contains(groupName)) collapsedGroups.Remove(groupName); else collapsedGroups.Add(groupName); } private async Task HandlePropertyChanged() { if (Value != null) { await ValueChanged.InvokeAsync(Value); } } private async Task HandleSave() { await OnSave.InvokeAsync(); } private bool IsPropertyReadOnly(string propertyName) { return ReadOnlyPropertyNames?.Contains(propertyName) == true; } }