about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared/SimpleComponents/DictionaryEditor.razor
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web/Shared/SimpleComponents/DictionaryEditor.razor')
-rw-r--r--MatrixRoomUtils.Web/Shared/SimpleComponents/DictionaryEditor.razor41
1 files changed, 41 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/DictionaryEditor.razor b/MatrixRoomUtils.Web/Shared/SimpleComponents/DictionaryEditor.razor
new file mode 100644

index 0000000..4d90c57 --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/SimpleComponents/DictionaryEditor.razor
@@ -0,0 +1,41 @@ +@using MatrixRoomUtils.Core.Extensions +<table> + @foreach(var i in Items.Keys) + { + var key = i; + <input value="@Items[key]" @oninput="(obj) => inputChanged(obj, key)"> + <button @onclick="() => { Items.Remove(key); ItemsChanged.InvokeAsync(); }">Remove</button> + <br/> + } +</table> +<button @onclick="() => { Items.Add(string.Empty, default); ItemsChanged.InvokeAsync(); }">Add</button> + +@code { + + [Parameter] + public Dictionary<string, object> Items { get; set; } = new(); + + [Parameter, EditorRequired] + public EventCallback ItemsChanged { get; set; } + + [Parameter] + public Func<string,string>? KeyFormatter { get; set; } + + [Parameter] + public Action? OnFocusLost { get; set; } + + + protected override Task OnInitializedAsync() + { + Console.WriteLine($"DictionaryEditor initialized with {Items.Count} items: {Items.ToJson()}"); + return base.OnInitializedAsync(); + } + + private void inputChanged(ChangeEventArgs obj, string key) + { + Console.WriteLine($"StringListEditor inputChanged {key} {obj.Value}"); + Items[key] = obj.Value.ToString(); + ItemsChanged.InvokeAsync(); + } + +} \ No newline at end of file