@korsolutions/guidon 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/src/types.ts ADDED
@@ -0,0 +1,242 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ /**
4
+ * Position of tooltip relative to the highlighted element
5
+ */
6
+ export type TooltipPosition = 'top' | 'bottom' | 'left' | 'right' | 'auto';
7
+
8
+ /**
9
+ * Defines the measurements of a target element
10
+ */
11
+ export interface TargetMeasurements {
12
+ x: number;
13
+ y: number;
14
+ width: number;
15
+ height: number;
16
+ }
17
+
18
+ /**
19
+ * A single step in the guidon
20
+ */
21
+ export interface GuidonStep {
22
+ /** Unique identifier for this step */
23
+ id: string;
24
+ /** ID of the target element to highlight */
25
+ targetId: string;
26
+ /** Title displayed in the tooltip */
27
+ title: string;
28
+ /** Description/content displayed in the tooltip */
29
+ description: string;
30
+ /** Preferred position of the tooltip */
31
+ tooltipPosition?: TooltipPosition;
32
+ /** Custom content to render in the tooltip */
33
+ customContent?: ReactNode;
34
+ /** Called when this step becomes active */
35
+ onStepEnter?: () => void;
36
+ /** Called when leaving this step */
37
+ onStepExit?: () => void;
38
+ }
39
+
40
+ /**
41
+ * Theme configuration for guidon styling
42
+ */
43
+ export interface GuidonTheme {
44
+ /** Color of the backdrop overlay */
45
+ backdropColor?: string;
46
+ /** Opacity of the backdrop (0-1) */
47
+ backdropOpacity?: number;
48
+ /** Background color of the tooltip */
49
+ tooltipBackgroundColor?: string;
50
+ /** Border color of the tooltip */
51
+ tooltipBorderColor?: string;
52
+ /** Border radius of the tooltip */
53
+ tooltipBorderRadius?: number;
54
+ /** Color of the title text */
55
+ titleColor?: string;
56
+ /** Color of the description text */
57
+ descriptionColor?: string;
58
+ /** Primary/accent color (buttons, progress) */
59
+ primaryColor?: string;
60
+ /** Muted/secondary color */
61
+ mutedColor?: string;
62
+ /** Border radius of the spotlight cutout */
63
+ spotlightBorderRadius?: number;
64
+ /** Padding around the highlighted element */
65
+ spotlightPadding?: number;
66
+ }
67
+
68
+ /**
69
+ * State of a specific guidon tour
70
+ */
71
+ export interface GuidonProgress {
72
+ /** Unique identifier for the guidon */
73
+ guidonId: string;
74
+ /** Whether this guidon has been completed */
75
+ completed: boolean;
76
+ /** Index of the last viewed step (for resuming) */
77
+ lastStepIndex?: number;
78
+ /** Timestamp of completion */
79
+ completedAt?: string;
80
+ /** Number of times this guidon has been completed */
81
+ completionCount?: number;
82
+ }
83
+
84
+ /**
85
+ * Persistence adapter interface for saving/loading guidon progress
86
+ * Implement this interface to connect the guidon to your backend
87
+ */
88
+ export interface GuidonPersistenceAdapter {
89
+ /**
90
+ * Load the progress for a specific guidon
91
+ * @param guidonId - Unique identifier for the guidon
92
+ * @returns The progress data or null if not found
93
+ */
94
+ loadProgress: (guidonId: string) => Promise<GuidonProgress | null>;
95
+
96
+ /**
97
+ * Save the progress for a specific guidon
98
+ * @param progress - The progress data to save
99
+ */
100
+ saveProgress: (progress: GuidonProgress) => Promise<void>;
101
+
102
+ /**
103
+ * Load all guidon progress (optional, for bulk operations)
104
+ * @returns Map of guidon IDs to progress data
105
+ */
106
+ loadAllProgress?: () => Promise<Record<string, GuidonProgress>>;
107
+
108
+ /**
109
+ * Clear progress for a specific guidon (for replay functionality)
110
+ * @param guidonId - Unique identifier for the guidon
111
+ */
112
+ clearProgress?: (guidonId: string) => Promise<void>;
113
+ }
114
+
115
+ /**
116
+ * Configuration for a guidon
117
+ */
118
+ export interface GuidonConfig {
119
+ /** Unique identifier for this guidon */
120
+ id: string;
121
+ /** Steps in the guidon */
122
+ steps: GuidonStep[];
123
+ /** Theme customization */
124
+ theme?: GuidonTheme;
125
+ /** Animation duration in milliseconds */
126
+ animationDuration?: number;
127
+ /** Called when the guidon is completed */
128
+ onComplete?: () => void;
129
+ /** Called when the guidon is skipped */
130
+ onSkip?: () => void;
131
+ /** Called when the step changes */
132
+ onStepChange?: (stepIndex: number, step: GuidonStep) => void;
133
+ }
134
+
135
+ /**
136
+ * Labels for tooltip buttons
137
+ */
138
+ export interface GuidonTooltipLabels {
139
+ next?: string;
140
+ previous?: string;
141
+ skip?: string;
142
+ finish?: string;
143
+ stepOf?: (current: number, total: number) => string;
144
+ }
145
+
146
+ /**
147
+ * Props for custom tooltip renderer
148
+ */
149
+ export interface GuidonTooltipRenderProps {
150
+ step: GuidonStep;
151
+ currentIndex: number;
152
+ totalSteps: number;
153
+ onNext: () => void;
154
+ onPrevious: () => void;
155
+ onSkip: () => void;
156
+ }
157
+
158
+ /**
159
+ * Props for the GuidonProvider component
160
+ */
161
+ export interface GuidonProviderProps {
162
+ children: ReactNode;
163
+ /** Configuration for the guidon */
164
+ config: GuidonConfig;
165
+ /** Whether to auto-start when the component mounts */
166
+ autoStart?: boolean;
167
+ /** Condition function to determine if guidon should start */
168
+ shouldStart?: () => boolean | Promise<boolean>;
169
+ /** Persistence adapter for saving/loading progress */
170
+ persistenceAdapter?: GuidonPersistenceAdapter;
171
+ /** Custom portal component for rendering overlay */
172
+ portalComponent?: React.ComponentType<{ children: ReactNode }>;
173
+ /** Custom tooltip renderer */
174
+ renderTooltip?: (props: GuidonTooltipRenderProps) => ReactNode;
175
+ /** Customize tooltip labels */
176
+ tooltipLabels?: GuidonTooltipLabels;
177
+ /** Called when backdrop is pressed */
178
+ onBackdropPress?: () => void;
179
+ }
180
+
181
+ /**
182
+ * Props for the GuidonTarget component
183
+ */
184
+ export interface GuidonTargetProps {
185
+ children: ReactNode;
186
+ /** Target ID that matches a step's targetId */
187
+ targetId: string;
188
+ /** Whether this target is currently active (for conditional rendering) */
189
+ active?: boolean;
190
+ }
191
+
192
+ /**
193
+ * Internal store state
194
+ */
195
+ export interface GuidonState {
196
+ /** Currently active guidon config */
197
+ config: GuidonConfig | null;
198
+ /** Whether the guidon is currently active */
199
+ isActive: boolean;
200
+ /** Current step index */
201
+ currentStepIndex: number;
202
+ /** Whether the guidon has been completed */
203
+ isCompleted: boolean;
204
+ /** Map of target IDs to their measurements */
205
+ targetMeasurements: Record<string, TargetMeasurements>;
206
+ /** Loading state for persistence operations */
207
+ isLoading: boolean;
208
+ /** Error from persistence operations */
209
+ error: string | null;
210
+ }
211
+
212
+ /**
213
+ * Internal store actions
214
+ */
215
+ export interface GuidonActions {
216
+ /** Configure the guidon */
217
+ configure: (config: GuidonConfig) => void;
218
+ /** Start the guidon */
219
+ start: () => void;
220
+ /** Go to the next step */
221
+ next: () => void;
222
+ /** Go to the previous step */
223
+ previous: () => void;
224
+ /** Go to a specific step */
225
+ goToStep: (index: number) => void;
226
+ /** Skip the guidon */
227
+ skip: () => void;
228
+ /** Complete the guidon */
229
+ complete: () => void;
230
+ /** Reset the guidon state */
231
+ reset: () => void;
232
+ /** Register a target's measurements */
233
+ registerTarget: (targetId: string, measurements: TargetMeasurements) => void;
234
+ /** Unregister a target */
235
+ unregisterTarget: (targetId: string) => void;
236
+ /** Set loading state */
237
+ setLoading: (isLoading: boolean) => void;
238
+ /** Set error state */
239
+ setError: (error: string | null) => void;
240
+ }
241
+
242
+ export type GuidonStore = GuidonState & GuidonActions;