@tent-official/react-walkthrough 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,6 +92,7 @@ Hook to register a walkthrough tour.
|
|
|
92
92
|
| `displayTotal` | `number` | — | Override the total step count displayed in the step counter (display-only, does not affect logic) |
|
|
93
93
|
| `displayStepOffset` | `number` | `0` | Offset added to the displayed current step number (display-only, does not affect logic). e.g. `displayStepOffset: 3` with 3 real steps shows 4/total → 5/total → 6/total |
|
|
94
94
|
| `isClearLastPositionOnEnd` | `boolean` | `false` | When `true`, clears the saved last highlight position when the tour ends. This prevents the next tour from animating its highlight from this tour's last position |
|
|
95
|
+
| `onStepNext` | `Record<number, () => void>` | — | Callbacks fired when the user clicks "Next" on a specific step. The key is the original step index (0-based). Called right before advancing to the next step |
|
|
95
96
|
|
|
96
97
|
**Returns:** `{ start: () => void }`
|
|
97
98
|
|
|
@@ -113,6 +114,9 @@ Hook to register a walkthrough tour.
|
|
|
113
114
|
| `nextLabel` | `string` | — | Override tour-level `nextLabel` for this step |
|
|
114
115
|
| `prevLabel` | `string` | — | Override tour-level `prevLabel` for this step |
|
|
115
116
|
| `skipLabel` | `string` | — | Override tour-level `skipLabel` for this step |
|
|
117
|
+
| `displayStep` | `number` | — | Override the displayed current step number for this step (display-only, does not affect logic) |
|
|
118
|
+
| `displayTotal` | `number` | — | Override the displayed total step count for this step (display-only, does not affect logic) |
|
|
119
|
+
| `forceRecompute` | `boolean` | `false` | When `true`, forces a recompute of valid steps after advancing from this step. Useful when the next step's element is hidden/conditional and needs DOM changes to become visible |
|
|
116
120
|
|
|
117
121
|
### `IStepDescription`
|
|
118
122
|
|
|
@@ -254,6 +258,45 @@ The popover automatically positions itself to stay within the viewport:
|
|
|
254
258
|
|
|
255
259
|
The popover also waits for the target element to be scrolled into view before appearing.
|
|
256
260
|
|
|
261
|
+
## Step-Level Callbacks (`onStepNext`)
|
|
262
|
+
|
|
263
|
+
Use `onStepNext` to fire a custom function when the user clicks "Next" on a specific step. The key is the original step index (0-based):
|
|
264
|
+
|
|
265
|
+
```jsx
|
|
266
|
+
useWalkthrough({
|
|
267
|
+
name: "setup-tour",
|
|
268
|
+
steps: [
|
|
269
|
+
{ el: "print-side", title: "Print Side", description: [{ description: "Select print side" }] },
|
|
270
|
+
{ el: "print-system", title: "Print System", description: [{ description: "Select print system" }] },
|
|
271
|
+
{ el: "print-color", title: "Print Color", description: [{ description: "Select color" }] },
|
|
272
|
+
],
|
|
273
|
+
onStepNext: {
|
|
274
|
+
0: () => openPrintSystemDropdown(), // fired when leaving step 0
|
|
275
|
+
1: () => fetchColorOptions(), // fired when leaving step 1
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Force Recompute (`forceRecompute`)
|
|
281
|
+
|
|
282
|
+
When a step's next element is conditionally rendered (hidden until some action), use `forceRecompute` to wait for it to appear before advancing:
|
|
283
|
+
|
|
284
|
+
```jsx
|
|
285
|
+
steps: [
|
|
286
|
+
{
|
|
287
|
+
el: "print-side",
|
|
288
|
+
title: "Print Side",
|
|
289
|
+
forceRecompute: true, // wait for next element to appear after advancing
|
|
290
|
+
description: [{ description: "Select print side — the next section will appear after selection" }],
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
el: "print-system", // this element is hidden until print-side is selected
|
|
294
|
+
title: "Print System",
|
|
295
|
+
description: [{ description: "Now select the print system" }],
|
|
296
|
+
},
|
|
297
|
+
]
|
|
298
|
+
```
|
|
299
|
+
|
|
257
300
|
## License
|
|
258
301
|
|
|
259
302
|
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -103,6 +103,8 @@ interface IUseWalkthroughOptions {
|
|
|
103
103
|
displayStepOffset?: number;
|
|
104
104
|
/** When true, clears the saved last highlight position when the tour ends. This prevents the next tour from animating its highlight FROM this tour's last position. Default: false */
|
|
105
105
|
isClearLastPositionOnEnd?: boolean;
|
|
106
|
+
/** Callbacks fired when the user clicks "Next" on a specific step. The key is the original step index (0-based). Called right before advancing to the next step. Example: `onStepNext: { 0: () => openDropdown(), 2: () => fetchData() }` */
|
|
107
|
+
onStepNext?: Record<number, () => void>;
|
|
106
108
|
}
|
|
107
109
|
/**
|
|
108
110
|
* Return value of the useWalkthrough hook.
|
package/dist/index.d.ts
CHANGED
|
@@ -103,6 +103,8 @@ interface IUseWalkthroughOptions {
|
|
|
103
103
|
displayStepOffset?: number;
|
|
104
104
|
/** When true, clears the saved last highlight position when the tour ends. This prevents the next tour from animating its highlight FROM this tour's last position. Default: false */
|
|
105
105
|
isClearLastPositionOnEnd?: boolean;
|
|
106
|
+
/** Callbacks fired when the user clicks "Next" on a specific step. The key is the original step index (0-based). Called right before advancing to the next step. Example: `onStepNext: { 0: () => openDropdown(), 2: () => fetchData() }` */
|
|
107
|
+
onStepNext?: Record<number, () => void>;
|
|
106
108
|
}
|
|
107
109
|
/**
|
|
108
110
|
* Return value of the useWalkthrough hook.
|
package/dist/index.js
CHANGED
|
@@ -222,11 +222,13 @@ var useWalkthrough = ({
|
|
|
222
222
|
animationSpeed = 350,
|
|
223
223
|
displayTotal,
|
|
224
224
|
displayStepOffset,
|
|
225
|
-
isClearLastPositionOnEnd = false
|
|
225
|
+
isClearLastPositionOnEnd = false,
|
|
226
|
+
onStepNext
|
|
226
227
|
}) => {
|
|
227
228
|
const started = react.useRef(false);
|
|
228
229
|
const onCompleteRef = react.useRef(onWalkthroughComplete);
|
|
229
230
|
const handleWhenLastStepRef = react.useRef(handleWhenLastStep);
|
|
231
|
+
const onStepNextRef = react.useRef(onStepNext);
|
|
230
232
|
const conditionMet = startWhenCondition === void 0 ? true : typeof startWhenCondition === "function" ? startWhenCondition() : !!startWhenCondition;
|
|
231
233
|
react.useEffect(() => {
|
|
232
234
|
onCompleteRef.current = onWalkthroughComplete;
|
|
@@ -234,6 +236,9 @@ var useWalkthrough = ({
|
|
|
234
236
|
react.useEffect(() => {
|
|
235
237
|
handleWhenLastStepRef.current = handleWhenLastStep;
|
|
236
238
|
}, [handleWhenLastStep]);
|
|
239
|
+
react.useEffect(() => {
|
|
240
|
+
onStepNextRef.current = onStepNext;
|
|
241
|
+
}, [onStepNext]);
|
|
237
242
|
const start = react.useCallback(() => {
|
|
238
243
|
if (isDone(storageSuffix, name) || started.current) return;
|
|
239
244
|
started.current = true;
|
|
@@ -257,7 +262,8 @@ var useWalkthrough = ({
|
|
|
257
262
|
animationSpeed,
|
|
258
263
|
displayTotal,
|
|
259
264
|
displayStepOffset,
|
|
260
|
-
isClearLastPositionOnEnd
|
|
265
|
+
isClearLastPositionOnEnd,
|
|
266
|
+
onStepNext: onStepNextRef.current
|
|
261
267
|
}
|
|
262
268
|
});
|
|
263
269
|
}, [
|
|
@@ -983,6 +989,12 @@ var WalkthroughOverlay = ({
|
|
|
983
989
|
}
|
|
984
990
|
};
|
|
985
991
|
const next = () => {
|
|
992
|
+
var _a2;
|
|
993
|
+
const currentOrigIdx = validSteps[currentValidPos]._originalIdx;
|
|
994
|
+
const stepNextCb = (_a2 = activeTour.onStepNext) == null ? void 0 : _a2[currentOrigIdx];
|
|
995
|
+
if (typeof stepNextCb === "function") {
|
|
996
|
+
stepNextCb();
|
|
997
|
+
}
|
|
986
998
|
const hasTrigger = !!step.triggerElOnNext;
|
|
987
999
|
if (hasTrigger) {
|
|
988
1000
|
setPopoverHidden(true);
|
|
@@ -995,8 +1007,8 @@ var WalkthroughOverlay = ({
|
|
|
995
1007
|
triggerTarget.dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, button: 0 }));
|
|
996
1008
|
triggerTarget.click();
|
|
997
1009
|
}
|
|
998
|
-
const
|
|
999
|
-
const nextOrigIdx =
|
|
1010
|
+
const currentOrigIdx2 = validSteps[currentValidPos]._originalIdx;
|
|
1011
|
+
const nextOrigIdx = currentOrigIdx2 + 1;
|
|
1000
1012
|
const nextStepDef = activeTour.steps[nextOrigIdx];
|
|
1001
1013
|
if (nextStepDef) {
|
|
1002
1014
|
const nextElId = resolveElId(nextStepDef.el);
|