-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathDragnDropCommon.razor
69 lines (59 loc) · 2.49 KB
/
DragnDropCommon.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
@using System.IO;
@inject IFileReaderService fileReaderService
<h1>Hello, dropped files!</h1>
Welcome to your new filestreaming app.
<br />
This demo reads files that was dropped in without doing anything particular with it.
<br />
<br />
<div class="btn-group btn-group-toggle">
@foreach (var item in possibleOptions)
{
<label class="@defaultClasses @(item.IsActive() ? "active":"")" @key="item.Id">
<input type="radio" name="options" id="@item.Id" autocomplete="off" checked="@(item.IsActive() ? "checked":"")" @onclick="_ => OnChange(item.Id)"> @item.Description
</label>
}
</div>
<br />
<br />
@if (currentOption == "DragnDropDivCommon")
{
<DragnDropDivCommon />
}
else if (currentOption == "DragnDropInputCommon")
{
<DragnDropInputCommon />
}
@code {
public static string WriteFileInfoOutput(IFileInfo fileInfo, string nl) {
var output = string.Empty;
output += $"{nameof(IFileInfo)}.{nameof(fileInfo.Name)}: {fileInfo?.Name}{nl}";
output += $"{nameof(IFileInfo)}.{nameof(fileInfo.Size)}: {fileInfo?.Size}{nl}";
output += $"{nameof(IFileInfo)}.{nameof(fileInfo.Type)}: {fileInfo?.Type}{nl}";
output += $"{nameof(IFileInfo)}.{nameof(fileInfo.LastModifiedDate)}: {fileInfo?.LastModifiedDate?.ToString() ?? "(N/A)"}{nl}";
output += fileInfo?.NonStandardProperties?.Keys.Aggregate(output, (current, property) => current + $"{nameof(IFileInfo)}.{property} (nonstandard): {fileInfo.NonStandardProperties[property]}{nl}");
output += $"Reading file...{nl}";
return output;
}
private class PossibleOption { public string Id { get; set; } public string Description { get; set; } public Func<bool> IsActive { get; set; } }
List<PossibleOption> possibleOptions = new List<PossibleOption> {
new PossibleOption { Id = "DragnDropDivCommon", Description= "Drag and Drop on Element" },
new PossibleOption { Id = "DragnDropInputCommon", Description= "Drag and Drop on Hidden input" },
};
string defaultClasses = "btn btn-primary";
string currentOption;
protected override void OnInitialized()
{
currentOption = possibleOptions.First().Id;
foreach (var item in possibleOptions)
{
item.IsActive = () => currentOption == item.Id;
}
base.OnInitialized();
}
public void OnChange(string id)
{
currentOption = id;
StateHasChanged();
}
}