Foundations
Metadata-driven live editors for Blazor components.
The Configurator system auto-generates interactive live editors from [Configurable] attribute annotations, producing a preview, controls panel, and live code snippet for every component.
Overview
The Configurator is a metadata-driven system that auto-generates interactive live editors for Blazor components. By annotating component [Parameter] properties with the [Configurable] attribute, the system uses reflection to discover editable properties, generates appropriate editor controls, and renders a live preview alongside a code snippet that updates in real time. No manual wiring of editors or code generation is required.
[Configurable] Attribute
Mark any [Parameter] property with [Configurable] to include it in the auto-generated editor. The attribute accepts three optional properties that control how the editor is rendered.
| Property | Type | Description |
|---|---|---|
| Group | string? | UI grouping label (e.g., "Appearance", "Content", "State"). Properties with the same group are rendered together under a shared header. |
| Editor | EditorKind | Override auto-detection of the editor control. Defaults to EditorKind.Auto which infers the editor from the property type. |
| Order | int | Sort order within a group. Lower values appear first. Groups themselves are sorted by their lowest member order. |
| SampleKey | string? | Resource key referencing a localized sample value in the component's .resx file. The AutoConfigurator uses this as the initial preview value instead of the empty default. |
Annotating component parameters
Typical [Configurable] annotations on a component with grouped and ordered parameters.
Opt-in only
Only [Parameter] properties that also carry [Configurable] appear in the editor. Properties without the attribute are ignored, keeping the controls panel focused.
Show code
Copy code
[Parameter]
[Configurable(Group = "Appearance", Order = 1)]
public Color Color { get; set; } = Color.Primary;
[Parameter]
[Configurable(Group = "Appearance", Order = 2)]
public Variant Variant { get; set; } = Variant.Filled;
[Parameter]
[Configurable(Group = "Content", Order = 0, SampleKey = "Sample_Title")]
public string Title { get; set; } = string.Empty;
[Parameter]
[Configurable(Group = "Content", Editor = EditorKind.IconPicker)]
public string? StartIcon { get; set; }
[Parameter]
[Configurable(Group = "State")]
public bool Disabled { get; set; }EditorKind Enum
EditorKind determines which editor control is rendered for a property. When set to Auto (the default), the system detects the appropriate editor from the property type.
| Value | Auto-detection rule | Description |
|---|---|---|
| Auto | Inferred from property type | Default. Resolves to one of the specific editors below based on the property type. |
| Select | Enum | Dropdown select for enum types. Shows all enum values as options with clear support. |
| Checkbox | bool | Toggle checkbox for boolean properties. |
| TextInput | string | Free-text input for string properties. Also used as fallback for unrecognized types. |
| IconPicker | Manual override only | Material Symbols icon picker with search. Must be set explicitly via Editor = EditorKind.IconPicker. |
| NumberInput | int, double, decimal, ... | Numeric input for int, double, decimal, float, long, short, and byte. |
Pipeline
The Configurator follows a four-step pipeline from attribute annotation to rendered output.
[Configurable]
Component authors annotate [Parameter] properties with [Configurable], specifying group, order, and editor overrides.
ConfiguratorMetadata
Reflection engine scans the component type, extracts annotated properties, resolves editor kinds, reads default values, and caches the result.
AutoConfigurator
Generic orchestrator that takes a TComponent, builds editor controls from metadata, manages parameter state, wraps EventCallbacks, and generates code.
Output
Live preview of the component with current parameter values, interactive controls panel, and a code snippet that updates as parameters change.
ConfiguratorMetadata
The reflection engine that powers the Configurator. It extracts all configurable information from a component type and caches it for reuse.
Scans all public instance properties with both [Parameter] and [Configurable] attributes.
Filters out RenderFragment, EventCallback, and their generic variants (RenderFragment<T>, EventCallback<T>).
Resolves EditorKind.Auto based on the property type: bool to Checkbox, Enum to Select, string to TextInput, numeric types to NumberInput.
Caches results per component type in a ConcurrentDictionary for zero-cost repeat access.
Separately discovers EventCallback and EventCallback<T> properties for event visualization chips.
AutoConfigurator Usage
To add an interactive configurator to a demo page, use the AutoConfigurator component. Specify the component type via TComponent, provide any fixed parameters, and supply a PreviewTemplate that renders the component with the current parameter values.
Adding a configurator to a demo page
Minimal AutoConfigurator setup for a Button component with a fixed Text parameter.
Context variable
The Context="cfg" directive exposes a ConfiguratorContext with a Parameters dictionary. Use @attributes="cfg.Parameters" to splat all configurable values onto the component.
Show code
Copy code
<AutoConfigurator TComponent="Button"
FixedParameters="@(new() { ["Text"] = "Button" })"
Context="cfg">
<PreviewTemplate>
<Button Text="Button" @attributes="cfg.Parameters" />
</PreviewTemplate>
</AutoConfigurator>Event Chips
The Configurator automatically discovers all EventCallback and EventCallback<T> properties on a component and renders them as Chip elements below the controls. When an event fires, the chip plays a 600ms pulse animation to provide visual feedback.
600ms pulse animation
Each EventCallback is wrapped in a proxy delegate that triggers the pulse. The chip transitions from Neutral/Outlined to Primary/Filled and back, using Blazor's CSS transition support. Typed EventCallback<T> wrappers are created via reflection to match the generic parameter.
Code Generation
The code snippet updates live as you interact with the controls. It follows clean formatting rules to produce copy-ready markup.
Properties at their default value are omitted from the output, keeping the snippet minimal.
Enum values are formatted as Type.Value (e.g., Color.Primary, Variant.Filled).
Icon properties use the @MaterialSymbols.Name format (e.g., @MaterialSymbols.Home).
Boolean values are rendered as lowercase true/false.
SampleKey — Localized Preview Content
String properties like Title, Description, or Label often default to empty strings. Without sample content, the AutoConfigurator preview renders an empty component. The SampleKey property solves this by referencing a localized resource entry that provides meaningful preview text.
Annotate the property
Add SampleKey to the [Configurable] attribute, referencing a key in the component's .resx file.
Add .resx entries
Create Sample_* entries in the component's .resx (English) and .de.resx (German) resource files.
Automatic resolution
The AutoConfigurator resolves the key via IStringLocalizerFactory at runtime. If the key is missing, it falls back to the property default.
SampleKey usage with .resx entries
A component annotates its text properties with SampleKey and provides localized sample values in its resource files.
Fallback behavior
If a SampleKey references a missing .resx entry, the AutoConfigurator silently falls back to the property's default value. This makes SampleKey fully opt-in and safe to add incrementally.
Show code
Copy code
// Component .razor file
[Parameter]
[Configurable(Group = "Content", Order = 0, SampleKey = "Sample_Title")]
public string Title { get; set; } = string.Empty;
[Parameter]
[Configurable(Group = "Content", Order = 1, SampleKey = "Sample_Description")]
public string Description { get; set; } = string.Empty;
// Resources/Components/PageHero.resx (English)
// Sample_Title = "Dashboard Overview"
// Sample_Description = "Your central workspace."
// Resources/Components/PageHero.de.resx (German)
// Sample_Title = "Dashboard-Ubersicht"
// Sample_Description = "Ihre zentrale Arbeitsflache."File Reference
| File | Description |
|---|---|
| Models/ConfigurableAttribute.cs | [Configurable] attribute definition with Group, Editor, Order, and SampleKey properties. |
| Models/EditorKind.cs | EditorKind enum: Auto, Select, Checkbox, TextInput, IconPicker, NumberInput. |
| Components/AutoConfigurator.razor(.cs) | Main orchestrator component (Demo). Builds controls, manages state, generates code, and wraps events. |
| Components/ConfiguratorMetadata.cs | Reflection engine (Demo). Scans component types, resolves editors, and caches results. |
| Components/Configurator.razor | Layout wrapper (Demo). Renders preview area, controls grid, code snippet, and reset button. |
| Components/ConfiguratorContext.cs | Parameter carrier (Demo). Holds the current parameter dictionary exposed to PreviewTemplate. |