Skip to content

Commit f73fcc3

Browse files
authored
feat(DriverJs): add OverlayClickBehavior support (#707)
* chore: bump version 10.0.1 * chore: updated version to 1.4.0 * feat: add OverlayClickBehavior support * feat: 更改回调参数
1 parent 0db83d7 commit f73fcc3

6 files changed

Lines changed: 716 additions & 638 deletions

File tree

src/components/BootstrapBlazor.DriverJs/BootstrapBlazor.DriverJs.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-
<RootNamespace>BootstrapBlazor.Components</RootNamespace>
4+
<Version>10.0.1</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/components/BootstrapBlazor.DriverJs/Components/DriverJs.razor.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

@@ -67,7 +67,7 @@ public async Task Start(int? index = 0)
6767
{
6868
string? ret = null;
6969

70-
if (Config?.OnDestroyStartedAsync != null)
70+
if (Config is { OnDestroyStartedAsync: not null })
7171
{
7272
ret = await Config.OnDestroyStartedAsync(Config, index);
7373
}
@@ -81,12 +81,25 @@ public async Task Start(int? index = 0)
8181
[JSInvokable]
8282
public async Task OnDestroyed()
8383
{
84-
if (Config?.OnDestroyedAsync != null)
84+
if (Config is { OnDestroyedAsync: not null })
8585
{
8686
await Config.OnDestroyedAsync();
8787
}
8888
}
8989

90+
/// <summary>
91+
/// 点击组件这招回调方法由 JavaScript 调用
92+
/// </summary>
93+
/// <returns></returns>
94+
[JSInvokable]
95+
public async Task OnOverlayClicked(int index)
96+
{
97+
if (Config is { OnOverlayClickedAsync: not null })
98+
{
99+
await Config.OnOverlayClickedAsync(this, Config, index);
100+
}
101+
}
102+
90103
/// <summary>
91104
/// Starts at step 0
92105
/// </summary>

src/components/BootstrapBlazor.DriverJs/Components/DriverJs.razor.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { driver } from "../driver.js"
1+
import { driver } from "../driver.js.mjs"
22
import { addLink } from '../../BootstrapBlazor/modules/utility.js'
33
import Data from "../../BootstrapBlazor/modules/data.js"
44

@@ -18,7 +18,7 @@ export function start(id, options, config) {
1818
if (d) {
1919
d.config = config;
2020
const { index } = config;
21-
const { hookDestroyStarted, hookDestroyed } = options;
21+
const { hookDestroyStarted, hookDestroyed, overlayClickBehavior } = options;
2222
if (hookDestroyStarted) {
2323
delete options.hookDestroyStarted;
2424
options.onDestroyStarted = async (el, step, { state }) => {
@@ -34,6 +34,12 @@ export function start(id, options, config) {
3434
d.invoke.invokeMethodAsync("OnDestroyed");
3535
};
3636
}
37+
if (overlayClickBehavior === "function") {
38+
options.overlayClickBehavior = async (el, step, { state }) => {
39+
await d.invoke.invokeMethodAsync("OnOverlayClicked", state.activeIndex)
40+
};
41+
}
42+
3743
const driverObj = driver(options);
3844
d.driver = driverObj;
3945
driverObj.drive(index);

src/components/BootstrapBlazor.DriverJs/Components/DriverJsConfig.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

@@ -142,4 +142,19 @@ public class DriverJsConfig
142142
/// </summary>
143143
[JsonIgnore]
144144
public Func<Task>? OnDestroyedAsync { get; set; }
145+
146+
/// <summary>
147+
/// 获得/设置 点击遮罩行为 close nextStep function 默认 close
148+
/// </summary>
149+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
150+
public string? OverlayClickBehavior { get; set; }
151+
152+
[JsonInclude]
153+
private string OverlayClickCallbackMethod => nameof(OnOverlayClickedAsync);
154+
155+
/// <summary>
156+
/// 获得/设置 组件销毁前回调方法名称
157+
/// </summary>
158+
[JsonIgnore]
159+
public Func<DriverJs, DriverJsConfig, int, Task>? OnOverlayClickedAsync { get; set; }
145160
}

0 commit comments

Comments
 (0)