@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,49 @@
|
|
|
1
|
+
import type { Actions, Lifecycle, Origin, Status } from './common';
|
|
2
|
+
|
|
3
|
+
/** Methods to programmatically control the tour. */
|
|
4
|
+
export type Controls = {
|
|
5
|
+
/** Close the current step and advance to the next one. */
|
|
6
|
+
close: (origin?: Origin | null) => void;
|
|
7
|
+
/** Jump to a specific step by index. */
|
|
8
|
+
go: (nextIndex: number) => void;
|
|
9
|
+
/** Get the current tour state. */
|
|
10
|
+
info: () => State;
|
|
11
|
+
/** Advance to the next step. */
|
|
12
|
+
next: (origin?: Origin | null) => void;
|
|
13
|
+
/** Open the tooltip for the current step. */
|
|
14
|
+
open: () => void;
|
|
15
|
+
/** Go back to the previous step. */
|
|
16
|
+
prev: (origin?: Origin | null) => void;
|
|
17
|
+
/** Replay the current step. Re-runs `before` and `after` hooks and re-emits step lifecycle events. */
|
|
18
|
+
replay: (origin?: Origin | null) => void;
|
|
19
|
+
/** Reset the tour. Optionally restart from the beginning. */
|
|
20
|
+
reset: (restart?: boolean) => void;
|
|
21
|
+
/** Skip the tour entirely. */
|
|
22
|
+
skip: (origin?: Extract<Origin, 'button_close' | 'button_skip'> | null) => void;
|
|
23
|
+
/** Start the tour at an optional step index. */
|
|
24
|
+
start: (nextIndex?: number) => void;
|
|
25
|
+
/** Stop the tour. Optionally advance to the next step before stopping. */
|
|
26
|
+
stop: (advance?: boolean) => void;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** The internal tour state. */
|
|
30
|
+
export type State = {
|
|
31
|
+
/** The action that triggered the state update. */
|
|
32
|
+
action: Actions;
|
|
33
|
+
/** Whether the tour is in controlled mode (using `stepIndex`). */
|
|
34
|
+
controlled: boolean;
|
|
35
|
+
/** The current step index. */
|
|
36
|
+
index: number;
|
|
37
|
+
/** The step's rendering phase. */
|
|
38
|
+
lifecycle: Lifecycle;
|
|
39
|
+
/** The UI element that triggered the last action. */
|
|
40
|
+
origin: Origin | null;
|
|
41
|
+
/** Whether the tour is scrolling to a target. */
|
|
42
|
+
scrolling: boolean;
|
|
43
|
+
/** The total number of steps. */
|
|
44
|
+
size: number;
|
|
45
|
+
/** The tour's current status. */
|
|
46
|
+
status: Status;
|
|
47
|
+
/** Whether the tour is blocked waiting for a `before` hook or target to appear. */
|
|
48
|
+
waiting: boolean;
|
|
49
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ReactNode, RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { SharedProps } from '~/types/props';
|
|
4
|
+
|
|
5
|
+
import type { Options, Placement, SpotlightPadding, Styles } from './common';
|
|
6
|
+
import type { SetRequired, Simplify } from './utilities';
|
|
7
|
+
|
|
8
|
+
/** A CSS selector string, an HTMLElement, or null. */
|
|
9
|
+
export type SelectorOrElement = string | null | HTMLElement;
|
|
10
|
+
|
|
11
|
+
/** A single step in the tour, provided by the user. */
|
|
12
|
+
export type Step = Simplify<
|
|
13
|
+
SharedProps &
|
|
14
|
+
Partial<Options> & {
|
|
15
|
+
/**
|
|
16
|
+
* The placement of the beacon. It will use the `placement` if nothing is passed.
|
|
17
|
+
*/
|
|
18
|
+
beaconPlacement?: Placement;
|
|
19
|
+
/**
|
|
20
|
+
* The tooltip's body.
|
|
21
|
+
*/
|
|
22
|
+
content: ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* Additional data you can add to the step.
|
|
25
|
+
*/
|
|
26
|
+
data?: any;
|
|
27
|
+
/**
|
|
28
|
+
* A unique identifier for the step.
|
|
29
|
+
*/
|
|
30
|
+
id?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Force the step to be fixed.
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
isFixed?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The placement of the beacon and tooltip. It will re-position itself if there's no space available.
|
|
38
|
+
* @default bottom
|
|
39
|
+
*/
|
|
40
|
+
placement?: Placement | 'auto' | 'center';
|
|
41
|
+
/**
|
|
42
|
+
* An optional element to scroll to instead of the target.
|
|
43
|
+
* The spotlight and tooltip will still use `target`.
|
|
44
|
+
*/
|
|
45
|
+
scrollTarget?: StepTarget;
|
|
46
|
+
/**
|
|
47
|
+
* An optional element to highlight instead of the target.
|
|
48
|
+
* The tooltip will still anchor to `target`.
|
|
49
|
+
*/
|
|
50
|
+
spotlightTarget?: StepTarget;
|
|
51
|
+
/**
|
|
52
|
+
* The target for the step.
|
|
53
|
+
* It can be a CSS selector, an HTMLElement, a React ref, or a function that returns an element.
|
|
54
|
+
*/
|
|
55
|
+
target: StepTarget;
|
|
56
|
+
/**
|
|
57
|
+
* The tooltip's title.
|
|
58
|
+
*/
|
|
59
|
+
title?: ReactNode;
|
|
60
|
+
}
|
|
61
|
+
>;
|
|
62
|
+
|
|
63
|
+
/** A normalized step with all defaults applied. */
|
|
64
|
+
export type StepMerged = Simplify<
|
|
65
|
+
SetRequired<
|
|
66
|
+
Step,
|
|
67
|
+
| 'arrowBase'
|
|
68
|
+
| 'arrowColor'
|
|
69
|
+
| 'arrowSize'
|
|
70
|
+
| 'arrowSpacing'
|
|
71
|
+
| 'backgroundColor'
|
|
72
|
+
| 'beaconSize'
|
|
73
|
+
| 'beaconTrigger'
|
|
74
|
+
| 'beforeTimeout'
|
|
75
|
+
| 'buttons'
|
|
76
|
+
| 'closeButtonAction'
|
|
77
|
+
| 'skipBeacon'
|
|
78
|
+
| 'dismissKeyAction'
|
|
79
|
+
| 'disableFocusTrap'
|
|
80
|
+
| 'hideOverlay'
|
|
81
|
+
| 'skipScroll'
|
|
82
|
+
| 'blockTargetInteraction'
|
|
83
|
+
| 'isFixed'
|
|
84
|
+
| 'loaderDelay'
|
|
85
|
+
| 'locale'
|
|
86
|
+
| 'offset'
|
|
87
|
+
| 'overlayClickAction'
|
|
88
|
+
| 'overlayColor'
|
|
89
|
+
| 'placement'
|
|
90
|
+
| 'primaryColor'
|
|
91
|
+
| 'scrollDuration'
|
|
92
|
+
| 'scrollOffset'
|
|
93
|
+
| 'showProgress'
|
|
94
|
+
| 'spotlightRadius'
|
|
95
|
+
| 'targetWaitTimeout'
|
|
96
|
+
| 'textColor'
|
|
97
|
+
| 'zIndex'
|
|
98
|
+
> & {
|
|
99
|
+
spotlightPadding: Required<SpotlightPadding>;
|
|
100
|
+
styles: Styles;
|
|
101
|
+
}
|
|
102
|
+
>;
|
|
103
|
+
|
|
104
|
+
export type StepTarget =
|
|
105
|
+
| string
|
|
106
|
+
| HTMLElement
|
|
107
|
+
| RefObject<HTMLElement | null>
|
|
108
|
+
| (() => HTMLElement | null);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Generic record type. */
|
|
2
|
+
export type AnyObject<T = any> = Record<string, T>;
|
|
3
|
+
|
|
4
|
+
/** Excludes arrays, functions, Map, and Set from a record type. */
|
|
5
|
+
export type NarrowPlainObject<T extends Record<string, any>> = Exclude<
|
|
6
|
+
T,
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
8
|
+
Array<unknown> | Function | Map<unknown, unknown> | Set<unknown>
|
|
9
|
+
>;
|
|
10
|
+
|
|
11
|
+
/** Makes all properties optional, with one level of depth for nested objects. */
|
|
12
|
+
export type PartialDeep<T> = {
|
|
13
|
+
[K in keyof T]?: T[K] extends object ? Partial<T[K]> : T[K];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Generic record type with unknown values. */
|
|
17
|
+
export type PlainObject<T = unknown> = Record<string, T>;
|
|
18
|
+
|
|
19
|
+
/** Makes specific keys required while keeping others unchanged. */
|
|
20
|
+
export type SetRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
21
|
+
|
|
22
|
+
/** Flattens intersection types for better IDE display. */
|
|
23
|
+
export type Simplify<T> = { [K in keyof T]: T[K] } & {};
|
|
24
|
+
|
|
25
|
+
/** Extracts a union of all values from an object type. */
|
|
26
|
+
export type ValueOf<T> = T[keyof T];
|