about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared/SimpleComponents/DictionaryEditor.razor
blob: afd1fdc8c4a2defc3a008ae5ed454611645438c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@using LibMatrix.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();
    }

}