Skip to content

Commit 3a939f2

Browse files
authored
feat(ResizeNotification): remove ResizeNotification service (#4550)
* chore: 更新 scss 链接 * refactor: 移除服务 * refactor: 移除 ResizeNotification 组件 * refactor: 增加系列化标签 * refactor: 更新 Responsive 组件 * test: 更新单元测试 * test: 更新单元测试 * refactor: 更新代码 * test: 更新单元测试 * test: 更新单元测试 * test: 更新单元测试
1 parent d35150c commit 3a939f2

File tree

12 files changed

+77
-212
lines changed

12 files changed

+77
-212
lines changed

src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<ToastContainer @ref="ToastContainer"></ToastContainer>
1010
<DrawerContainer></DrawerContainer>
1111

12-
<ResizeNotification></ResizeNotification>
1312
<ConnectionHub></ConnectionHub>
1413
<Mask></Mask>
1514

src/BootstrapBlazor/Components/ResizeNotification/ResizeNotification.razor.scss

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/BootstrapBlazor/Components/ResizeNotification/ResizeNotificationService.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/BootstrapBlazor/Components/ResizeNotification/Responsive.cs

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/BootstrapBlazor/Components/ResizeNotification/ResizeNotification.cs renamed to src/BootstrapBlazor/Components/Responsive/Responsive.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
namespace BootstrapBlazor.Components;
77

88
/// <summary>
9-
/// 网页尺寸变化通知组件
9+
/// 响应监听 组件
1010
/// </summary>
1111
[BootstrapModuleAutoLoader(ModuleName = "responsive", JSObjectReference = true)]
12-
public class ResizeNotification : BootstrapModuleComponentBase
12+
public class Responsive : BootstrapModuleComponentBase
1313
{
14-
[Inject]
15-
[NotNull]
16-
private ResizeNotificationService? ResizeService { get; set; }
14+
/// <summary>
15+
/// 获得/设置 浏览器断点阈值改变时触发 默认 null
16+
/// </summary>
17+
[Parameter]
18+
public Func<BreakPoint, Task>? OnBreakPointChanged { get; set; }
19+
20+
private BreakPoint _breakPoint = BreakPoint.None;
1721

1822
/// <summary>
1923
/// <inheritdoc/>
@@ -24,16 +28,16 @@ public class ResizeNotification : BootstrapModuleComponentBase
2428
/// <summary>
2529
/// JSInvoke 回调方法
2630
/// </summary>
27-
/// <param name="pointString"></param>
31+
/// <param name="breakPoint"></param>
2832
/// <returns></returns>
2933
[JSInvokable]
30-
public Task OnResize(string pointString)
34+
public async Task OnResize(BreakPoint breakPoint)
3135
{
32-
var point = BreakPoint.ExtraExtraLarge;
33-
if (Enum.TryParse<BreakPoint>(pointString, true, out var p))
36+
if (OnBreakPointChanged != null && breakPoint != _breakPoint)
3437
{
35-
point = p;
38+
_breakPoint = breakPoint;
39+
40+
await OnBreakPointChanged(breakPoint);
3641
}
37-
return ResizeService.InvokeAsync(point);
3842
}
3943
}

src/BootstrapBlazor/Components/Table/Table.razor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,11 +1148,11 @@ private async Task ProcessFirstRender()
11481148
/// <returns></returns>
11491149
protected override async Task InvokeInitAsync()
11501150
{
1151-
ScreenSize = BreakPoint.ExtraExtraLarge;
1152-
var pointString = await InvokeAsync<string?>("getResponsive");
1153-
if (Enum.TryParse<BreakPoint>(pointString, true, out var p))
1151+
ScreenSize = BreakPoint.None;
1152+
var breakPoint = await InvokeAsync<BreakPoint>("getResponsive");
1153+
if (breakPoint != BreakPoint.None)
11541154
{
1155-
ScreenSize = p;
1155+
ScreenSize = breakPoint;
11561156
}
11571157
}
11581158

src/BootstrapBlazor/Enums/BreakPoint.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6-
using System.Text.Json.Serialization;
7-
86
namespace BootstrapBlazor.Components;
97

108
/// <summary>
119
/// BreakPoint 枚举
1210
/// </summary>
13-
[JsonConverter(typeof(JsonStringEnumConverter))]
11+
[JsonEnumConverter(true)]
1412
public enum BreakPoint
1513
{
1614
/// <summary>

src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public static IServiceCollection AddBootstrapBlazor(this IServiceCollection serv
8686
services.AddScoped<AjaxService>();
8787
services.AddScoped(typeof(DragDropService<>));
8888
services.AddScoped<ClipboardService>();
89-
services.AddScoped<ResizeNotificationService>();
9089
services.AddScoped<NotificationService>();
9190
services.AddScoped<EyeDropperService>();
9291
services.AddScoped<WebSpeechService>();

src/BootstrapBlazor/wwwroot/scss/components.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
@import "../../Components/Rate/Rate.razor.scss";
7373
@import "../../Components/Reconnector/ReconnectorContent.razor.scss";
7474
@import "../../Components/Repeater/Repeater.razor.scss";
75-
@import "../../Components/ResizeNotification/ResizeNotification.razor.scss";
7675
@import "../../Components/RibbonTab/RibbonTab.razor.scss";
7776
@import "../../Components/Row/Row.razor.scss";
7877
@import "../../Components/Scroll/Scroll.razor.scss";

src/BootstrapBlazor/wwwroot/scss/root.scss

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,47 @@ a, a:hover, a:focus {
8585
animation: clip .3s ease-in;
8686
}
8787

88+
body:before {
89+
content: "extraExtraSmall";
90+
display: none;
91+
}
92+
93+
@media (min-width:375px) {
94+
body:before {
95+
content: "extraSmall";
96+
}
97+
}
98+
99+
@media (min-width:576px) {
100+
body:before {
101+
content: "small";
102+
}
103+
}
104+
105+
@media (min-width:768px) {
106+
body:before {
107+
content: "medium";
108+
}
109+
}
110+
111+
@media (min-width:992px) {
112+
body:before {
113+
content: "large";
114+
}
115+
}
116+
117+
@media (min-width:1200px) {
118+
body:before {
119+
content: "extraLarge";
120+
}
121+
}
122+
123+
@media (min-width:1400px) {
124+
body:before {
125+
content: "extraExtraLarge";
126+
}
127+
}
128+
88129
@keyframes clip {
89130
from {
90131
clip-path: circle(0% at var(--bb-theme-x) var(--bb-theme-y));

0 commit comments

Comments
 (0)