@matthesketh/react-guidetour 1.0.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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ This package is a modernised fork of react-joyride by Gil Barbara.
2
+ Original source: https://github.com/gilbarbara/react-joyride
3
+ The original MIT license is preserved below.
4
+
5
+ ---
6
+
7
+ MIT License
8
+
9
+ Copyright (c) 2015, Gil Barbara
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @wrxck/react-guidetour
2
+
3
+ React 19 guided tour component. A modernised fork of [react-joyride](https://github.com/gilbarbara/react-joyride) by Gil Barbara.
4
+
5
+ ## Why this fork?
6
+
7
+ react-joyride v2.9.3 uses `ReactDOM.unmountComponentAtNode()` and `ReactDOM.unstable_renderSubtreeIntoContainer()`, both removed in React 19. This fork:
8
+
9
+ - Converts all class components to functional components with hooks
10
+ - Uses `createPortal` directly (no legacy React 15/16 branching)
11
+ - Removes legacy browser detection (IE/Edge legacy)
12
+ - Targets React 19+ only
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install @wrxck/react-guidetour
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ The API is the same as react-joyride. See the [react-joyride documentation](https://docs.react-joyride.com/) for full usage details.
23
+
24
+ ```tsx
25
+ import Joyride from '@wrxck/react-guidetour';
26
+
27
+ const steps = [
28
+ {
29
+ target: '.my-first-step',
30
+ content: 'This is my first step!',
31
+ },
32
+ ];
33
+
34
+ function App() {
35
+ return <Joyride steps={steps} />;
36
+ }
37
+ ```
38
+
39
+ ## Attribution
40
+
41
+ Original work by [Gil Barbara](https://github.com/gilbarbara) under the MIT License.
@@ -0,0 +1,496 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { CSSProperties, ReactNode, ElementType, MouseEventHandler, RefCallback } from 'react';
3
+ import { Styles as Styles$1, Props as Props$1 } from 'react-floater';
4
+ export { Props as FloaterProps } from 'react-floater';
5
+ import { ValueOf, Simplify, SetRequired, PartialDeep } from 'type-fest';
6
+
7
+ declare const ACTIONS: {
8
+ readonly INIT: "init";
9
+ readonly START: "start";
10
+ readonly STOP: "stop";
11
+ readonly RESET: "reset";
12
+ readonly PREV: "prev";
13
+ readonly NEXT: "next";
14
+ readonly GO: "go";
15
+ readonly CLOSE: "close";
16
+ readonly SKIP: "skip";
17
+ readonly UPDATE: "update";
18
+ };
19
+ declare const EVENTS: {
20
+ readonly TOUR_START: "tour:start";
21
+ readonly STEP_BEFORE: "step:before";
22
+ readonly BEACON: "beacon";
23
+ readonly TOOLTIP: "tooltip";
24
+ readonly STEP_AFTER: "step:after";
25
+ readonly TOUR_END: "tour:end";
26
+ readonly TOUR_STATUS: "tour:status";
27
+ readonly TARGET_NOT_FOUND: "error:target_not_found";
28
+ readonly ERROR: "error";
29
+ };
30
+ declare const LIFECYCLE: {
31
+ readonly INIT: "init";
32
+ readonly READY: "ready";
33
+ readonly BEACON: "beacon";
34
+ readonly TOOLTIP: "tooltip";
35
+ readonly COMPLETE: "complete";
36
+ readonly ERROR: "error";
37
+ };
38
+ declare const ORIGIN: {
39
+ readonly BUTTON_CLOSE: "button_close";
40
+ readonly BUTTON_PRIMARY: "button_primary";
41
+ readonly KEYBOARD: "keyboard";
42
+ readonly OVERLAY: "overlay";
43
+ };
44
+ declare const STATUS: {
45
+ readonly IDLE: "idle";
46
+ readonly READY: "ready";
47
+ readonly WAITING: "waiting";
48
+ readonly RUNNING: "running";
49
+ readonly PAUSED: "paused";
50
+ readonly SKIPPED: "skipped";
51
+ readonly FINISHED: "finished";
52
+ readonly ERROR: "error";
53
+ };
54
+
55
+ type Actions = ValueOf<typeof ACTIONS>;
56
+ type Events = ValueOf<typeof EVENTS>;
57
+ type Lifecycle = ValueOf<typeof LIFECYCLE>;
58
+ type Origin = ValueOf<typeof ORIGIN>;
59
+ type Status = ValueOf<typeof STATUS>;
60
+ type AnyObject<T = any> = Record<string, T>;
61
+ type NarrowPlainObject<T extends Record<string, any>> = Exclude<T, Array<unknown> | Function | Map<unknown, unknown> | Set<unknown>>;
62
+ interface Locale {
63
+ /**
64
+ * Label for the back button.
65
+ * @default 'Back'
66
+ */
67
+ back?: ReactNode;
68
+ /**
69
+ * Label for the close button.
70
+ * @default 'Close'
71
+ */
72
+ close?: ReactNode;
73
+ /**
74
+ * Label for the last button.
75
+ * @default 'Last'
76
+ */
77
+ last?: ReactNode;
78
+ /**
79
+ * Label for the next button.
80
+ * @default 'Next'
81
+ */
82
+ next?: ReactNode;
83
+ /**
84
+ * Label for the next button with `showProgress`.
85
+ * Use the `{step}` and `{steps}` placeholders to display the current step and the total steps.
86
+ * @default 'Next (Step {step} of {steps})'
87
+ */
88
+ nextLabelWithProgress?: ReactNode;
89
+ /**
90
+ * Label for the open button.
91
+ * @default 'Open the dialog'
92
+ */
93
+ open?: ReactNode;
94
+ /**
95
+ * Label for the skip button.
96
+ * @default 'Skip'
97
+ */
98
+ skip?: ReactNode;
99
+ }
100
+ type Placement = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end';
101
+ interface Styles {
102
+ beacon: CSSProperties;
103
+ beaconInner: CSSProperties;
104
+ beaconOuter: CSSProperties;
105
+ buttonBack: CSSProperties;
106
+ buttonClose: CSSProperties;
107
+ buttonNext: CSSProperties;
108
+ buttonSkip: CSSProperties;
109
+ options: Partial<StylesOptions>;
110
+ overlay: CSSProperties;
111
+ overlayLegacy: CSSProperties;
112
+ overlayLegacyCenter: CSSProperties;
113
+ spotlight: CSSProperties;
114
+ spotlightLegacy: CSSProperties;
115
+ tooltip: CSSProperties;
116
+ tooltipContainer: CSSProperties;
117
+ tooltipContent: CSSProperties;
118
+ tooltipFooter: CSSProperties;
119
+ tooltipFooterSpacer: CSSProperties;
120
+ tooltipTitle: CSSProperties;
121
+ }
122
+ interface StylesWithFloaterStyles extends Styles {
123
+ floaterStyles: Styles$1;
124
+ }
125
+ interface StylesOptions {
126
+ arrowColor: string;
127
+ backgroundColor: string;
128
+ beaconSize: number;
129
+ overlayColor: string;
130
+ primaryColor: string;
131
+ spotlightShadow: string;
132
+ textColor: string;
133
+ width?: string | number;
134
+ zIndex: number;
135
+ }
136
+
137
+ type Listener = (state: State) => void;
138
+ type PopperData = any;
139
+ declare class Store {
140
+ private beaconPopper;
141
+ private tooltipPopper;
142
+ private data;
143
+ private listener;
144
+ private store;
145
+ constructor(options?: StoreOptions);
146
+ getState(): State;
147
+ private getNextState;
148
+ private getSteps;
149
+ private hasUpdatedState;
150
+ private setState;
151
+ addListener: (listener: Listener) => void;
152
+ setSteps: (steps: Array<Step>) => void;
153
+ getHelpers(): StoreHelpers;
154
+ getPopper: (name: "beacon" | "tooltip") => PopperData | null;
155
+ setPopper: (name: "beacon" | "tooltip", popper: PopperData) => void;
156
+ cleanupPoppers: () => void;
157
+ close: (origin?: Origin | null) => void;
158
+ go: (nextIndex: number) => void;
159
+ info: () => State;
160
+ next: () => void;
161
+ open: () => void;
162
+ prev: () => void;
163
+ reset: (restart?: boolean) => void;
164
+ skip: () => void;
165
+ start: (nextIndex?: number) => void;
166
+ stop: (advance?: boolean) => void;
167
+ update: (state: Partial<State>) => void;
168
+ }
169
+ type StoreInstance = ReturnType<typeof createStore>;
170
+ declare function createStore(options?: StoreOptions): Store;
171
+
172
+ type BaseProps = {
173
+ /**
174
+ * A React component to use instead the default Beacon.
175
+ */
176
+ beaconComponent?: ElementType<BeaconRenderProps>;
177
+ /**
178
+ * Disable closing the tooltip on ESC.
179
+ * @default false
180
+ */
181
+ disableCloseOnEsc?: boolean;
182
+ /**
183
+ * Don't show the overlay.
184
+ * @default false
185
+ */
186
+ disableOverlay?: boolean;
187
+ /**
188
+ * Don't close the tooltip when clicking the overlay.
189
+ * @default false
190
+ */
191
+ disableOverlayClose?: boolean;
192
+ /**
193
+ * Disable the fix to handle "unused" overflow parents.
194
+ * @default false
195
+ */
196
+ disableScrollParentFix?: boolean;
197
+ /**
198
+ * @default false
199
+ */
200
+ disableScrolling?: boolean;
201
+ /**
202
+ * Options to be passed to react-floater
203
+ */
204
+ floaterProps?: Partial<Props$1>;
205
+ /**
206
+ * Hide the Back button.
207
+ * @default false
208
+ */
209
+ hideBackButton?: boolean;
210
+ /**
211
+ * Hide the Close button.
212
+ * @default false
213
+ */
214
+ hideCloseButton?: boolean;
215
+ /**
216
+ * The strings used in the tooltip.
217
+ */
218
+ locale?: Locale;
219
+ /**
220
+ * @default false
221
+ */
222
+ showProgress?: boolean;
223
+ /**
224
+ * @default false
225
+ */
226
+ showSkipButton?: boolean;
227
+ /**
228
+ * @default false
229
+ */
230
+ spotlightClicks?: boolean;
231
+ /**
232
+ * The padding of the spotlight.
233
+ * @default 10
234
+ */
235
+ spotlightPadding?: number;
236
+ /**
237
+ * Override the styling of the Tooltip
238
+ */
239
+ styles?: PartialDeep<Styles>;
240
+ /**
241
+ * A React component to use instead the default Tooltip.
242
+ */
243
+ tooltipComponent?: ElementType<TooltipRenderProps>;
244
+ };
245
+ type BeaconProps = Simplify<Pick<Props, 'beaconComponent' | 'nonce'> & BeaconRenderProps & {
246
+ locale: Locale;
247
+ onClickOrHover: MouseEventHandler<HTMLElement>;
248
+ shouldFocus: boolean;
249
+ styles: Styles;
250
+ }>;
251
+ type BeaconRenderProps = {
252
+ continuous: boolean;
253
+ index: number;
254
+ isLastStep: boolean;
255
+ size: number;
256
+ step: StepMerged;
257
+ };
258
+ type Callback = (data: CallBackProps) => void;
259
+ type CallBackProps = {
260
+ /**
261
+ * The action that updated the state.
262
+ */
263
+ action: Actions;
264
+ /**
265
+ * It the tour is in `controlled` mode.
266
+ * (using the `stepIndex` prop)
267
+ */
268
+ controlled: boolean;
269
+ /**
270
+ * The current step's index
271
+ */
272
+ index: number;
273
+ /**
274
+ * The step's lifecycle.
275
+ */
276
+ lifecycle: Lifecycle;
277
+ /**
278
+ * The element that triggered the action (if available).
279
+ */
280
+ origin: Origin | null;
281
+ /**
282
+ * The number of steps
283
+ */
284
+ size: number;
285
+ /**
286
+ * The tour's status.
287
+ */
288
+ status: Status;
289
+ /**
290
+ * The current step's data.
291
+ */
292
+ step: Step;
293
+ /**
294
+ * The type of the event.
295
+ */
296
+ type: Events;
297
+ };
298
+ type OverlayProps = Simplify<StepMerged & {
299
+ continuous: boolean;
300
+ debug: boolean;
301
+ lifecycle: Lifecycle;
302
+ onClickOverlay: () => void;
303
+ }>;
304
+ type Props = Simplify<BaseProps & {
305
+ /**
306
+ * A function to be called when Joyride's state changes.
307
+ * It returns a single parameter with the state.
308
+ */
309
+ callback?: Callback;
310
+ /**
311
+ * The tour is played sequentially with the Next button.
312
+ * @default false
313
+ */
314
+ continuous?: boolean;
315
+ /**
316
+ * Log Joyride's actions to the console.
317
+ * @default false
318
+ */
319
+ debug?: boolean;
320
+ /**
321
+ * Get the store methods to control the tour programmatically. `prev, next, go, close, skip, reset, info`
322
+ */
323
+ getHelpers?: (helpers: StoreHelpers) => void;
324
+ /**
325
+ * A nonce value for inline styles (Content Security Policy - CSP)
326
+ */
327
+ nonce?: string;
328
+ /**
329
+ * Run/stop the tour.
330
+ * @default true
331
+ */
332
+ run?: boolean;
333
+ /**
334
+ * The duration for scroll to element.
335
+ * @default 300
336
+ */
337
+ scrollDuration?: number;
338
+ /**
339
+ * The scroll distance from the element scrollTop value.
340
+ * @default 20
341
+ */
342
+ scrollOffset?: number;
343
+ /**
344
+ * Scroll the page for the first step.
345
+ * @default false
346
+ */
347
+ scrollToFirstStep?: boolean;
348
+ /**
349
+ * Setting a number here will turn Joyride into `controlled` mode.
350
+ * You'll have to keep an internal state by yourself and update it with the events in the `callback`.
351
+ */
352
+ stepIndex?: number;
353
+ /**
354
+ * The tour's steps.
355
+ */
356
+ steps: Array<Step>;
357
+ }>;
358
+ type State = {
359
+ action: Actions;
360
+ controlled: boolean;
361
+ index: number;
362
+ lifecycle: Lifecycle;
363
+ origin: Origin | null;
364
+ size: number;
365
+ status: Status;
366
+ };
367
+ type Step = Simplify<BaseProps & {
368
+ /**
369
+ * The tooltip's body.
370
+ */
371
+ content: ReactNode;
372
+ /**
373
+ * Additional data you can add to the step.
374
+ */
375
+ data?: any;
376
+ /**
377
+ * Don't show the Beacon before the tooltip.
378
+ * @default false
379
+ */
380
+ disableBeacon?: boolean;
381
+ /**
382
+ * The event to trigger the beacon.
383
+ * @default click
384
+ */
385
+ event?: 'click' | 'hover';
386
+ /**
387
+ * Options to be passed to react-floater
388
+ */
389
+ floaterProps?: Props$1;
390
+ /**
391
+ * Hide the tooltip's footer.
392
+ * @default false
393
+ */
394
+ hideFooter?: boolean;
395
+ /**
396
+ * Force the step to be fixed.
397
+ * @default false
398
+ */
399
+ isFixed?: boolean;
400
+ /**
401
+ * @default 10
402
+ */
403
+ offset?: number;
404
+ /**
405
+ * The placement of the beacon and tooltip. It will re-position itself if there's no space available.
406
+ * @default bottom
407
+ */
408
+ placement?: Placement | 'auto' | 'center';
409
+ /**
410
+ * The placement of the beacon. It will use the `placement` if nothing is passed
411
+ */
412
+ placementBeacon?: Placement;
413
+ /**
414
+ * The target for the step.
415
+ * It can be a CSS selector or an HTMLElement ref.
416
+ */
417
+ target: string | HTMLElement;
418
+ /**
419
+ * The tooltip's title.
420
+ */
421
+ title?: ReactNode;
422
+ }>;
423
+ type StepMerged = Simplify<SetRequired<Step, 'disableBeacon' | 'disableCloseOnEsc' | 'disableOverlay' | 'disableOverlayClose' | 'disableScrollParentFix' | 'disableScrolling' | 'event' | 'hideBackButton' | 'hideCloseButton' | 'hideFooter' | 'isFixed' | 'locale' | 'offset' | 'placement' | 'showProgress' | 'showSkipButton' | 'spotlightClicks' | 'spotlightPadding'> & {
424
+ styles: Styles;
425
+ }>;
426
+ type StepProps = Simplify<State & {
427
+ callback: Callback;
428
+ continuous: boolean;
429
+ debug: boolean;
430
+ helpers: StoreHelpers;
431
+ nonce?: string;
432
+ shouldScroll: boolean;
433
+ step: StepMerged;
434
+ store: StoreInstance;
435
+ }>;
436
+ type StoreHelpers = {
437
+ close: (origin?: Origin | null) => void;
438
+ go: (nextIndex: number) => void;
439
+ info: () => State;
440
+ next: () => void;
441
+ open: () => void;
442
+ prev: () => void;
443
+ reset: (restart: boolean) => void;
444
+ skip: () => void;
445
+ };
446
+ type StoreOptions = Simplify<Props & {
447
+ controlled: boolean;
448
+ }>;
449
+ type TooltipProps = {
450
+ continuous: boolean;
451
+ helpers: StoreHelpers;
452
+ index: number;
453
+ isLastStep: boolean;
454
+ setTooltipRef: RefCallback<HTMLElement>;
455
+ size: number;
456
+ step: StepMerged;
457
+ };
458
+ type TooltipRenderProps = Simplify<BeaconRenderProps & {
459
+ backProps: {
460
+ 'aria-label': string;
461
+ 'data-action': string;
462
+ onClick: MouseEventHandler<HTMLElement>;
463
+ role: string;
464
+ title: string;
465
+ };
466
+ closeProps: {
467
+ 'aria-label': string;
468
+ 'data-action': string;
469
+ onClick: MouseEventHandler<HTMLElement>;
470
+ role: string;
471
+ title: string;
472
+ };
473
+ primaryProps: {
474
+ 'aria-label': string;
475
+ 'data-action': string;
476
+ onClick: MouseEventHandler<HTMLElement>;
477
+ role: string;
478
+ title: string;
479
+ };
480
+ skipProps: {
481
+ 'aria-label': string;
482
+ 'data-action': string;
483
+ onClick: MouseEventHandler<HTMLElement>;
484
+ role: string;
485
+ title: string;
486
+ };
487
+ tooltipProps: {
488
+ 'aria-modal': boolean;
489
+ ref: RefCallback<HTMLElement>;
490
+ role: string;
491
+ };
492
+ }>;
493
+
494
+ declare function Joyride(inputProps: Props): react_jsx_runtime.JSX.Element | null;
495
+
496
+ export { ACTIONS, type Actions, type AnyObject, type BaseProps, type BeaconProps, type BeaconRenderProps, type CallBackProps, type Callback, EVENTS, type Events, LIFECYCLE, type Lifecycle, type Locale, type NarrowPlainObject, ORIGIN, type Origin, type OverlayProps, type Placement, type Props, STATUS, type State, type Status, type Step, type StepMerged, type StepProps, type StoreHelpers, type StoreOptions, type Styles, type StylesOptions, type StylesWithFloaterStyles, type TooltipProps, type TooltipRenderProps, Joyride as default };