-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
Loading.razor
331 lines (294 loc) · 11.4 KB
/
Loading.razor
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
@using System.ComponentModel.DataAnnotations;
<PageScroll />
<h1>Loading and Overlay Components</h1>
<p>
Blazor components that renders Overlays for the whole page on load or for specific element on custom event.
Also HTML @("<button>") with customizable content for showing async operation in progress/loading state. For usage see source code and docs on
<a href="https://github.com/majorimi/blazor-components/blob/master/.github/docs/Loading.md" target="_blank">Github</a>.
<br /><strong>Majorsoft.Blazor.Components.Loading</strong> package is available on <a href="https://www.nuget.org/packages/Majorsoft.Blazor.Components.Loading" target="_blank">Nuget</a>
</p>
<h3>Loading and Overlay Components features:</h3>
<ul>
<li><NavLink href="loading#loading-page">Loading page</NavLink></li>
<li><NavLink href="loading#loading-element">Loading element</NavLink></li>
<li><NavLink href="loading#loading-button">Loading button</NavLink></li>
</ul>
<div class="container-fluid p-3 mb-3 border rounded">
<PermaLinkElement PermaLinkName="loading-page" IconActions="PermaLinkIconActions.Copy|PermaLinkIconActions.Navigate" IconMarginTop="8" IconSize="18">
<Content><h3>Loading page</h3></Content>
</PermaLinkElement>
<p>Renders an Overlay layer for the whole page with customizable content for showing Page loading...</p>
<LoadingPage OnLoading="@SendRequest">
<LoadingContent>
<i class="fa fa-spinner fa-3x fa-spin"></i>
<h2 class="m-3">Loading...</h2>
</LoadingContent>
</LoadingPage>
<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Overlay color (Name, RGB, Hex, HSL): <input class="form-control w-100" @bind="_overlayColor" />
</div>
</div>
<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Overlay opacity: @(_overlayOpacity/100)
<input type="range" class="w-100" min="0" max="100" @bind="_overlayOpacity" @oninput="(e => _overlayOpacity = int.Parse(e.Value?.ToString()))" />
</div>
</div>
<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Loading content: <textarea class="form-control w-100" @bind="_overlayContent" />
</div>
</div>
<LoadingPage IsLoading="@_pageIsLoading" OverlayBackgroundColor="@_overlayColor" OverlayOpacity="@(_overlayOpacity / 100)">
<LoadingContent>
@((MarkupString)_overlayContent)
</LoadingContent>
</LoadingPage>
<button class="btn btn-primary" @onclick="LoadForm">Prompt Page loader...</button>
</div>
<div class="container-fluid p-3 mb-3 border rounded">
<PermaLinkElement PermaLinkName="loading-element" IconActions="PermaLinkIconActions.Copy|PermaLinkIconActions.Navigate" IconMarginTop="8" IconSize="18">
<Content><h3>Loading element</h3></Content>
</PermaLinkElement>
<p>Renders an Overlay layer for the wrapped element (Table, Grid, etc.) with customizable content for showing loading or any progress... It can be used for a 'static' overlay as well.</p>
<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Overlay color (Name, RGB, Hex, HSL): <input class="form-control w-100" @bind="_overlayColorTable" />
</div>
</div>
<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Overlay opacity: @(_overlayOpacityTable / 100)
<input type="range" class="w-100" min="0" max="100" @bind="_overlayOpacityTable" @oninput="(e => _overlayOpacityTable = int.Parse(e.Value?.ToString()))" />
</div>
</div>
<div class="row pb-2">
<div class="col-12 col-lg-8 col-xl-5">
Loading content: <textarea class="form-control w-100" @bind="_overlayContent2" />
</div>
</div>
<div class="row pb-2">
<div class="col-12">
<LoadingElement IsLoading="@_elementIsLoading" OverlayBackgroundColor="@_overlayColorTable" OverlayOpacity="@(_overlayOpacityTable / 100)">
<LoadingContent>
@((MarkupString)_overlayContent2)
</LoadingContent>
<Content>
<table class="table table-striped table-bordered">
<thead class="">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
</thead>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
</table>
</Content>
</LoadingElement>
</div>
</div>
<button class="btn btn-primary mb-2" @onclick="LoadTable">Prompt Table loader...</button>
<h3>Static overlay</h3>
<div class="row pb-1 mx-auto w-50 justify-content-center">
<div class="col-12">
<LoadingElement IsLoading="_showStaticOverlay" OnOverlayClicked="OnOverlayClick">
<LoadingContent>
<button class="btn btn-primary btn-sm" @onclick="e => _showStaticOverlay = false">Close overlay</button>
</LoadingContent>
<Content>
<p class="p-2 border">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eget diam sed diam dignissim cursus. Donec gravida dapibus nisi eget luctus. Fusce commodo fermentum justo, at suscipit ex consequat dictum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Curabitur elit turpis, tempor vel nibh eu, feugiat porta ligula. Donec pulvinar justo vel nunc lobortis volutpat. Nulla id lectus sed dui dignissim gravida. Vivamus imperdiet nulla turpis, ac sagittis magna feugiat quis. Ut ut ornare lacus. Integer a condimentum orci. Fusce vitae bibendum justo, nec facilisis neque. Vivamus et metus vitae mauris pretium tristique. Integer eleifend dignissim blandit. Sed auctor lectus et neque tempor lacinia. Aliquam sollicitudin tincidunt commodo.
</p>
</Content>
</LoadingElement>
</div>
</div>
<div>Allow to close Overlay on Click: <input type="checkbox" @bind="_closeOverlayOnClick" /></div>
<button class="btn btn-primary mb-2" @onclick="StaticOverlay">Prompt Table loader...</button>
</div>
<div class="container-fluid p-3 mb-3 border rounded">
<PermaLinkElement PermaLinkName="loading-button" IconActions="PermaLinkIconActions.Copy|PermaLinkIconActions.Navigate" IconMarginTop="8" IconSize="18">
<Content><h3>Loading button</h3></Content>
</PermaLinkElement>
<p>Renders <strong>HTML Button</strong> with customizable content to show during async operation progress/loading...</p>
<div class="row">
<div class="col-12">
<div>Submit button will switch state automatically when clicked and registered callback finished executing. </div>
<div>Disabled when Loading: <input type="checkbox" @bind="_disabledWhenLoading1" /></div>
</div>
<div class="col-12 col-lg-8 col-xl-5">
Default state Content: <input class="form-control w-100" @bind="_buttonTextContent" />
Loading state Content: <input class="form-control w-100" @bind="_buttonLoadingContent" />
</div>
<div class="col-12 mt-2">
<LoadingButton class="btn btn-primary" Type="ButtonTypes.Submit" DisabledWhenLoading="_disabledWhenLoading1" OnClicked="@SendRequest">
<Content>
@((MarkupString)_buttonTextContent)
</Content>
<LoadingContent>
@((MarkupString)_buttonLoadingContent)
</LoadingContent>
</LoadingButton>
</div>
</div>
<hr />
<div class="row">
<div class="col-12">
<div>Simple button will switch state automatically when clicked and registered callback finished executing. </div>
<div>Disabled when Loading: <input type="checkbox" @bind="_disabledWhenLoading2" /></div>
</div>
<div class="col-12 mt-2">
<LoadingButton class="btn btn-warning" DisabledWhenLoading="_disabledWhenLoading2" OnClicked="@SendRequest">
<Content>
Save
<i class="fa fa-save"></i>
</Content>
<LoadingContent>
<i class="fa fa-sync fa-spin"></i> Sending data...
</LoadingContent>
</LoadingButton>
</div>
</div>
<hr />
<div class="row">
<EditForm Model="@exampleModel" OnValidSubmit="@FormOnValidSubmit">
<div class="col-12">
<div>Form Submit button without Click handler states has to be switched 'Manually' by acquiring @@ref="" and call Set()/Reset() functions.</div>
<div>Disabled when Loading: <input type="checkbox" @bind="_disabledWhenLoading3" /></div>
</div>
<DataAnnotationsValidator />
<ValidationSummary />
<div class="col-12 col-lg-8 col-xl-5">
<div class="pb-2 pt-3">
<InputText @bind-Value="exampleModel.Name" class="form-control w-100" />
</div>
<div class="pb-2">
<LoadingButton @ref="_loadingButton" class="btn btn-secondary"
IsLoading="@_isButtonLoading"
DisabledWhenLoading="_disabledWhenLoading3"
Type="ButtonTypes.Submit">
<Content>
Submit
</Content>
<LoadingContent>
<i class="fa fa-circle-notch fa-spin"></i> Post...
</LoadingContent>
</LoadingButton>
</div>
</div>
</EditForm>
</div>
</div>
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
//await _loadingButton.InnerElementReference.FocusAsync();
}
}
//Page Loading
private string _overlayColor = "lightblue";
private double _overlayOpacity = 50;
private string _overlayContent = @"<i class=""fa fa-cog fa-3x fa-spin""></i>
<h2 class=""m-3"">Refreshing...</h2>";
//Use it when loader should be manually triggered otherwise use LoadingPage.OnLoading event.
private bool _pageIsLoading = false;
private async Task LoadForm()
{
try
{
_pageIsLoading = true; //Set the layout to Loading state
await Task.Delay(1000); //write your code here...
}
finally
{
_pageIsLoading = false; //Reset layout to default state in FINALLY block to avoid infinity loading state in case of any error!
}
}
//Element Loading
private string _overlayColorTable = "orange";
private double _overlayOpacityTable = 50;
private bool _elementIsLoading = false;
private string _overlayContent2 = @"<i class=""fa fa-cog fa-3x fa-spin""></i>
<h2 class=""m-3"">Refreshing table...</h2>";
private async Task LoadTable()
{
try
{
_elementIsLoading = true; //Set the layout to Loading state
await Task.Delay(1500); //write your code here...
}
finally
{
_elementIsLoading = false; //Reset layout to default state in FINALLY block to avoid infinity loading state in case of any error!
}
}
//Static Overlay
private bool _showStaticOverlay = false;
private bool _closeOverlayOnClick = true;
private async Task StaticOverlay()
{
_showStaticOverlay = true;
}
private async Task OnOverlayClick()
{
if(_closeOverlayOnClick)
{
_showStaticOverlay = false;
}
}
//Button Loading
private async Task SendRequest()
{
await Task.Delay(1500); //write your code here...
}
private string _buttonTextContent= @"Fetch data";
private string _buttonLoadingContent = @"<i class=""fa fa-spinner fa-spin""></i> Loading...";
private bool _disabledWhenLoading1 = true;
private bool _disabledWhenLoading2 = true;
private bool _disabledWhenLoading3 = true;
//Use it with EditForm otherwise use LoadingButton.OnClicked event.
private LoadingButton _loadingButton;
private bool _isButtonLoading = false;
private async Task FormOnValidSubmit()
{
try
{
_isButtonLoading = true; //Set the button to Loading state
await Task.Delay(1500); //write your code here...
}
finally
{
_isButtonLoading = false; //Reset button to default state in FINALLY block to avoid infinity loading state in case of any error!
}
}
//Form model
private ExampleModel exampleModel = new ExampleModel();
public class ExampleModel
{
[Required]
public string Name { get; set; }
}
}