-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathComponents.razor
More file actions
400 lines (364 loc) · 14.8 KB
/
Copy pathComponents.razor
File metadata and controls
400 lines (364 loc) · 14.8 KB
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
@page "/components"
@using System.ComponentModel.DataAnnotations
@using MComponents.ExampleApp.Service
@using MComponents.Files
@using MComponents.MAccordion
@using MComponents.MBadge
@using MComponents.MCards
@using MComponents.MLoading
@using MComponents.MPaint
@using MComponents.MProgressbar
@using MComponents.MQueryBuilder
@using MComponents.MScrollAnchor
@using MComponents.MSeparator
@using MComponents.MToaster
@using MComponents.MWizard
@inject IToaster Toaster
<h1>Component gallery</h1>
<p>Each section contains a simple example and a more advanced scenario.</p>
<section id="maccordion" class="mb-5">
<ExampleHeading Name="MAccordion" />
<h3>Simple</h3>
<MAccordion>
<Cards>
<MAccordionCard Identifier="first" Title="First card" InitialOpen="true">
The first card starts open.
</MAccordionCard>
<MAccordionCard Identifier="second" Title="Second card">
Select the heading to reveal this content.
</MAccordionCard>
</Cards>
</MAccordion>
<h3>Advanced</h3>
<MAccordion AllowMultipleOpenCards="true" RenderHiddenCards="true">
<Cards>
<MAccordionCard Identifier="profile" Title="<strong>Profile</strong>" InitialOpen="true">
Multiple cards can stay open and titles can contain markup.
</MAccordionCard>
<MAccordionCard Identifier="preferences" Title="Preferences">
Hidden card content remains rendered for stateful controls.
</MAccordionCard>
</Cards>
</MAccordion>
</section>
<section id="mbadge" class="mb-5">
<ExampleHeading Name="MBadge" />
<h3>Simple</h3>
<MBadge>New</MBadge>
<h3>Advanced</h3>
<MBadge CssClass="text-uppercase" title="Three pending items">3 pending</MBadge>
</section>
<section id="mcards" class="mb-5">
<ExampleHeading Name="MCards" />
<h3>Simple</h3>
<MCards T="string" Values="CardNames">
<Template Context="name"><strong>@name</strong></Template>
</MCards>
<h3>Advanced</h3>
<MCards T="GalleryItem" Values="GalleryItems" Columns="3" OnClick="SelectCard">
<Template Context="item">
<h4>@item.Title</h4>
<p>@item.Description</p>
</Template>
<TemplateEmpty><em>No cards are available.</em></TemplateEmpty>
</MCards>
@if (SelectedCard != null)
{
<p>Selected: @SelectedCard.Title</p>
}
</section>
<section id="mform" class="mb-5">
<ExampleHeading Name="MForm" />
<h3>Simple</h3>
<MFormContainer SaveButtonText="Save profile">
<MForm Model="SimpleProfile" />
</MFormContainer>
<h3>Advanced</h3>
<MFormContainer SaveButtonText="Validate and save" OnAfterAllFormsSubmitted="OnFormsSubmitted">
<MForm Model="AdvancedProfile" UpdateOnInput="true" StoreOriginalValues="true">
<Fields>
<MFieldRow>
<MField Property="@nameof(Profile.Name)" />
<MField Property="@nameof(Profile.Email)" />
</MFieldRow>
<MField Property="@nameof(Profile.Notes)" />
</Fields>
</MForm>
</MFormContainer>
@if (!string.IsNullOrEmpty(FormStatus))
{
<p>@FormStatus</p>
}
</section>
<section id="mgrid" class="mb-5">
<ExampleHeading Name="MGrid" />
<h3>Simple</h3>
<MGrid DataSource="GridItems" HtmlTableClass="m-grid m-grid-striped">
<MGridColumns>
<MGridColumn Property="@nameof(GalleryItem.Title)" />
<MGridColumn Property="@nameof(GalleryItem.Description)" />
</MGridColumns>
</MGrid>
<h3>Advanced</h3>
<MGrid DataSource="GridItems"
EnableAdding="true"
EnableEditing="true"
EnableDeleting="true"
EnableFilterRow="true"
EnableGrouping="true"
EnableUserSorting="true"
ToolbarItems="ToolbarItem.Add | ToolbarItem.Edit | ToolbarItem.Delete"
HtmlTableClass="m-grid m-grid-striped m-grid-bordered m-grid-hover">
<MGridColumns>
<MGridColumn Property="@nameof(GalleryItem.Title)" HeaderText="Item" />
<MGridColumn Property="@nameof(GalleryItem.Description)" />
<MGridActionColumn T="GalleryItem" />
</MGridColumns>
<MGridPager PageSize="5" SelectablePageSizes="new[] { 5, 10, 20 }" />
</MGrid>
<p>The data-adapter, import, and export scenario is also available in the <a href="fetchdata2">data-adapter example</a>.</p>
</section>
<section id="minputfile" class="mb-5">
<ExampleHeading Name="MInputFile" />
<CascadingValue Value="ExampleEditContext">
<h3>Simple</h3>
<MInputFileSimple @bind-Value="SingleFile" Accept=".pdf,image/*" />
<h3>Advanced</h3>
<MInputFile MaxAllowedFiles="5"
@bind-Values="MultipleFiles"
Accept=".pdf,image/*"
OnFileClicked="OnFileClicked" />
</CascadingValue>
@if (!string.IsNullOrEmpty(FileStatus))
{
<p>@FileStatus</p>
}
</section>
<section id="mpaint" class="mb-5">
<ExampleHeading Name="MPaint" />
<h3>Simple</h3>
<MPaint Width="320" Height="120" />
<h3>Advanced</h3>
<MPaint @ref="Paint" Width="480" Height="160" PenColor="#0b7285" CssClass="border" />
<button type="button" class="btn btn-secondary mt-2" @onclick="CheckPainting">Check canvas</button>
<span class="ml-2">@PaintStatus</span>
</section>
<section id="mpopup" class="mb-5">
<ExampleHeading Name="MPopup" />
<h3>Simple</h3>
<MPopup>
<Target><button type="button" class="btn btn-secondary">Open menu</button></Target>
<PopupContent><a href="/">Home</a></PopupContent>
</MPopup>
<h3>Advanced</h3>
<MPopup CssClass="m-popup">
<Target><button type="button" class="btn btn-secondary">Choose language</button></Target>
<PopupContent>
<ul class="list-unstyled m-2">
<li><button class="btn btn-link" @onclick="SelectEnglish">English</button></li>
<li><button class="btn btn-link" @onclick="SelectGerman">German</button></li>
</ul>
</PopupContent>
</MPopup>
<p>Language: @Language</p>
</section>
<section id="mprogressbar" class="mb-5">
<ExampleHeading Name="MProgressbar" />
<h3>Simple</h3>
<MProgressbar Percentage="35" />
<h3>Advanced</h3>
<input type="range" min="0" max="100" @bind="Progress" @bind:event="oninput" />
<MProgressbar Percentage="Progress" CssClass="mt-2" />
<span>@Progress%</span>
</section>
<section id="mquerybuilder" class="mb-5">
<ExampleHeading Name="MQueryBuilder" />
<h3>Simple</h3>
<MQueryBuilder T="GalleryItem" @bind-RuleGroup="SimpleRules">
<MQueryBuilderField RuleName="@nameof(GalleryItem.Title)" />
</MQueryBuilder>
<h3>Advanced</h3>
<MQueryBuilder T="GalleryItem" @bind-RuleGroup="AdvancedRules">
<MQueryBuilderField RuleName="@nameof(GalleryItem.Title)" Title="Title" />
<MQueryBuilderField RuleName="@nameof(GalleryItem.Description)" Title="Description" />
<MQueryBuilderField RuleName="@nameof(GalleryItem.Priority)" Title="Priority" />
</MQueryBuilder>
<p>Use <code>MQueryBuilderHelper.ApplyRules</code> to apply the resulting rule group to an <code>IQueryable</code>.</p>
</section>
<section id="mscrollanchor" class="mb-5">
<ExampleHeading Name="MScrollAnchor" />
<h3>Simple</h3>
<a href="components#scroll-target">Jump to the target</a>
<div style="height: 8rem"></div>
<MScrollAnchor Id="scroll-target" />
<strong>Scroll target</strong>
<h3>Advanced</h3>
<p>Place anchors next to validation summaries or dynamically rendered sections so deep links return users to the relevant content.</p>
</section>
<section id="mselect" class="mb-5">
<ExampleHeading Name="MSelect" />
<CascadingValue Value="ExampleEditContext">
<h3>Simple</h3>
<MSelect T="string" @bind-Value="SelectedValue" Options="SelectValues" />
<p>Selected: @SelectedValue</p>
<h3>Advanced</h3>
<MSelect T="string"
@bind-Values="SelectedValues"
Options="SelectValues"
EnableSearch="true"
EnableSelectAll="true"
CustomFormatter="FormatSelectValue" />
<p>Selected: @string.Join(", ", SelectedValues)</p>
</CascadingValue>
</section>
<section id="mseparator" class="mb-5">
<ExampleHeading Name="MSeparator" />
<h3>Simple</h3>
<MSeparator />
<h3>Advanced</h3>
<MSeparator><h4>Account details</h4></MSeparator>
</section>
<section id="mspinner" class="mb-5">
<ExampleHeading Name="MSpinner" />
<h3>Simple</h3>
<MSpinner />
<h3>Advanced</h3>
<button type="button" class="btn btn-secondary" @onclick="() => IsLoading = !IsLoading">Toggle loading</button>
@if (IsLoading)
{
<div class="mt-2"><MSpinner /> Loading data…</div>
}
</section>
<section id="mtabs" class="mb-5">
<ExampleHeading Name="MTabs" />
<h3>Simple</h3>
<MTabs>
<MTab Title="Overview">Overview content</MTab>
<MTab Title="Details">Details content</MTab>
</MTabs>
<h3>Advanced</h3>
<MTabs SyncTabsWithFragmentIdentifierInUrl="true" CssClass="mt-2">
<MTab Title="General" FragmentIdentifier="general">General settings</MTab>
<MTab Title="Notifications" FragmentIdentifier="notifications" CssClassButton="text-uppercase">
Notification settings
</MTab>
</MTabs>
</section>
<section id="mtoaster" class="mb-5">
<ExampleHeading Name="MToaster" />
<h3>Simple</h3>
<button type="button" class="btn btn-info" @onclick="ShowInfoToast">
Show info toast
</button>
<h3>Advanced</h3>
<button type="button" class="btn btn-success" @onclick="ShowInteractiveToast">Show interactive toast</button>
<button type="button" class="btn btn-secondary" @onclick="Toaster.Clear">Clear all</button>
@if (!string.IsNullOrEmpty(ToastStatus))
{
<p>@ToastStatus</p>
}
</section>
<section id="mtooltip" class="mb-5">
<ExampleHeading Name="MTooltip" />
<h3>Simple</h3>
<MTooltip Text="A plain text tooltip">Hover over this text</MTooltip>
<h3>Advanced</h3>
<MTooltip CssClass="p-2">
<ChildContent><button type="button" class="btn btn-secondary">Rich tooltip</button></ChildContent>
<TooltipContent>
<strong>Formatted content</strong>
<div>Tooltips can contain arbitrary render fragments.</div>
</TooltipContent>
</MTooltip>
</section>
<section id="mwizard" class="mb-5">
<ExampleHeading Name="MWizard" />
<h3>Simple</h3>
<MWizard>
<Steps>
<MWizardStep Title="Start"><Content>Welcome to the wizard.</Content></MWizardStep>
<MWizardStep Title="Finish"><Content>Review and finish.</Content></MWizardStep>
</Steps>
</MWizard>
<h3>Advanced</h3>
<MWizard EnableJumpToAnyStep="true" OnStepChanged="OnWizardStepChanged" OnSubmit="OnWizardSubmitted">
<Steps>
<MWizardStep Title="Account" Position="1"><Content>Enter account details.</Content></MWizardStep>
<MWizardStep Title="Options" Position="2"><Content>Choose optional features.</Content></MWizardStep>
<MWizardStep Title="Review" Position="3"><Content>Confirm the selections.</Content></MWizardStep>
</Steps>
</MWizard>
@if (!string.IsNullOrEmpty(WizardStatus))
{
<p>@WizardStatus</p>
}
</section>
@code {
private readonly string[] CardNames = { "First", "Second", "Third" };
private readonly string[] SelectValues = Enumerable.Range(1, 20).Select(i => $"Value {i}").ToArray();
private readonly List<GalleryItem> GalleryItems =
[
new() { Title = "Alpha", Description = "First item", Priority = 1 },
new() { Title = "Beta", Description = "Second item", Priority = 2 },
new() { Title = "Gamma", Description = "Third item", Priority = 3 }
];
private GalleryItem SelectedCard { get; set; }
private Profile SimpleProfile { get; } = new();
private Profile AdvancedProfile { get; } = new();
private string FormStatus { get; set; }
private IFile SingleFile { get; set; }
private ICollection<IFile> MultipleFiles { get; set; } = new List<IFile>();
private string FileStatus { get; set; }
private MPaint Paint { get; set; }
private string PaintStatus { get; set; }
private string Language { get; set; } = "English";
private int Progress { get; set; } = 65;
private MQueryBuilderRuleGroup SimpleRules { get; set; } = new();
private MQueryBuilderRuleGroup AdvancedRules { get; set; } = new();
private string SelectedValue { get; set; }
private ICollection<string> SelectedValues { get; set; } = new List<string>();
private bool IsLoading { get; set; }
private string ToastStatus { get; set; }
private string WizardStatus { get; set; }
private EditContext ExampleEditContext { get; } = new(new object());
private IEnumerable<GalleryItem> GridItems => GalleryItems;
private void SelectCard(GalleryItem item) => SelectedCard = item;
private void OnFormsSubmitted(MFormContainerAfterAllFormsSubmittedArgs args)
=> FormStatus = "All forms were submitted successfully.";
private void OnFileClicked(IFile file) => FileStatus = $"Selected {file.FileName}";
private void CheckPainting() => PaintStatus = Paint?.ImageIsEmpty == false ? "The canvas contains a drawing." : "The canvas is empty.";
private void SelectEnglish() => Language = "English";
private void SelectGerman() => Language = "German";
private string FormatSelectValue(string value) => $"Option: {value}";
private void ShowInfoToast() => Toaster.Info("The operation started.", "Information");
private void ShowInteractiveToast()
=> Toaster.Success("Select this toast to run its callback.", "Saved", options =>
{
options.RequireInteraction = true;
options.Onclick = toast =>
{
ToastStatus = "The toast callback ran.";
return Task.CompletedTask;
};
});
private void OnWizardStepChanged(StepChangedArgs args)
=> WizardStatus = $"Moved from {args.OldStep.Title} to {args.NewStep.Title}.";
private void OnWizardSubmitted(SubmitEventArgs args) => WizardStatus = "Wizard submitted.";
public sealed class GalleryItem
{
public Guid Id { get; set; } = Guid.NewGuid();
[Required]
public string Title { get; set; }
public string Description { get; set; }
public int Priority { get; set; }
}
public sealed class Profile
{
public Guid Id { get; set; } = Guid.NewGuid();
[Required]
public string Name { get; set; }
[EmailAddress]
public string Email { get; set; }
public string Notes { get; set; }
}
}