@tent-official/react-walkthrough 1.3.0 → 1.3.3

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 CHANGED
@@ -92,7 +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
+ | `onStepNext` | `Record<number, () => void>` | — | Map of original step index → callback. Fires when the user clicks "Next" from that step. Example: `{ 0: () => console.log("left step 0"), 2: () => doSomething() }` |
96
96
 
97
97
  **Returns:** `{ start: () => void }`
98
98
 
@@ -114,9 +114,9 @@ Hook to register a walkthrough tour.
114
114
  | `nextLabel` | `string` | — | Override tour-level `nextLabel` for this step |
115
115
  | `prevLabel` | `string` | — | Override tour-level `prevLabel` for this step |
116
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 |
117
+ | `displayStep` | `number` | — | Override the displayed step number for this step (display-only) |
118
+ | `displayTotal` | `number` | — | Override the displayed total for this step (display-only) |
119
+ | `forceRecompute` | `boolean` | | When `true`, forces a DOM re-read before advancing to the next step. Useful when the next element is conditionally rendered and needs a layout update to appear |
120
120
 
121
121
  ### `IStepDescription`
122
122
 
@@ -258,44 +258,9 @@ The popover automatically positions itself to stay within the viewport:
258
258
 
259
259
  The popover also waits for the target element to be scrolled into view before appearing.
260
260
 
261
- ## Step-Level Callbacks (`onStepNext`)
261
+ ## Instant Dismiss
262
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
- ```
263
+ When the user clicks **Done** on the last step (or **Skip** at any step), the highlight and popover vanish **instantly** in the same render frame — no lingering overlay or flash.
299
264
 
300
265
  ## License
301
266
 
package/dist/index.js CHANGED
@@ -637,6 +637,7 @@ var WalkthroughOverlay = ({
637
637
  const popoverRef = react.useRef(null);
638
638
  const [popoverPos, setPopoverPos] = react.useState(null);
639
639
  const [popoverHidden, setPopoverHidden] = react.useState(false);
640
+ const [isDismissing, setIsDismissing] = react.useState(false);
640
641
  const displayStepRef = react.useRef(null);
641
642
  const displayPosRef = react.useRef(null);
642
643
  const [validSteps, setValidSteps] = react.useState([]);
@@ -649,6 +650,7 @@ var WalkthroughOverlay = ({
649
650
  if (!activeTour) {
650
651
  setValidSteps([]);
651
652
  setIsDelaying(false);
653
+ setIsDismissing(false);
652
654
  waitingForElsRef.current = false;
653
655
  delayDoneForRef.current = null;
654
656
  skipNextRecomputeRef.current = false;
@@ -848,6 +850,7 @@ var WalkthroughOverlay = ({
848
850
  setPopoverHidden(false);
849
851
  }, [popoverHidden, isAnimating, step, popoverPos]);
850
852
  if (!activeTour) return null;
853
+ if (isDismissing) return null;
851
854
  if (_activeOverlayId !== null && _activeOverlayId !== instanceIdRef.current) {
852
855
  return null;
853
856
  }
@@ -938,6 +941,7 @@ var WalkthroughOverlay = ({
938
941
  const hasMoreOriginalSteps = currentOrigIdx < activeTour.steps.length - 1;
939
942
  const effectiveIsLast = isLast && !(hasTrigger && hasMoreOriginalSteps);
940
943
  if (effectiveIsLast) {
944
+ setIsDismissing(true);
941
945
  if (activeTour.handleWhenLastStep) activeTour.handleWhenLastStep();
942
946
  completeTour();
943
947
  } else {
@@ -1050,8 +1054,7 @@ var WalkthroughOverlay = ({
1050
1054
  }
1051
1055
  return;
1052
1056
  }
1053
- setPopoverHidden(true);
1054
- setPopoverPos(null);
1057
+ setIsDismissing(true);
1055
1058
  if (activeTour.handleWhenLastStep) activeTour.handleWhenLastStep();
1056
1059
  setTimeout(() => completeTour(), 300);
1057
1060
  return;
@@ -1070,6 +1073,7 @@ var WalkthroughOverlay = ({
1070
1073
  }
1071
1074
  };
1072
1075
  const skip = () => {
1076
+ setIsDismissing(true);
1073
1077
  completeTour();
1074
1078
  };
1075
1079
  const popoverWidth = clampSize(step.width, window.innerWidth);