@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.
@@ -0,0 +1,110 @@
1
+ import { CSSProperties, ReactNode } from 'react';
2
+ import { Styles as FloaterStyles } from 'react-floater';
3
+ import { ValueOf } from 'type-fest';
4
+
5
+ import { ACTIONS, EVENTS, LIFECYCLE, ORIGIN, STATUS } from '~/literals';
6
+
7
+ export type Actions = ValueOf<typeof ACTIONS>;
8
+ export type Events = ValueOf<typeof EVENTS>;
9
+ export type Lifecycle = ValueOf<typeof LIFECYCLE>;
10
+ export type Origin = ValueOf<typeof ORIGIN>;
11
+ export type Status = ValueOf<typeof STATUS>;
12
+
13
+ export type AnyObject<T = any> = Record<string, T>;
14
+
15
+ export type NarrowPlainObject<T extends Record<string, any>> = Exclude<
16
+ T,
17
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
18
+ Array<unknown> | Function | Map<unknown, unknown> | Set<unknown>
19
+ >;
20
+
21
+ export interface Locale {
22
+ /**
23
+ * Label for the back button.
24
+ * @default 'Back'
25
+ */
26
+ back?: ReactNode;
27
+ /**
28
+ * Label for the close button.
29
+ * @default 'Close'
30
+ */
31
+ close?: ReactNode;
32
+ /**
33
+ * Label for the last button.
34
+ * @default 'Last'
35
+ */
36
+ last?: ReactNode;
37
+ /**
38
+ * Label for the next button.
39
+ * @default 'Next'
40
+ */
41
+ next?: ReactNode;
42
+ /**
43
+ * Label for the next button with `showProgress`.
44
+ * Use the `{step}` and `{steps}` placeholders to display the current step and the total steps.
45
+ * @default 'Next (Step {step} of {steps})'
46
+ */
47
+ nextLabelWithProgress?: ReactNode;
48
+ /**
49
+ * Label for the open button.
50
+ * @default 'Open the dialog'
51
+ */
52
+ open?: ReactNode;
53
+ /**
54
+ * Label for the skip button.
55
+ * @default 'Skip'
56
+ */
57
+ skip?: ReactNode;
58
+ }
59
+
60
+ export type Placement =
61
+ | 'top'
62
+ | 'top-start'
63
+ | 'top-end'
64
+ | 'bottom'
65
+ | 'bottom-start'
66
+ | 'bottom-end'
67
+ | 'left'
68
+ | 'left-start'
69
+ | 'left-end'
70
+ | 'right'
71
+ | 'right-start'
72
+ | 'right-end';
73
+
74
+ export interface Styles {
75
+ beacon: CSSProperties;
76
+ beaconInner: CSSProperties;
77
+ beaconOuter: CSSProperties;
78
+ buttonBack: CSSProperties;
79
+ buttonClose: CSSProperties;
80
+ buttonNext: CSSProperties;
81
+ buttonSkip: CSSProperties;
82
+ options: Partial<StylesOptions>;
83
+ overlay: CSSProperties;
84
+ overlayLegacy: CSSProperties;
85
+ overlayLegacyCenter: CSSProperties;
86
+ spotlight: CSSProperties;
87
+ spotlightLegacy: CSSProperties;
88
+ tooltip: CSSProperties;
89
+ tooltipContainer: CSSProperties;
90
+ tooltipContent: CSSProperties;
91
+ tooltipFooter: CSSProperties;
92
+ tooltipFooterSpacer: CSSProperties;
93
+ tooltipTitle: CSSProperties;
94
+ }
95
+
96
+ export interface StylesWithFloaterStyles extends Styles {
97
+ floaterStyles: FloaterStyles;
98
+ }
99
+
100
+ export interface StylesOptions {
101
+ arrowColor: string;
102
+ backgroundColor: string;
103
+ beaconSize: number;
104
+ overlayColor: string;
105
+ primaryColor: string;
106
+ spotlightShadow: string;
107
+ textColor: string;
108
+ width?: string | number;
109
+ zIndex: number;
110
+ }
@@ -0,0 +1,382 @@
1
+ import { ElementType, MouseEventHandler, ReactNode, RefCallback } from 'react';
2
+ import { Props as FloaterProps } from 'react-floater';
3
+ import { PartialDeep, SetRequired, Simplify } from 'type-fest';
4
+
5
+ import type { StoreInstance } from '~/modules/store';
6
+
7
+ import { Actions, Events, Lifecycle, Locale, Origin, Placement, Status, Styles } from './common';
8
+
9
+ export type BaseProps = {
10
+ /**
11
+ * A React component to use instead the default Beacon.
12
+ */
13
+ beaconComponent?: ElementType<BeaconRenderProps>;
14
+ /**
15
+ * Disable closing the tooltip on ESC.
16
+ * @default false
17
+ */
18
+ disableCloseOnEsc?: boolean;
19
+ /**
20
+ * Don't show the overlay.
21
+ * @default false
22
+ */
23
+ disableOverlay?: boolean;
24
+ /**
25
+ * Don't close the tooltip when clicking the overlay.
26
+ * @default false
27
+ */
28
+ disableOverlayClose?: boolean;
29
+ /**
30
+ * Disable the fix to handle "unused" overflow parents.
31
+ * @default false
32
+ */
33
+ disableScrollParentFix?: boolean;
34
+ /**
35
+ * @default false
36
+ */
37
+ disableScrolling?: boolean;
38
+ /**
39
+ * Options to be passed to react-floater
40
+ */
41
+ floaterProps?: Partial<FloaterProps>;
42
+ /**
43
+ * Hide the Back button.
44
+ * @default false
45
+ */
46
+ hideBackButton?: boolean;
47
+ /**
48
+ * Hide the Close button.
49
+ * @default false
50
+ */
51
+ hideCloseButton?: boolean;
52
+ /**
53
+ * The strings used in the tooltip.
54
+ */
55
+ locale?: Locale;
56
+ /**
57
+ * @default false
58
+ */
59
+ showProgress?: boolean;
60
+ /**
61
+ * @default false
62
+ */
63
+ showSkipButton?: boolean;
64
+ /**
65
+ * @default false
66
+ */
67
+ spotlightClicks?: boolean;
68
+ /**
69
+ * The padding of the spotlight.
70
+ * @default 10
71
+ */
72
+ spotlightPadding?: number;
73
+ /**
74
+ * Override the styling of the Tooltip
75
+ */
76
+ styles?: PartialDeep<Styles>;
77
+ /**
78
+ * A React component to use instead the default Tooltip.
79
+ */
80
+ tooltipComponent?: ElementType<TooltipRenderProps>;
81
+ };
82
+
83
+ export type BeaconProps = Simplify<
84
+ Pick<Props, 'beaconComponent' | 'nonce'> &
85
+ BeaconRenderProps & {
86
+ locale: Locale;
87
+ onClickOrHover: MouseEventHandler<HTMLElement>;
88
+ shouldFocus: boolean;
89
+ styles: Styles;
90
+ }
91
+ >;
92
+
93
+ export type BeaconRenderProps = {
94
+ continuous: boolean;
95
+ index: number;
96
+ isLastStep: boolean;
97
+ size: number;
98
+ step: StepMerged;
99
+ };
100
+
101
+ export type Callback = (data: CallBackProps) => void;
102
+
103
+ export type CallBackProps = {
104
+ /**
105
+ * The action that updated the state.
106
+ */
107
+ action: Actions;
108
+ /**
109
+ * It the tour is in `controlled` mode.
110
+ * (using the `stepIndex` prop)
111
+ */
112
+ controlled: boolean;
113
+ /**
114
+ * The current step's index
115
+ */
116
+ index: number;
117
+ /**
118
+ * The step's lifecycle.
119
+ */
120
+ lifecycle: Lifecycle;
121
+ /**
122
+ * The element that triggered the action (if available).
123
+ */
124
+ origin: Origin | null;
125
+ /**
126
+ * The number of steps
127
+ */
128
+ size: number;
129
+ /**
130
+ * The tour's status.
131
+ */
132
+ status: Status;
133
+ /**
134
+ * The current step's data.
135
+ */
136
+ step: Step;
137
+ /**
138
+ * The type of the event.
139
+ */
140
+ type: Events;
141
+ };
142
+
143
+ export type OverlayProps = Simplify<
144
+ StepMerged & {
145
+ continuous: boolean;
146
+ debug: boolean;
147
+ lifecycle: Lifecycle;
148
+ onClickOverlay: () => void;
149
+ }
150
+ >;
151
+
152
+ export type Props = Simplify<
153
+ BaseProps & {
154
+ /**
155
+ * A function to be called when Joyride's state changes.
156
+ * It returns a single parameter with the state.
157
+ */
158
+ callback?: Callback;
159
+ /**
160
+ * The tour is played sequentially with the Next button.
161
+ * @default false
162
+ */
163
+ continuous?: boolean;
164
+ /**
165
+ * Log Joyride's actions to the console.
166
+ * @default false
167
+ */
168
+ debug?: boolean;
169
+ /**
170
+ * Get the store methods to control the tour programmatically. `prev, next, go, close, skip, reset, info`
171
+ */
172
+ getHelpers?: (helpers: StoreHelpers) => void;
173
+ /**
174
+ * A nonce value for inline styles (Content Security Policy - CSP)
175
+ */
176
+ nonce?: string;
177
+ /**
178
+ * Run/stop the tour.
179
+ * @default true
180
+ */
181
+ run?: boolean;
182
+ /**
183
+ * The duration for scroll to element.
184
+ * @default 300
185
+ */
186
+ scrollDuration?: number;
187
+ /**
188
+ * The scroll distance from the element scrollTop value.
189
+ * @default 20
190
+ */
191
+ scrollOffset?: number;
192
+ /**
193
+ * Scroll the page for the first step.
194
+ * @default false
195
+ */
196
+ scrollToFirstStep?: boolean;
197
+ /**
198
+ * Setting a number here will turn Joyride into `controlled` mode.
199
+ * You'll have to keep an internal state by yourself and update it with the events in the `callback`.
200
+ */
201
+ stepIndex?: number;
202
+ /**
203
+ * The tour's steps.
204
+ */
205
+ steps: Array<Step>;
206
+ }
207
+ >;
208
+
209
+ export type State = {
210
+ action: Actions;
211
+ controlled: boolean;
212
+ index: number;
213
+ lifecycle: Lifecycle;
214
+ origin: Origin | null;
215
+ size: number;
216
+ status: Status;
217
+ };
218
+
219
+ export type Step = Simplify<
220
+ BaseProps & {
221
+ /**
222
+ * The tooltip's body.
223
+ */
224
+ content: ReactNode;
225
+ /**
226
+ * Additional data you can add to the step.
227
+ */
228
+ data?: any;
229
+ /**
230
+ * Don't show the Beacon before the tooltip.
231
+ * @default false
232
+ */
233
+ disableBeacon?: boolean;
234
+ /**
235
+ * The event to trigger the beacon.
236
+ * @default click
237
+ */
238
+ event?: 'click' | 'hover';
239
+ /**
240
+ * Options to be passed to react-floater
241
+ */
242
+ floaterProps?: FloaterProps;
243
+ /**
244
+ * Hide the tooltip's footer.
245
+ * @default false
246
+ */
247
+ hideFooter?: boolean;
248
+ /**
249
+ * Force the step to be fixed.
250
+ * @default false
251
+ */
252
+ isFixed?: boolean;
253
+ /**
254
+ * @default 10
255
+ */
256
+ offset?: number;
257
+ /**
258
+ * The placement of the beacon and tooltip. It will re-position itself if there's no space available.
259
+ * @default bottom
260
+ */
261
+ placement?: Placement | 'auto' | 'center';
262
+ /**
263
+ * The placement of the beacon. It will use the `placement` if nothing is passed
264
+ */
265
+ placementBeacon?: Placement;
266
+ /**
267
+ * The target for the step.
268
+ * It can be a CSS selector or an HTMLElement ref.
269
+ */
270
+ target: string | HTMLElement;
271
+ /**
272
+ * The tooltip's title.
273
+ */
274
+ title?: ReactNode;
275
+ }
276
+ >;
277
+
278
+ export type StepMerged = Simplify<
279
+ SetRequired<
280
+ Step,
281
+ | 'disableBeacon'
282
+ | 'disableCloseOnEsc'
283
+ | 'disableOverlay'
284
+ | 'disableOverlayClose'
285
+ | 'disableScrollParentFix'
286
+ | 'disableScrolling'
287
+ | 'event'
288
+ | 'hideBackButton'
289
+ | 'hideCloseButton'
290
+ | 'hideFooter'
291
+ | 'isFixed'
292
+ | 'locale'
293
+ | 'offset'
294
+ | 'placement'
295
+ | 'showProgress'
296
+ | 'showSkipButton'
297
+ | 'spotlightClicks'
298
+ | 'spotlightPadding'
299
+ > & {
300
+ styles: Styles;
301
+ }
302
+ >;
303
+
304
+ export type StepProps = Simplify<
305
+ State & {
306
+ callback: Callback;
307
+ continuous: boolean;
308
+ debug: boolean;
309
+ helpers: StoreHelpers;
310
+ nonce?: string;
311
+ shouldScroll: boolean;
312
+ step: StepMerged;
313
+ store: StoreInstance;
314
+ }
315
+ >;
316
+
317
+ export type StoreHelpers = {
318
+ close: (origin?: Origin | null) => void;
319
+ go: (nextIndex: number) => void;
320
+ info: () => State;
321
+ next: () => void;
322
+ open: () => void;
323
+ prev: () => void;
324
+ reset: (restart: boolean) => void;
325
+ skip: () => void;
326
+ };
327
+
328
+ export type StoreOptions = Simplify<
329
+ Props & {
330
+ controlled: boolean;
331
+ }
332
+ >;
333
+
334
+ export type TooltipProps = {
335
+ continuous: boolean;
336
+ helpers: StoreHelpers;
337
+ index: number;
338
+ isLastStep: boolean;
339
+ setTooltipRef: RefCallback<HTMLElement>;
340
+ size: number;
341
+ step: StepMerged;
342
+ };
343
+
344
+ export type TooltipRenderProps = Simplify<
345
+ BeaconRenderProps & {
346
+ backProps: {
347
+ 'aria-label': string;
348
+ 'data-action': string;
349
+ onClick: MouseEventHandler<HTMLElement>;
350
+ role: string;
351
+ title: string;
352
+ };
353
+ closeProps: {
354
+ 'aria-label': string;
355
+ 'data-action': string;
356
+ onClick: MouseEventHandler<HTMLElement>;
357
+ role: string;
358
+ title: string;
359
+ };
360
+ primaryProps: {
361
+ 'aria-label': string;
362
+ 'data-action': string;
363
+ onClick: MouseEventHandler<HTMLElement>;
364
+ role: string;
365
+ title: string;
366
+ };
367
+ skipProps: {
368
+ 'aria-label': string;
369
+ 'data-action': string;
370
+ onClick: MouseEventHandler<HTMLElement>;
371
+ role: string;
372
+ title: string;
373
+ };
374
+ tooltipProps: {
375
+ 'aria-modal': boolean;
376
+ ref: RefCallback<HTMLElement>;
377
+ role: string;
378
+ };
379
+ }
380
+ >;
381
+
382
+ export type { Props as FloaterProps } from 'react-floater';
@@ -0,0 +1,2 @@
1
+ export * from './common';
2
+ export * from './components';