@numidev/react-joyride 1.0.1
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/LICENSE +9 -0
- package/README.md +93 -0
- package/dist/index.cjs +2677 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +753 -0
- package/dist/index.d.mts +753 -0
- package/dist/index.mjs +2638 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +158 -0
- package/src/components/Arrow.tsx +138 -0
- package/src/components/Beacon.tsx +141 -0
- package/src/components/Floater.tsx +381 -0
- package/src/components/Loader.tsx +80 -0
- package/src/components/Overlay.tsx +167 -0
- package/src/components/Portal.tsx +17 -0
- package/src/components/Step.tsx +72 -0
- package/src/components/Tooltip/CloseButton.tsx +29 -0
- package/src/components/Tooltip/DefaultTooltip.tsx +82 -0
- package/src/components/Tooltip/index.tsx +163 -0
- package/src/components/TourRenderer.tsx +157 -0
- package/src/defaults.ts +64 -0
- package/src/global.d.ts +8 -0
- package/src/hooks/useControls.ts +219 -0
- package/src/hooks/useDebugLogger.ts +58 -0
- package/src/hooks/useEventEmitter.ts +55 -0
- package/src/hooks/useFocusTrap.ts +72 -0
- package/src/hooks/useJoyride.tsx +32 -0
- package/src/hooks/useLifecycleEffect.ts +512 -0
- package/src/hooks/usePortalElement.ts +49 -0
- package/src/hooks/usePropSync.ts +84 -0
- package/src/hooks/useScrollEffect.ts +217 -0
- package/src/hooks/useTargetPosition.ts +154 -0
- package/src/hooks/useTourEngine.ts +106 -0
- package/src/index.tsx +23 -0
- package/src/literals/index.ts +61 -0
- package/src/modules/changes.ts +20 -0
- package/src/modules/dom.ts +359 -0
- package/src/modules/helpers.tsx +230 -0
- package/src/modules/step.ts +156 -0
- package/src/modules/store.ts +215 -0
- package/src/modules/svg.ts +40 -0
- package/src/styles.ts +183 -0
- package/src/types/common.ts +315 -0
- package/src/types/components.ts +84 -0
- package/src/types/events.ts +89 -0
- package/src/types/floating.ts +60 -0
- package/src/types/index.ts +8 -0
- package/src/types/props.ts +124 -0
- package/src/types/state.ts +49 -0
- package/src/types/step.ts +108 -0
- package/src/types/utilities.ts +26 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode, SVGAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ACTIONS, EVENTS, LIFECYCLE, ORIGIN, STATUS } from '~/literals';
|
|
4
|
+
|
|
5
|
+
import type { TourData } from './events';
|
|
6
|
+
import type { ValueOf } from './utilities';
|
|
7
|
+
|
|
8
|
+
/** The action that triggered the state update. */
|
|
9
|
+
export type Actions = ValueOf<typeof ACTIONS>;
|
|
10
|
+
|
|
11
|
+
/** A hook that runs after a step completes. Fire-and-forget. */
|
|
12
|
+
export type AfterHook = (data: TourData) => void;
|
|
13
|
+
|
|
14
|
+
/** A hook that runs before a step is shown. The tour waits for the promise to resolve. */
|
|
15
|
+
export type BeforeHook = (data: TourData) => Promise<void>;
|
|
16
|
+
|
|
17
|
+
/** The buttons to show in the tooltip. */
|
|
18
|
+
export type ButtonType = 'back' | 'close' | 'primary' | 'skip';
|
|
19
|
+
|
|
20
|
+
/** The event type passed to the `onEvent` callback. */
|
|
21
|
+
export type Events = ValueOf<typeof EVENTS>;
|
|
22
|
+
|
|
23
|
+
/** The reason a step failed during the tour. */
|
|
24
|
+
export type FailureReason = 'before_hook' | 'target_not_found';
|
|
25
|
+
|
|
26
|
+
/** The rendering phase of the current step. */
|
|
27
|
+
export type Lifecycle = ValueOf<typeof LIFECYCLE>;
|
|
28
|
+
|
|
29
|
+
/** The UI element that triggered the action. */
|
|
30
|
+
export type Origin = ValueOf<typeof ORIGIN>;
|
|
31
|
+
|
|
32
|
+
/** Tooltip and beacon placement positions. */
|
|
33
|
+
export type Placement =
|
|
34
|
+
| 'top'
|
|
35
|
+
| 'top-start'
|
|
36
|
+
| 'top-end'
|
|
37
|
+
| 'bottom'
|
|
38
|
+
| 'bottom-start'
|
|
39
|
+
| 'bottom-end'
|
|
40
|
+
| 'left'
|
|
41
|
+
| 'left-start'
|
|
42
|
+
| 'left-end'
|
|
43
|
+
| 'right'
|
|
44
|
+
| 'right-start'
|
|
45
|
+
| 'right-end';
|
|
46
|
+
|
|
47
|
+
/** The current state of the tour. */
|
|
48
|
+
export type Status = ValueOf<typeof STATUS>;
|
|
49
|
+
|
|
50
|
+
/** Tooltip button and navigation labels. */
|
|
51
|
+
export interface Locale {
|
|
52
|
+
/**
|
|
53
|
+
* Label for the back button.
|
|
54
|
+
* @default 'Back'
|
|
55
|
+
*/
|
|
56
|
+
back?: ReactNode;
|
|
57
|
+
/**
|
|
58
|
+
* Label for the close button.
|
|
59
|
+
* @default 'Close'
|
|
60
|
+
*/
|
|
61
|
+
close?: ReactNode;
|
|
62
|
+
/**
|
|
63
|
+
* Label for the last button.
|
|
64
|
+
* @default 'Last'
|
|
65
|
+
*/
|
|
66
|
+
last?: ReactNode;
|
|
67
|
+
/**
|
|
68
|
+
* Label for the next button.
|
|
69
|
+
* @default 'Next'
|
|
70
|
+
*/
|
|
71
|
+
next?: ReactNode;
|
|
72
|
+
/**
|
|
73
|
+
* Label for the next button with `showProgress`.
|
|
74
|
+
* Use the `{current}` and `{total}` placeholders to display the current step and the total steps.
|
|
75
|
+
* @default 'Next ({current} of {total})'
|
|
76
|
+
*/
|
|
77
|
+
nextWithProgress?: ReactNode;
|
|
78
|
+
/**
|
|
79
|
+
* Label for the open button.
|
|
80
|
+
* @default 'Open the dialog'
|
|
81
|
+
*/
|
|
82
|
+
open?: ReactNode;
|
|
83
|
+
/**
|
|
84
|
+
* Label for the skip button.
|
|
85
|
+
* @default 'Skip'
|
|
86
|
+
*/
|
|
87
|
+
skip?: ReactNode;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Step options for behavior, theming, and layout. Shared between Props and Step. */
|
|
91
|
+
export interface Options {
|
|
92
|
+
/**
|
|
93
|
+
* A hook that runs after the step completes (user clicked next, prev, close, or skip).
|
|
94
|
+
* Fire-and-forget — does not block the tour.
|
|
95
|
+
*/
|
|
96
|
+
after?: AfterHook;
|
|
97
|
+
/**
|
|
98
|
+
* Width of the arrow base edge in pixels.
|
|
99
|
+
* @default 32
|
|
100
|
+
*/
|
|
101
|
+
arrowBase: number;
|
|
102
|
+
/**
|
|
103
|
+
* Arrow fill color.
|
|
104
|
+
* @default '#ffffff'
|
|
105
|
+
*/
|
|
106
|
+
arrowColor: string;
|
|
107
|
+
/**
|
|
108
|
+
* Height/depth of the arrow (tip to base edge) in pixels.
|
|
109
|
+
* @default 16
|
|
110
|
+
*/
|
|
111
|
+
arrowSize: number;
|
|
112
|
+
/**
|
|
113
|
+
* The distance between the arrow and the edge of the tooltip.
|
|
114
|
+
* @default 12
|
|
115
|
+
*/
|
|
116
|
+
arrowSpacing: number;
|
|
117
|
+
/**
|
|
118
|
+
* Tooltip background color.
|
|
119
|
+
* @default '#ffffff'
|
|
120
|
+
*/
|
|
121
|
+
backgroundColor: string;
|
|
122
|
+
/**
|
|
123
|
+
* Beacon diameter in pixels.
|
|
124
|
+
* @default 36
|
|
125
|
+
*/
|
|
126
|
+
beaconSize: number;
|
|
127
|
+
/**
|
|
128
|
+
* The interaction that triggers the beacon to show the tooltip.
|
|
129
|
+
* @default 'click'
|
|
130
|
+
*/
|
|
131
|
+
beaconTrigger: 'click' | 'hover';
|
|
132
|
+
/**
|
|
133
|
+
* A hook that runs before the step is shown.
|
|
134
|
+
* The tour waits for the returned promise to resolve and shows the loader while waiting (after `loaderDelay`).
|
|
135
|
+
* Max duration capped by `beforeTimeout`.
|
|
136
|
+
*/
|
|
137
|
+
before?: BeforeHook;
|
|
138
|
+
/**
|
|
139
|
+
* Max time (ms) to wait for a `before` hook to resolve. 0 = no timeout.
|
|
140
|
+
* @default 5000
|
|
141
|
+
*/
|
|
142
|
+
beforeTimeout: number;
|
|
143
|
+
/**
|
|
144
|
+
* Block pointer events on the highlighted element through the spotlight cutout.
|
|
145
|
+
* @default false
|
|
146
|
+
*/
|
|
147
|
+
blockTargetInteraction: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* The buttons to show in the tooltip.
|
|
150
|
+
* @default ['back', 'close', 'primary']
|
|
151
|
+
*/
|
|
152
|
+
buttons: ButtonType[];
|
|
153
|
+
/**
|
|
154
|
+
* The action to take when the close button is clicked.
|
|
155
|
+
* - `'close'`: Advances to the next step (default behavior).
|
|
156
|
+
* - `'skip'`: Ends the tour entirely.
|
|
157
|
+
* - `'replay'`: Replays the current step.
|
|
158
|
+
* @default 'close'
|
|
159
|
+
*/
|
|
160
|
+
closeButtonAction: 'close' | 'skip' | 'replay';
|
|
161
|
+
/**
|
|
162
|
+
* Disable the focus trap for the tooltip.
|
|
163
|
+
* @default false
|
|
164
|
+
*/
|
|
165
|
+
disableFocusTrap: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* The action to take when the ESC key is pressed.
|
|
168
|
+
* - `'close'`: Closes the step (shows beacon on next step in continuous mode).
|
|
169
|
+
* - `'next'`: Advances to the next step (skips beacon in continuous mode).
|
|
170
|
+
* - `'replay'`: Replays the current step.
|
|
171
|
+
* - `false`: Disables ESC key.
|
|
172
|
+
* @default 'close'
|
|
173
|
+
*/
|
|
174
|
+
dismissKeyAction: 'close' | 'next' | 'replay' | false;
|
|
175
|
+
/**
|
|
176
|
+
* Don't show the overlay.
|
|
177
|
+
* @default false
|
|
178
|
+
*/
|
|
179
|
+
hideOverlay: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Delay (ms) before showing the loader while the tour is waiting.
|
|
182
|
+
* @default 300
|
|
183
|
+
*/
|
|
184
|
+
loaderDelay: number;
|
|
185
|
+
/**
|
|
186
|
+
* The distance in pixels between the tooltip and the spotlight.
|
|
187
|
+
* @default 10
|
|
188
|
+
*/
|
|
189
|
+
offset: number;
|
|
190
|
+
/**
|
|
191
|
+
* The action to take when the overlay is clicked.
|
|
192
|
+
* - `'close'`: Closes the step (fires a CLOSE action).
|
|
193
|
+
* - `'next'`: Advances to the next step (ends the tour on the last step).
|
|
194
|
+
* - `'replay'`: Replays the current step.
|
|
195
|
+
* - `false`: Disables overlay click.
|
|
196
|
+
* @default 'close'
|
|
197
|
+
*/
|
|
198
|
+
overlayClickAction: 'close' | 'next' | 'replay' | false;
|
|
199
|
+
/**
|
|
200
|
+
* Overlay backdrop color.
|
|
201
|
+
* @default '#00000080'
|
|
202
|
+
*/
|
|
203
|
+
overlayColor: string;
|
|
204
|
+
/**
|
|
205
|
+
* Primary button and beacon color.
|
|
206
|
+
* @default '#000000'
|
|
207
|
+
*/
|
|
208
|
+
primaryColor: string;
|
|
209
|
+
/**
|
|
210
|
+
* The scroll animation duration in milliseconds.
|
|
211
|
+
* @default 300
|
|
212
|
+
*/
|
|
213
|
+
scrollDuration: number;
|
|
214
|
+
/**
|
|
215
|
+
* The scroll distance from the element scrollTop value.
|
|
216
|
+
* @default 20
|
|
217
|
+
*/
|
|
218
|
+
scrollOffset: number;
|
|
219
|
+
/**
|
|
220
|
+
* Show the progress (1 of 5) in the tooltip.
|
|
221
|
+
* @default false
|
|
222
|
+
*/
|
|
223
|
+
showProgress: boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Don't show the Beacon before the tooltip.
|
|
226
|
+
* @default false
|
|
227
|
+
*/
|
|
228
|
+
skipBeacon: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Skip scrolling to the target.
|
|
231
|
+
* @default false
|
|
232
|
+
*/
|
|
233
|
+
skipScroll: boolean;
|
|
234
|
+
/**
|
|
235
|
+
* The padding of the spotlight.
|
|
236
|
+
* Accepts a number for equal padding on all sides, or an object with `top`, `right`, `bottom`, `left`.
|
|
237
|
+
* @default 10
|
|
238
|
+
*/
|
|
239
|
+
spotlightPadding: number | SpotlightPadding;
|
|
240
|
+
/**
|
|
241
|
+
* The border radius of the spotlight cutout in pixels.
|
|
242
|
+
* @default 4
|
|
243
|
+
*/
|
|
244
|
+
spotlightRadius: number;
|
|
245
|
+
/**
|
|
246
|
+
* Max time (ms) to wait for the target to appear. 0 = no waiting.
|
|
247
|
+
* @default 1000
|
|
248
|
+
*/
|
|
249
|
+
targetWaitTimeout: number;
|
|
250
|
+
/**
|
|
251
|
+
* Tooltip text color.
|
|
252
|
+
* @default '#000000'
|
|
253
|
+
*/
|
|
254
|
+
textColor: string;
|
|
255
|
+
/**
|
|
256
|
+
* Tooltip width in pixels or CSS string.
|
|
257
|
+
* @default 380
|
|
258
|
+
*/
|
|
259
|
+
width?: string | number;
|
|
260
|
+
/**
|
|
261
|
+
* z-index for the overlay and tooltip.
|
|
262
|
+
* @default 100
|
|
263
|
+
*/
|
|
264
|
+
zIndex: number;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Padding around the spotlight cutout in pixels. */
|
|
268
|
+
export interface SpotlightPadding {
|
|
269
|
+
bottom?: number;
|
|
270
|
+
left?: number;
|
|
271
|
+
right?: number;
|
|
272
|
+
top?: number;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** CSS styles for all Joyride UI elements. */
|
|
276
|
+
export interface Styles {
|
|
277
|
+
/** Arrow element styles. */
|
|
278
|
+
arrow: CSSProperties;
|
|
279
|
+
/** Beacon visual styles (size, border-radius). Applied to the default beacon content. */
|
|
280
|
+
beacon: CSSProperties;
|
|
281
|
+
/** Beacon inner pulse element styles. */
|
|
282
|
+
beaconInner: CSSProperties;
|
|
283
|
+
/** Beacon outer ring element styles. */
|
|
284
|
+
beaconOuter: CSSProperties;
|
|
285
|
+
/** Beacon wrapper button styles (interaction, layout). */
|
|
286
|
+
beaconWrapper: CSSProperties;
|
|
287
|
+
/** Back button styles. */
|
|
288
|
+
buttonBack: CSSProperties;
|
|
289
|
+
/** Close button styles. */
|
|
290
|
+
buttonClose: CSSProperties;
|
|
291
|
+
/** Next/Last button styles. */
|
|
292
|
+
buttonPrimary: CSSProperties;
|
|
293
|
+
/** Skip button styles. */
|
|
294
|
+
buttonSkip: CSSProperties;
|
|
295
|
+
/** Floating container styles. */
|
|
296
|
+
floater: CSSProperties;
|
|
297
|
+
/** Loader wrapper styles. */
|
|
298
|
+
loader: CSSProperties;
|
|
299
|
+
/** Overlay backdrop styles. */
|
|
300
|
+
overlay: CSSProperties;
|
|
301
|
+
/** Spotlight styles (SVG Path). */
|
|
302
|
+
spotlight: SVGAttributes<SVGPathElement>;
|
|
303
|
+
/** Tooltip wrapper styles. */
|
|
304
|
+
tooltip: CSSProperties;
|
|
305
|
+
/** Tooltip inner container styles. */
|
|
306
|
+
tooltipContainer: CSSProperties;
|
|
307
|
+
/** Tooltip body content styles. */
|
|
308
|
+
tooltipContent: CSSProperties;
|
|
309
|
+
/** Tooltip footer styles. */
|
|
310
|
+
tooltipFooter: CSSProperties;
|
|
311
|
+
/** Tooltip footer spacer styles. */
|
|
312
|
+
tooltipFooterSpacer: CSSProperties;
|
|
313
|
+
/** Tooltip title styles. */
|
|
314
|
+
tooltipTitle: CSSProperties;
|
|
315
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { MouseEventHandler } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { Controls } from '~/types/state';
|
|
4
|
+
|
|
5
|
+
import type { Placement } from './common';
|
|
6
|
+
import type { StepMerged } from './step';
|
|
7
|
+
import type { Simplify } from './utilities';
|
|
8
|
+
|
|
9
|
+
/** Props passed to a custom arrow component. */
|
|
10
|
+
export type ArrowRenderProps = {
|
|
11
|
+
/** Width of the arrow base in pixels. */
|
|
12
|
+
base: number;
|
|
13
|
+
/** The computed placement of the tooltip. */
|
|
14
|
+
placement: Placement;
|
|
15
|
+
/** Height of the arrow in pixels. */
|
|
16
|
+
size: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Props passed to a custom beacon component.
|
|
20
|
+
* Must render a span since it's placed inside a `<button>` wrapper.
|
|
21
|
+
*/
|
|
22
|
+
export type BeaconRenderProps = {
|
|
23
|
+
/** Whether the tour is in continuous mode. */
|
|
24
|
+
continuous: boolean;
|
|
25
|
+
/** The current step index. */
|
|
26
|
+
index: number;
|
|
27
|
+
/** Whether this is the last step. */
|
|
28
|
+
isLastStep: boolean;
|
|
29
|
+
/** The total number of steps. */
|
|
30
|
+
size: number;
|
|
31
|
+
/** The current step data. */
|
|
32
|
+
step: StepMerged;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** Props passed to a custom loader component. */
|
|
36
|
+
export type LoaderRenderProps = {
|
|
37
|
+
/** The current step data. */
|
|
38
|
+
step: StepMerged;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Props passed to a custom tooltip component. */
|
|
42
|
+
export type TooltipRenderProps = Simplify<
|
|
43
|
+
BeaconRenderProps & {
|
|
44
|
+
/** Props to spread on the back button. */
|
|
45
|
+
backProps: {
|
|
46
|
+
'aria-label': string;
|
|
47
|
+
'data-action': string;
|
|
48
|
+
onClick: MouseEventHandler<HTMLElement>;
|
|
49
|
+
role: string;
|
|
50
|
+
title: string;
|
|
51
|
+
};
|
|
52
|
+
/** Props to spread on the close button. */
|
|
53
|
+
closeProps: {
|
|
54
|
+
'aria-label': string;
|
|
55
|
+
'data-action': string;
|
|
56
|
+
onClick: MouseEventHandler<HTMLElement>;
|
|
57
|
+
role: string;
|
|
58
|
+
title: string;
|
|
59
|
+
};
|
|
60
|
+
/** Methods to programmatically control the tour. */
|
|
61
|
+
controls: Controls;
|
|
62
|
+
/** Props to spread on the next/last button. */
|
|
63
|
+
primaryProps: {
|
|
64
|
+
'aria-label': string;
|
|
65
|
+
'data-action': string;
|
|
66
|
+
onClick: MouseEventHandler<HTMLElement>;
|
|
67
|
+
role: string;
|
|
68
|
+
title: string;
|
|
69
|
+
};
|
|
70
|
+
/** Props to spread on the skip button. */
|
|
71
|
+
skipProps: {
|
|
72
|
+
'aria-label': string;
|
|
73
|
+
'data-action': string;
|
|
74
|
+
onClick: MouseEventHandler<HTMLElement>;
|
|
75
|
+
role: string;
|
|
76
|
+
title: string;
|
|
77
|
+
};
|
|
78
|
+
/** Props to spread on the tooltip container. */
|
|
79
|
+
tooltipProps: {
|
|
80
|
+
'aria-modal': boolean;
|
|
81
|
+
role: string;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Actions, Events, Lifecycle, Origin, Status } from './common';
|
|
2
|
+
import type { Controls } from './state';
|
|
3
|
+
import type { StepMerged } from './step';
|
|
4
|
+
import type { Simplify } from './utilities';
|
|
5
|
+
|
|
6
|
+
/** The payload passed to the `onEvent` callback. Extends `TourData` with event-specific fields. */
|
|
7
|
+
export type EventData = Simplify<
|
|
8
|
+
TourData & {
|
|
9
|
+
/**
|
|
10
|
+
* The error that occurred (only populated for ERROR events).
|
|
11
|
+
*/
|
|
12
|
+
error: Error | null;
|
|
13
|
+
/**
|
|
14
|
+
* Scroll data (only populated for SCROLL_START/SCROLL_END events).
|
|
15
|
+
*/
|
|
16
|
+
scroll: ScrollData | null;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the tour is currently scrolling to a target.
|
|
19
|
+
*/
|
|
20
|
+
scrolling: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The type of the event.
|
|
23
|
+
*/
|
|
24
|
+
type: Events;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the tour is blocked waiting for a before hook or target to appear.
|
|
27
|
+
*/
|
|
28
|
+
waiting: boolean;
|
|
29
|
+
}
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
/** Callback signature for the `onEvent` prop. */
|
|
33
|
+
export type EventHandler = (data: EventData, controls: Controls) => void;
|
|
34
|
+
|
|
35
|
+
/** Scroll position details for `scroll:start` and `scroll:end` events. */
|
|
36
|
+
export type ScrollData = {
|
|
37
|
+
/**
|
|
38
|
+
* The scroll duration in milliseconds.
|
|
39
|
+
*/
|
|
40
|
+
duration: number;
|
|
41
|
+
/**
|
|
42
|
+
* The element being scrolled.
|
|
43
|
+
*/
|
|
44
|
+
element: Element;
|
|
45
|
+
/**
|
|
46
|
+
* The scroll position before scrolling.
|
|
47
|
+
*/
|
|
48
|
+
initial: number;
|
|
49
|
+
/**
|
|
50
|
+
* The computed scroll destination.
|
|
51
|
+
*/
|
|
52
|
+
target: number;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** Base event payload with tour state at the time of the event. */
|
|
56
|
+
export interface TourData {
|
|
57
|
+
/**
|
|
58
|
+
* The action that triggered the state update.
|
|
59
|
+
*/
|
|
60
|
+
action: Actions;
|
|
61
|
+
/**
|
|
62
|
+
* Whether the tour is in `controlled` mode (using the `stepIndex` prop).
|
|
63
|
+
*/
|
|
64
|
+
controlled: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The current step's index.
|
|
67
|
+
*/
|
|
68
|
+
index: number;
|
|
69
|
+
/**
|
|
70
|
+
* The step's rendering phase.
|
|
71
|
+
*/
|
|
72
|
+
lifecycle: Lifecycle;
|
|
73
|
+
/**
|
|
74
|
+
* The UI element that triggered the action (if available).
|
|
75
|
+
*/
|
|
76
|
+
origin: Origin | null;
|
|
77
|
+
/**
|
|
78
|
+
* The total number of steps.
|
|
79
|
+
*/
|
|
80
|
+
size: number;
|
|
81
|
+
/**
|
|
82
|
+
* The tour's current status.
|
|
83
|
+
*/
|
|
84
|
+
status: Status;
|
|
85
|
+
/**
|
|
86
|
+
* The current step's data.
|
|
87
|
+
*/
|
|
88
|
+
step: StepMerged;
|
|
89
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AutoUpdateOptions,
|
|
3
|
+
FlipOptions,
|
|
4
|
+
Middleware,
|
|
5
|
+
MiddlewareData,
|
|
6
|
+
ShiftOptions,
|
|
7
|
+
Strategy,
|
|
8
|
+
} from '@floating-ui/react-dom';
|
|
9
|
+
|
|
10
|
+
import type { Placement } from './common';
|
|
11
|
+
|
|
12
|
+
/** Tooltip and beacon positioning configuration using Floating UI. */
|
|
13
|
+
export interface FloatingOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Options passed to autoUpdate (ancestorScroll, elementResize, animationFrame, etc).
|
|
16
|
+
*/
|
|
17
|
+
autoUpdate?: Partial<AutoUpdateOptions>;
|
|
18
|
+
/**
|
|
19
|
+
* Beacon positioning config.
|
|
20
|
+
*/
|
|
21
|
+
beaconOptions?: { offset?: number };
|
|
22
|
+
/**
|
|
23
|
+
* Options for the flip middleware, or `false` to disable flipping.
|
|
24
|
+
* Defaults: crossAxis false, padding 20, smart fallbackPlacements for left/right.
|
|
25
|
+
*/
|
|
26
|
+
flipOptions?: Partial<FlipOptions> | false;
|
|
27
|
+
/**
|
|
28
|
+
* Hide the arrow element.
|
|
29
|
+
* Centered placement already hides the arrow.
|
|
30
|
+
*
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
hideArrow?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Additional Floating UI middleware appended to defaults (offset, flip/autoPlacement, shift, arrow).
|
|
36
|
+
*/
|
|
37
|
+
middleware?: Array<Middleware>;
|
|
38
|
+
/**
|
|
39
|
+
* Called after each position calculation.
|
|
40
|
+
*/
|
|
41
|
+
onPosition?: (data: PositionData) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Options for the shift middleware.
|
|
44
|
+
* Default: padding 10.
|
|
45
|
+
*/
|
|
46
|
+
shiftOptions?: Partial<ShiftOptions>;
|
|
47
|
+
/**
|
|
48
|
+
* Positioning strategy.
|
|
49
|
+
* Defaults to 'fixed' when step.isFixed is true, 'absolute' otherwise.
|
|
50
|
+
*/
|
|
51
|
+
strategy?: Strategy;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Computed position data returned by Floating UI after each calculation. */
|
|
55
|
+
export interface PositionData {
|
|
56
|
+
middlewareData: MiddlewareData;
|
|
57
|
+
placement: Placement;
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { ElementType, ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ArrowRenderProps,
|
|
5
|
+
BeaconRenderProps,
|
|
6
|
+
LoaderRenderProps,
|
|
7
|
+
TooltipRenderProps,
|
|
8
|
+
} from '~/types/components';
|
|
9
|
+
import type { FloatingOptions } from '~/types/floating';
|
|
10
|
+
|
|
11
|
+
import type { Events, FailureReason, Locale, Options, Styles } from './common';
|
|
12
|
+
import type { EventHandler } from './events';
|
|
13
|
+
import type { Controls, State } from './state';
|
|
14
|
+
import type { SelectorOrElement, Step, StepMerged } from './step';
|
|
15
|
+
import type { PartialDeep, Simplify } from './utilities';
|
|
16
|
+
|
|
17
|
+
export type Props = Simplify<
|
|
18
|
+
SharedProps & {
|
|
19
|
+
/**
|
|
20
|
+
* The tour is played sequentially with the Next button.
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
continuous?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Log Joyride's actions to the console.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The initial step index for uncontrolled tours.
|
|
31
|
+
* Ignored when stepIndex is set (controlled mode).
|
|
32
|
+
* @default 0
|
|
33
|
+
*/
|
|
34
|
+
initialStepIndex?: number;
|
|
35
|
+
/**
|
|
36
|
+
* A nonce value for inline styles (Content Security Policy).
|
|
37
|
+
*/
|
|
38
|
+
nonce?: string;
|
|
39
|
+
/**
|
|
40
|
+
* A function called when Joyride fires an event.
|
|
41
|
+
*/
|
|
42
|
+
onEvent?: EventHandler;
|
|
43
|
+
/**
|
|
44
|
+
* Default options for all steps.
|
|
45
|
+
*/
|
|
46
|
+
options?: Partial<Options>;
|
|
47
|
+
/**
|
|
48
|
+
* Render all Joyride components inside a specific element.
|
|
49
|
+
*/
|
|
50
|
+
portalElement?: SelectorOrElement;
|
|
51
|
+
/**
|
|
52
|
+
* Run/stop the tour.
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
run?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Scroll the page for the first step.
|
|
58
|
+
* @default false
|
|
59
|
+
*/
|
|
60
|
+
scrollToFirstStep?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Setting a number here will turn Joyride into `controlled` mode.
|
|
63
|
+
* You'll have to keep an internal state by yourself and update it with the events in `onEvent`.
|
|
64
|
+
*/
|
|
65
|
+
stepIndex?: number;
|
|
66
|
+
/**
|
|
67
|
+
* The tour's steps.
|
|
68
|
+
*/
|
|
69
|
+
steps: Array<Step>;
|
|
70
|
+
}
|
|
71
|
+
>;
|
|
72
|
+
/** Shared configuration inherited by both `Props` and `Step`. */
|
|
73
|
+
export type SharedProps = {
|
|
74
|
+
/**
|
|
75
|
+
* Custom Arrow component.
|
|
76
|
+
*/
|
|
77
|
+
arrowComponent?: ElementType<ArrowRenderProps>;
|
|
78
|
+
/**
|
|
79
|
+
* Custom Beacon component.
|
|
80
|
+
*/
|
|
81
|
+
beaconComponent?: ElementType<BeaconRenderProps>;
|
|
82
|
+
/**
|
|
83
|
+
* Options for the floating tooltip positioning.
|
|
84
|
+
*/
|
|
85
|
+
floatingOptions?: Partial<FloatingOptions>;
|
|
86
|
+
/**
|
|
87
|
+
* Custom Loader component. Set to `null` to disable.
|
|
88
|
+
*/
|
|
89
|
+
loaderComponent?: ElementType<LoaderRenderProps> | null;
|
|
90
|
+
/**
|
|
91
|
+
* The strings used in the tooltip.
|
|
92
|
+
*/
|
|
93
|
+
locale?: Locale;
|
|
94
|
+
/**
|
|
95
|
+
* Override the styling of the Tooltip.
|
|
96
|
+
*/
|
|
97
|
+
styles?: PartialDeep<Styles>;
|
|
98
|
+
/**
|
|
99
|
+
* Custom Tooltip component.
|
|
100
|
+
*/
|
|
101
|
+
tooltipComponent?: ElementType<TooltipRenderProps>;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Return value of the `useJoyride` hook. */
|
|
105
|
+
export type UseJoyrideReturn = {
|
|
106
|
+
/** Methods to programmatically control the tour. */
|
|
107
|
+
controls: Controls;
|
|
108
|
+
/** Steps that failed during the current tour run (target not found, before hook errors). Clears on start/reset. */
|
|
109
|
+
failures: StepFailure[];
|
|
110
|
+
/** Subscribe to a specific event type. Returns an unsubscribe function. */
|
|
111
|
+
on: (eventType: Events, handler: EventHandler) => () => void;
|
|
112
|
+
/** The current tour state. */
|
|
113
|
+
state: State;
|
|
114
|
+
/** The current merged step, or null if no step is active. */
|
|
115
|
+
step: StepMerged | null;
|
|
116
|
+
/** The tour React element to render. */
|
|
117
|
+
Tour: ReactElement | null;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** A step that failed during the tour. */
|
|
121
|
+
export interface StepFailure {
|
|
122
|
+
reason: FailureReason;
|
|
123
|
+
step: StepMerged;
|
|
124
|
+
}
|