Skip to content

Commit c045592

Browse files
momijijinArgoZhang
andauthored
feat(AvatarUpload): preview when click backdrop (#7368)
* refactor(AvatarUpload): Rewrite zoom event,align the current item index. 1. Make the hover style of the delete button more prominent, 2. Rewrite zoom onclick event and set stopPropagation. * refactor(AvatarUpload): Update unit test * refactor(AvatarUpload): Refactor the related logic to reduce redundant calculations. * refactor(AvatarUpload): Update unit test * refactor(AvatarUpload): Unit test need ok uploadFile, Files search change to use PrevUrl * refactor(AvatarUpload): Update unit test * refactor(AvatarUpload): Update unit test * refactor(AvatarUpload): Update unit test * refactor: 重构代码 * chore: 更新编码方式 * style: 微调样式 * style: 更新样式 * Revert "refactor(AvatarUpload): Update unit test" This reverts commit 7e55079. * Revert "refactor(AvatarUpload): Update unit test" This reverts commit 7827b37. * Revert "refactor(AvatarUpload): Update unit test" This reverts commit 84f274e. * chore: 重构单元测试 * test: 增加单元测试 * test: 更新单元测试 * chore: bump version 10.1.4 --------- Co-Authored-By: jin momiji <[email protected]> Co-authored-by: Argo Zhang <[email protected]>
1 parent 3c92843 commit c045592

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.1.4-beta07</Version>
4+
<Version>10.1.4</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Upload/AvatarUpload.razor

Lines changed: 4 additions & 3 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 UploadBase<TValue>
44

@@ -16,8 +16,9 @@
1616
{
1717
<div @key="item" class="@GetItemClassString()" id="@item.ValidateId" style="@ItemStyleString">
1818
<Avatar Url="@item.PrevUrl" />
19-
<div class="upload-item-actions">
20-
<span class="upload-item-delete" @onclick="@(e => OnFileDelete(item))">
19+
<div class="upload-item-actions" @onclick="@(() => Preview(item))">
20+
<span class="upload-item-delete" @onclick="@(e => OnFileDelete(item))"
21+
@onclick:stopPropagation="true">
2122
<i class="@DeleteIcon"></i>
2223
</span>
2324
@if (GetShowProgress(item))

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

Lines changed: 14 additions & 2 deletions
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
@@ -156,12 +156,24 @@ protected override async Task TriggerOnChanged(UploadFile file)
156156
/// <returns></returns>
157157
public async Task Preview()
158158
{
159-
if(ShowPreviewList)
159+
if (ShowPreviewList)
160160
{
161161
await InvokeVoidAsync("preview", PreviewerId, 0);
162162
}
163163
}
164164

165+
private async Task Preview(UploadFile file)
166+
{
167+
if (!string.IsNullOrEmpty(file.PrevUrl))
168+
{
169+
var index = Files.FindIndex(r => r.PrevUrl == file.PrevUrl);
170+
if (index != -1)
171+
{
172+
await InvokeVoidAsync("preview", PreviewerId, index);
173+
}
174+
}
175+
}
176+
165177
private IReadOnlyCollection<ValidationResult> _results = [];
166178

167179
/// <summary>

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
}
8686

8787
.upload .upload-body.is-list .cancel-icon {
88-
margin-left: .5rem;
88+
margin-inline-start: .5rem;
8989
color: var(--bs-danger);
9090
}
9191

@@ -157,6 +157,14 @@
157157
.upload .upload-body.is-avatar .upload-item:hover .upload-item-actions .upload-item-delete {
158158
display: block;
159159
color: var(--bs-danger);
160+
padding: 0.25rem;
161+
border-radius: var(--bs-border-radius);
162+
border: 1px solid var(--bs-danger);
163+
}
164+
165+
.upload .upload-body.is-avatar .upload-item:hover .upload-item-actions .upload-item-delete:hover {
166+
color: var(--bs-white);
167+
background-color: var(--bs-danger);
160168
}
161169

162170
.upload .upload-body.is-avatar .upload-item.is-invalid .upload-item-spin {

test/UnitTest/Components/UploadAvatarTest.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,31 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
9898
});
9999
}
100100

101+
[Fact]
102+
public async Task Preview_Ok()
103+
{
104+
var cut = Context.Render<AvatarUpload<string>>(pb =>
105+
{
106+
pb.Add(a => a.DefaultFileList, new List<UploadFile>()
107+
{
108+
new UploadFile() { PrevUrl = "./sample/preview.jpg" }
109+
});
110+
});
111+
112+
var action = cut.Find(".upload-item-actions");
113+
await cut.InvokeAsync(() => action.Click());
114+
115+
cut.Render(pb =>
116+
{
117+
pb.Add(a => a.DefaultFileList, new List<UploadFile>()
118+
{
119+
new UploadFile() { PrevUrl = "" }
120+
});
121+
});
122+
action = cut.Find(".upload-item-actions");
123+
await cut.InvokeAsync(() => action.Click());
124+
}
125+
101126
[Fact]
102127
public async Task AvatarUpload_ValidateForm_Ok()
103128
{

0 commit comments

Comments
 (0)