Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
ο»Ώ<FluentInputFile @ref="@myFileUploader"
DragDropZoneVisible="false"
Mode="InputFileMode.SaveToTemporaryFolder"
Multiple="true"
AnchorId="MyUploadLoadingButton"
MaximumFileSize="@(100 * 1024 * 1024)"
Accept=".mp4, .mov, .avi"
OnProgressChange="@(e =>
{
_formUploading = true;
progressPercent = e.ProgressPercent;
progressTitle = e.ProgressTitle;
})"
OnCompleted="@OnCompleted" />

<FluentProgress Min="0" Max="100" Visible="@(progressPercent > 0)" Value="@progressPercent" />
<FluentLabel Alignment="HorizontalAlignment.Center">
@progressTitle
</FluentLabel>

<FluentButton Id="MyUploadLoadingButton" Loading="_formUploading" Appearance="Appearance.Accent">
Upload files
</FluentButton>

@if (Files.Any())
{
<h4>File(s) uploaded:</h4>
<ul>
@foreach (var file in Files)
{
<li>
<b>@file.Name</b> πŸ”Ή
@($"{Decimal.Divide(file.Size, 1024):N} KB") πŸ”Ή
@file.ContentType πŸ”Ή
@file.LocalFile?.FullName
@file.ErrorMessage
</li>
}
</ul>
}


@code
{
bool _formUploading;
FluentInputFile? myFileUploader = default!;
int? progressPercent;
string? progressTitle;

FluentInputFileEventArgs[] Files = Array.Empty<FluentInputFileEventArgs>();

void OnCompleted(IEnumerable<FluentInputFileEventArgs> files)
{
Files = files.ToArray();
progressPercent = myFileUploader!.ProgressPercent;
progressTitle = myFileUploader!.ProgressTitle;

// For the demo, delete these files.
foreach (var file in Files)
{
file.LocalFile?.Delete();
}
_formUploading = false;
StateHasChanged();
}
}
6 changes: 6 additions & 0 deletions examples/Demo/Shared/Pages/InputFile/InputFilePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
</Description>
</DemoSection>

<DemoSection Title="Manual upload with loading indicator" Component="@typeof(InputFileLoading)">
<Description>

</Description>
</DemoSection>

<DemoSection Title="Mode = InputFileMode.Buffer" Component="@typeof(InputFileBufferMode)">
<Description>

Expand Down
12 changes: 6 additions & 6 deletions src/Core/Components/InputFile/FluentInputFile.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class FluentInputFile : FluentComponentBase, IAsyncDisposable
private ElementReference? _containerElement;
private InputFile? _inputFile;
private IJSObjectReference? _containerInstance;

public static string ResourceLoadingBefore = "Loading...";
public static string ResourceLoadingCompleted = "Completed";
public static string ResourceLoadingCanceled = "Canceled";
Expand Down Expand Up @@ -201,13 +201,13 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
Module ??= await JSRuntime.InvokeAsync<IJSObjectReference>("import", JAVASCRIPT_FILE.FormatCollocatedUrl(LibraryConfiguration));

if (!string.IsNullOrEmpty(AnchorId))
{
await Module.InvokeVoidAsync("attachClickHandler", AnchorId, Id);
}

_containerInstance = await Module.InvokeAsync<IJSObjectReference>("initializeFileDropZone", _containerElement, _inputFile!.Element);
}

if (!string.IsNullOrEmpty(AnchorId) && Module is not null)
{
await Module.InvokeVoidAsync("attachClickHandler", AnchorId, Id);
}
}

/// <summary />
Expand Down
6 changes: 5 additions & 1 deletion src/Core/Components/InputFile/FluentInputFile.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ export function raiseFluentInputFile(fileInputId) {
export function attachClickHandler(buttonId, fileInputId) {
var button = document.getElementById(buttonId);
var fileInput = document.getElementById(fileInputId);
if (button && fileInput) {

if (button && fileInput && !button.fluentuiBlazorFileInputHandlerAttached) {

button.addEventListener("click", function (e) {
fileInput.click();
});

button.fluentuiBlazorFileInputHandlerAttached = true;
}
}

Expand Down
Loading