summaryrefslogtreecommitdiff
path: root/Pages/Component/TabContainer.razor
blob: 3caab0b1871ffa3eb1ed965b819353113023f09d (plain)
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
<link rel="stylesheet" href="@(nameof(HyperBooru)).styles.css"/>

<div class="tabs">
    @foreach(var pane in Panes) {
        <a href="javascript:;" @onclick=@(() => ActivePane = pane) class="@(pane == ActivePane ? "selected" : "")">
            @pane.Title
        </a>
    }
</div>

<CascadingValue Value="this">
    @ChildContent
</CascadingValue>

@code {
    [Parameter]
    public RenderFragment ChildContent { get; set; }

    public TabPane? ActivePane { get; set; }
    List<TabPane> Panes = new();

    public void AddPane(TabPane tabPane) {
        Panes.Add(tabPane);
        if(Panes.Count == 1)
            ActivePane = tabPane;
        StateHasChanged();
    }

    public void RemovePane(TabPane tabPane) {
        if(ActivePane == tabPane)
            ActivePane = Panes.ElementAtOrDefault(0);
        Panes.Remove(tabPane);
        StateHasChanged();
    }
}