summaryrefslogtreecommitdiff
path: root/Pages/Component/Dialog.razor
blob: dbfec49d862d6f3298ab7c8a6d6fdf04c200f913 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@inject IJSRuntime jsRuntime
@implements IDialog

<div
    class="dialog"
    onmousedown="dialogMouseDown(event)"
    style="opacity:0;visibility:hidden;@(heightStyle)"
    @ref=dialogDiv>
    @if(Title is not null) {
        <div class="titlebar" onmousedown="dialogTitleMouseDown(event)">
            <p class="title">@Title</p>
            <hr/>
        </div>
    }
    <div class="content">
        @ChildContent
    </div>
</div>

@code {
    [Parameter]
    public string? Title { get; set; }

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

    [Parameter]
    public int HeightPixels  { set => height = $"{value}px"; }
    [Parameter]
    public int HeightPercent { set => height = $"{value}%"; }

    public bool Visible {
        get => visible;
        set {
            visible = value;
            jsRuntime.InvokeVoidAsync(
                "setDialogVisibility",
                new object?[] { dialogDiv, value });
        }
    }

    private bool visible = false;

    private string? height;

    private ElementReference dialogDiv;

    public void Show() => Visible = true;
    public void Hide() => Visible = false;

    private string heightStyle =>
        $"{(height is null ? "" : $"max-height:{height};")}";
}