I have a class that can wrap any generic type that allows me to store localized data in a Dictionary with a default fallback.
public class Localization<T>(T @default, Dictionary<string, T> localizations){ public T Default { get; set; } = @default; public Dictionary<string, T> Localizations { get; set; } = localizations;}I want to create a Blazor component to repesent a generic editor for any localizable types, that can bind a child Blazor component for the generic type.
The UI would be as follows:
[My Localizable Field Label] [Editor<T> for Localization.Default][Toggle to enable localization] [Editor<T> for Localization.Localizations[context]]The top row of label and editor would always display, the bottom toggle would always display and control visibility of the second editor.
Good examples of generic types would be:
- bool (as checkbox or toggle button)
- string (as input[type=text])
- int (as input[type=number])
I need some help understanding the best way to structure this...
My initial thought was to leverage ChildContent to be able to do something like:
<LocalizationEditor T="bool" Localization="MyInstanceOfLocalization"><ToggleButton Checked="@context" /></LocalizationEditor>That seems flawed though, because I don't think updates to the ChildContent will be reflected in MyInstanceOfLocalization - especially because there is additional logic needed to handle a Dictionary.Remove when the Toggle to enable localization is toggled off etc.
The alternative seems to be to have a switch within the LocalizationEditor.razor that covers every supported ChildEditor based on the Generic Type(s).
<LocalizationEditor T="bool" Localization="MyInstanceOfLocalization" />As I try to scaffold something, can anyone provide some guidance on what would typically work well within the Blazor paradigm that I am not especially familiar with yet.