about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared/ModalWindow.razor
blob: 75c293393490b136c211d9e1aedbd7c487ebc324 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<div class="r-modal" style="top: @(_y)px; left: @(_x)px;">
    <div class="titlebar" @onmousedown="MouseDown" @onmouseup="MouseUp" @onmousemove="MouseMove" @onmouseleave="MouseMove">
        <b class="title">@Title</b>
        <button class="close" @onclick="OnCloseClicked">X</button>
    </div>
    <div class="content">
        @ChildContent
    </div>
</div>

<style>
    .r-modal {
        position: absolute;
        width: fit-content;
        height: fit-content;
        z-index: 1000;
    }
    .r-modal:hover {
        z-index: 1001;
    }
    
    .r-modal > .titlebar {
        position: absolute;
        display: block;
        top: 0;
        left: 0;
        width: 100%;
        height: 25px;
        background-color: #000;
        user-select: none;
    }
    
    .r-modal > .titlebar > .title {
        position: relative;
        top: 0;
        left: 0;
        width: fit-content;
        height: 100%;
        line-height: 25px;
        padding-left: 10px;
        color: #fff;
    }
    
    .r-modal > .titlebar > .close {
        position: absolute;
        top: 0;
        right: 0;
        width: 25px;
        height: 100%;
        line-height: 25px;
        text-align: center;
        color: #fff;
        background-color: #111;
        cursor: pointer;
    }
    
    .r-modal > .content {
        position: relative;
        top: 25px;
        left: 0;
        width: fit-content;
        height: fit-content;
        min-width: 150px;
        min-height: 5px;
        max-width: 75vw;
        max-height: 75vh;
        overflow: auto;
        background-color: #fff;
    }
</style>

@code {
    
    [Parameter]
    public RenderFragment? ChildContent { get; set; }
    
    [Parameter]
    public string Title { get; set; } = "Untitled window";
    
    [Parameter]
    public double X { get; set; } = 60;
    
    [Parameter]
    public double Y { get; set; } = 60;
    
    [Parameter]
    public Action OnCloseClicked { get; set; }
    

    private double _x = 60;
    private double _y = 60;
    
    protected override void OnInitialized() {
        _x = X;
        _y = Y;
    }

    private void WindowDrag(DragEventArgs obj) {
        Console.WriteLine("Drag: " + obj.ToJson());
        
        _x += obj.MovementX;
        _y += obj.MovementY;
        
        StateHasChanged();
    }

    private bool isDragging = false;
    private double dragX = 0;
    private double dragY = 0;
    private void MouseDown(MouseEventArgs obj) {
        isDragging = true;
        dragX = obj.ClientX;
        dragY = obj.ClientY;
    }

    private void MouseUp(MouseEventArgs obj) {
        isDragging = false;
    }

    private void MouseMove(MouseEventArgs obj) {
        if (isDragging) {
            _x += obj.ClientX - dragX;
            _y += obj.ClientY - dragY;
            dragX = obj.ClientX;
            dragY = obj.ClientY;
            StateHasChanged();
        }
    }

}