File tree Expand file tree Collapse file tree 4 files changed +53
-20
lines changed
src/BootstrapBlazor/Components/Upload Expand file tree Collapse file tree 4 files changed +53
-20
lines changed Original file line number Diff line number Diff line change 1- @namespace BootstrapBlazor.Components
1+ @namespace BootstrapBlazor.Components
22@typeparam TValue
33@inherits FileListUploadBase <TValue >
44
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 )
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 {
Original file line number Diff line number Diff line change 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>
Original file line number Diff line number Diff line change 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 } ;
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 {
Original file line number Diff line number Diff 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 ]
You can’t perform that action at this time.
0 commit comments