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
18 changes: 12 additions & 6 deletions src/BootstrapBlazor/Components/Upload/CardUpload.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@namespace BootstrapBlazor.Components
@namespace BootstrapBlazor.Components
@typeparam TValue
@inherits FileListUploadBase<TValue>

Expand Down 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-file">
<span class="upload-item-file-name">@item.GetFileName()</span>
@if (ShowFileSize)
{
<span class="upload-item-file-size">(@item.Size.ToFileSizeString())</span>
}
</div>
<div class="upload-item-actions">
<div class="btn-group">
@if (BeforeActionButtonTemplate != null)
Expand All @@ -54,10 +60,10 @@
<i class="@CancelIcon"></i>
</button>
}
@if (ActionButtonTemplate != null)
{
@ActionButtonTemplate(item)
}
@if (ActionButtonTemplate != null)
{
@ActionButtonTemplate(item)
}
</div>
@if (ShowDeleteButton)
{
Expand Down
8 changes: 7 additions & 1 deletion src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
Expand Down 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
23 changes: 12 additions & 11 deletions src/BootstrapBlazor/Components/Upload/InputUpload.razor.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use "../../wwwroot/scss/variables" as *;
@use "../../wwwroot/scss/variables" as *;

.upload {
--bb-upload-body-margin-top: #{$bb-upload-body-margin-top};
Expand Down Expand Up @@ -208,21 +208,22 @@
display: none;
}

.upload .upload-body.is-card .upload-item-size {
.upload .upload-body.is-card .upload-item-file {
margin: 1rem auto;
text-align: center;
font-size: 0.625rem;
display: flex;
flex-wrap: nowrap;
justify-content: center;
}
align-items: center;

.upload .upload-body.is-card .upload-item-size span {
max-width: calc(100% - 4.5rem);
overflow: hidden;
text-overflow: ellipsis;
display: block;
white-space: nowrap;
padding-right: 0.25rem;
.upload-item-file-name {
max-width: calc(100% - 4.5rem);
overflow: hidden;
text-overflow: ellipsis;
display: block;
white-space: nowrap;
padding-right: 0.25rem;
}
}

.upload .upload-item .upload-item-label {
Expand Down
24 changes: 22 additions & 2 deletions test/UnitTest/Components/UploadCardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
cut.DoesNotContain("aria-label=\"delete\"");
}

[Fact]
public void ShowFileSize_Ok()
{
var cut = Context.Render<CardUpload<string>>(pb =>
{
pb.Add(a => a.ShowFileSize, true);
pb.Add(a => a.DefaultFileList,
[
new() { FileName = "Test-File1.text" },
]);
});
cut.Contains("upload-item-file-size");

cut.Render(pb =>
{
pb.Add(a => a.ShowFileSize, false);
});
cut.DoesNotContain("upload-item-file-size");
}

[Fact]
public void CardUpload_ValidateForm_Ok()
{
Expand Down Expand Up @@ -157,7 +177,7 @@ public void AllowExtensions_Ok()
new() { FileName = "test.dba" }
]);
});
cut.Contains("<span>test.dba</span> (0 B)");
cut.Contains("test.dba");

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

[Fact]
Expand Down