Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 7 additions & 1 deletion src/BootstrapBlazor/Components/Upload/CardUpload.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
<FileIcon Extension="@item.GetExtension()"></FileIcon>
}
</div>
<div class="upload-item-size"><span>@item.GetFileName()</span> (@item.Size.ToFileSizeString())</div>
<div class="upload-item-size">
<span>@item.GetFileName()</span>
@if (ShowFileSize)
{
<span class="file-size-view">(@item.Size.ToFileSizeString())</span>
}
</div>
<div class="upload-item-actions">
<div class="btn-group">
@if (BeforeActionButtonTemplate != null)
Expand Down
6 changes: 6 additions & 0 deletions src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public partial class CardUpload<TValue>
[Parameter]
public RenderFragment<UploadFile>? ActionButtonTemplate { get; set; }

/// <summary>
/// 获得/设置 是否显示文件尺寸,默认为true显示
/// </summary>
[Parameter]
public bool ShowFileSize { get; set; } = true;

/// <summary>
/// 获得/设置 新建图标
/// </summary>
Expand Down
8 changes: 6 additions & 2 deletions test/UnitTest/Components/UploadCardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public async Task CardUpload_Ok()
{
pb.Add(a => a.ShowZoomButton, true);
pb.Add(a => a.ShowDeleteButton, true);
pb.Add(a => a.ShowFileSize, true);
pb.Add(a => a.OnDelete, file =>
{
deleted = true;
Expand All @@ -35,6 +36,7 @@ public async Task CardUpload_Ok()
new() { FileName = null! }
]);
});
cut.Contains("file-size-view");
cut.Contains("bb-previewer collapse active");
cut.Contains("aria-label=\"zoom\"");
cut.Contains("aria-label=\"delete\"");
Expand Down Expand Up @@ -123,9 +125,11 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
{
pb.Add(a => a.IsUploadButtonAtFirst, true);
pb.Add(a => a.IsMultiple, true);
pb.Add(a => a.ShowFileSize, false);
pb.Add(a => a.ShowZoomButton, false);
pb.Add(a => a.ShowDeleteButton, false);
});
cut.DoesNotContain("file-size-view");
cut.DoesNotContain("aria-label=\"zoom\"");
cut.DoesNotContain("aria-label=\"delete\"");
}
Expand Down Expand Up @@ -157,7 +161,7 @@ public void AllowExtensions_Ok()
new() { FileName = "test.dba" }
]);
});
cut.Contains("<span>test.dba</span> (0 B)");
cut.Contains("<span>test.dba</span><span class=\"file-size-view\">(0 B)</span>");

cut.Render(pb =>
{
Expand All @@ -166,7 +170,7 @@ public void AllowExtensions_Ok()
new() { File = new MockBrowserFile("demo.dba") }
]);
});
cut.Contains("<span>demo.dba</span> (0 B)");
cut.Contains("<span>demo.dba</span><span class=\"file-size-view\">(0 B)</span>");
}

[Fact]
Expand Down