Skip to content

Commit 3c92843

Browse files
momijijinArgoZhang
andauthored
feat(CardUpload): add ShowFileSize parameter (#7370)
* feat(CardUpload): Add ShowFileSize * refactor(CardUpload): Update unit test * refactor(CardUpload): Update unit test * refactor(CardUpload): Update unit test * doc: 更新注释 * doc: 调整样式 * test: 重构单元测试 * test: 更新单元测试 --------- Co-authored-by: Argo Zhang <[email protected]>
1 parent 9acaf8f commit 3c92843

File tree

4 files changed

+53
-20
lines changed

4 files changed

+53
-20
lines changed

src/BootstrapBlazor/Components/Upload/CardUpload.razor

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@namespace BootstrapBlazor.Components
1+
@namespace BootstrapBlazor.Components
22
@typeparam TValue
33
@inherits FileListUploadBase<TValue>
44

@@ -29,7 +29,13 @@
2929
<FileIcon Extension="@item.GetExtension()"></FileIcon>
3030
}
3131
</div>
32-
<div class="upload-item-size"><span>@item.GetFileName()</span> (@item.Size.ToFileSizeString())</div>
32+
<div class="upload-item-file">
33+
<span class="upload-item-file-name">@item.GetFileName()</span>
34+
@if (ShowFileSize)
35+
{
36+
<span class="upload-item-file-size">(@item.Size.ToFileSizeString())</span>
37+
}
38+
</div>
3339
<div class="upload-item-actions">
3440
<div class="btn-group">
3541
@if (BeforeActionButtonTemplate != null)
@@ -54,10 +60,10 @@
5460
<i class="@CancelIcon"></i>
5561
</button>
5662
}
57-
@if (ActionButtonTemplate != null)
58-
{
59-
@ActionButtonTemplate(item)
60-
}
63+
@if (ActionButtonTemplate != null)
64+
{
65+
@ActionButtonTemplate(item)
66+
}
6167
</div>
6268
@if (ShowDeleteButton)
6369
{

src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
@@ -72,6 +72,12 @@ public partial class CardUpload<TValue>
7272
[Parameter]
7373
public RenderFragment<UploadFile>? ActionButtonTemplate { get; set; }
7474

75+
/// <summary>
76+
/// 获得/设置 是否显示文件尺寸,默认为 true 显示
77+
/// </summary>
78+
[Parameter]
79+
public bool ShowFileSize { get; set; } = true;
80+
7581
/// <summary>
7682
/// 获得/设置 新建图标
7783
/// </summary>

src/BootstrapBlazor/Components/Upload/InputUpload.razor.scss

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@use "../../wwwroot/scss/variables" as *;
1+
@use "../../wwwroot/scss/variables" as *;
22

33
.upload {
44
--bb-upload-body-margin-top: #{$bb-upload-body-margin-top};
@@ -208,21 +208,22 @@
208208
display: none;
209209
}
210210

211-
.upload .upload-body.is-card .upload-item-size {
211+
.upload .upload-body.is-card .upload-item-file {
212212
margin: 1rem auto;
213-
text-align: center;
214213
font-size: 0.625rem;
215214
display: flex;
215+
flex-wrap: nowrap;
216216
justify-content: center;
217-
}
217+
align-items: center;
218218

219-
.upload .upload-body.is-card .upload-item-size span {
220-
max-width: calc(100% - 4.5rem);
221-
overflow: hidden;
222-
text-overflow: ellipsis;
223-
display: block;
224-
white-space: nowrap;
225-
padding-right: 0.25rem;
219+
.upload-item-file-name {
220+
max-width: calc(100% - 4.5rem);
221+
overflow: hidden;
222+
text-overflow: ellipsis;
223+
display: block;
224+
white-space: nowrap;
225+
padding-right: 0.25rem;
226+
}
226227
}
227228

228229
.upload .upload-item .upload-item-label {

test/UnitTest/Components/UploadCardTest.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,26 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
130130
cut.DoesNotContain("aria-label=\"delete\"");
131131
}
132132

133+
[Fact]
134+
public void ShowFileSize_Ok()
135+
{
136+
var cut = Context.Render<CardUpload<string>>(pb =>
137+
{
138+
pb.Add(a => a.ShowFileSize, true);
139+
pb.Add(a => a.DefaultFileList,
140+
[
141+
new() { FileName = "Test-File1.text" },
142+
]);
143+
});
144+
cut.Contains("upload-item-file-size");
145+
146+
cut.Render(pb =>
147+
{
148+
pb.Add(a => a.ShowFileSize, false);
149+
});
150+
cut.DoesNotContain("upload-item-file-size");
151+
}
152+
133153
[Fact]
134154
public void CardUpload_ValidateForm_Ok()
135155
{
@@ -157,7 +177,7 @@ public void AllowExtensions_Ok()
157177
new() { FileName = "test.dba" }
158178
]);
159179
});
160-
cut.Contains("<span>test.dba</span> (0 B)");
180+
cut.Contains("test.dba");
161181

162182
cut.Render(pb =>
163183
{
@@ -166,7 +186,7 @@ public void AllowExtensions_Ok()
166186
new() { File = new MockBrowserFile("demo.dba") }
167187
]);
168188
});
169-
cut.Contains("<span>demo.dba</span> (0 B)");
189+
cut.Contains("demo.dba");
170190
}
171191

172192
[Fact]

0 commit comments

Comments
 (0)