react-headless-tour 0.1.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 react-headless-tour contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,245 @@
1
+ # react-headless-tour
2
+
3
+ [![npm version](https://img.shields.io/npm/v/react-headless-tour.svg)](https://www.npmjs.com/package/react-headless-tour)
4
+ [![npm downloads](https://img.shields.io/npm/dm/react-headless-tour.svg)](https://www.npmjs.com/package/react-headless-tour)
5
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/react-headless-tour)](https://bundlephobia.com/package/react-headless-tour)
6
+ [![license](https://img.shields.io/npm/l/react-headless-tour.svg)](./LICENSE)
7
+
8
+ Fully customizable, **headless** product tour / onboarding library for React & Next.js.
9
+
10
+ All the logic, none of the opinions. The library owns targeting, positioning, the animated spotlight, keyboard navigation and state — you own every pixel. Restyle it with CSS variables, class names, or replace whole components with your own.
11
+
12
+ - ðŸŠķ **Tiny** — ~4.5 kB min+gzip of library code (~12 kB total with its single dependency, Floating UI). No animation library.
13
+ - ðŸŽĻ **Three levels of theming** — CSS variables → per-part `classNames` → full component replacement
14
+ - âœĻ **Springy spotlight** — an SVG-mask cutout that glides smoothly between targets via pure CSS transitions
15
+ - 📐 **Bulletproof positioning** — Floating UI under the hood: auto flip, shift, arrow
16
+ - âŒĻïļ **Keyboard navigation** — `←` `→` `Enter` `Esc` out of the box
17
+ - ðŸ–ąïļ **Interactable steps** — let users click the highlighted element mid-tour
18
+ - 🧭 **Follows moving targets** — survives scrolling, resizes, sticky headers, layout shifts
19
+ - ðŸ§Đ **Centered modal steps** — omit `target` for welcome/outro screens
20
+ - 🌐 **SSR-safe** — works with the Next.js App Router (ships `"use client"`), no `window` access on the server
21
+ - â™ŋ **Accessible** — `role="dialog"` with step announcements, focus management, `prefers-reduced-motion` support; the demo audits clean with axe-core
22
+ - 🔷 **TypeScript-first** — every prop and slot is fully typed
23
+
24
+ ## Why this over the alternatives?
25
+
26
+ | Library | Bundle cost (min+gzip) | React components | Theming | License |
27
+ | --- | --- | --- | --- | --- |
28
+ | **react-headless-tour** | **12.3 kB (4.5 kB core)** | ✅ React | ✅ Fully headless | MIT |
29
+ | react-joyride | 25.0 kB | ✅ React | ⚠ïļ Styled, override via props | MIT |
30
+ | intro.js | 17.2 kB | ❌ Vanilla + wrapper | ⚠ïļ Theme via CSS overrides | AGPL / paid commercial |
31
+ | driver.js | 7.2 kB | ❌ Vanilla | ⚠ïļ Theme via CSS overrides | MIT |
32
+
33
+ <sub>Sizes via bundlephobia, September 2026. "Core" excludes the Floating UI positioning engine, which many apps already ship via other popover/tooltip libraries.</sub>
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ npm install react-headless-tour
39
+ ```
40
+
41
+ React 18 or 19. The only dependency is `@floating-ui/react-dom` (positioning); animations are pure CSS.
42
+
43
+ ## Quick start
44
+
45
+ ```tsx
46
+ "use client"; // Next.js App Router
47
+
48
+ import { TourProvider, useTour, type TourStep } from "react-headless-tour";
49
+
50
+ const steps: TourStep[] = [
51
+ { title: "Welcome 👋", content: "No target = centered modal step." },
52
+ { target: "#stats", title: "Your metrics", content: "Everything at a glance." },
53
+ { target: "#new-project", title: "Create a project", placement: "left", interactable: true },
54
+ ];
55
+
56
+ function StartButton() {
57
+ const { start } = useTour();
58
+ return <button onClick={() => start()}>Start tour</button>;
59
+ }
60
+
61
+ export default function App() {
62
+ return (
63
+ <TourProvider steps={steps}>
64
+ <StartButton />
65
+ {/* ...your app... */}
66
+ </TourProvider>
67
+ );
68
+ }
69
+ ```
70
+
71
+ That's it — the default card is intentionally neutral and already looks fine. Now make it yours:
72
+
73
+ ## Theming
74
+
75
+ ### Level 1 — CSS variables (zero code)
76
+
77
+ Every visual decision of the default UI is a CSS variable with a fallback. Set them globally, on a wrapper class, or inline via the `theme` prop:
78
+
79
+ ```css
80
+ /* e.g. in your globals.css */
81
+ .my-tour {
82
+ --tour-bg: #16181d;
83
+ --tour-fg: #f9fafb;
84
+ --tour-muted: #9ca3af;
85
+ --tour-accent: #4f46e5; /* primary button */
86
+ --tour-accent-fg: #ffffff;
87
+ --tour-radius: 14px;
88
+ --tour-shadow: 0 10px 38px rgba(0, 0, 0, 0.35);
89
+ --tour-border: 1px solid rgba(255, 255, 255, 0.14);
90
+ --tour-overlay-color: rgba(10, 12, 24, 0.68);
91
+ --tour-max-width: 340px;
92
+ --tour-padding: 16px;
93
+ --tour-font: "Inter", sans-serif;
94
+ --tour-arrow-size: 12px;
95
+ --tour-z-index: 10000;
96
+ }
97
+ ```
98
+
99
+ ```tsx
100
+ <TourProvider steps={steps} classNames={{ root: "my-tour" }} />
101
+ // or inline:
102
+ <TourProvider steps={steps} theme={{ "--tour-accent": "#7c3aed" }} />
103
+ ```
104
+
105
+ Because the variables cascade from the tour root, they automatically follow your app's light/dark mode if you define them under your theme selectors.
106
+
107
+ ### Level 2 — class names (Tailwind, CSS Modules, â€Ķ)
108
+
109
+ Every rendered part exposes a class hook and a stable `data-tour-*` attribute:
110
+
111
+ ```tsx
112
+ <TourProvider
113
+ steps={steps}
114
+ classNames={{
115
+ card: "rounded-2xl bg-white shadow-xl p-4",
116
+ title: "font-bold text-slate-900",
117
+ content: "text-sm text-slate-500",
118
+ primaryButton: "bg-indigo-600 text-white rounded-lg px-3 py-1.5",
119
+ skipButton: "text-slate-400",
120
+ }}
121
+ />
122
+ ```
123
+
124
+ Available keys: `root`, `overlay`, `popover`, `card`, `title`, `content`, `footer`, `progress`, `navButton`, `primaryButton`, `skipButton`, `arrow`.
125
+
126
+ ### Level 3 — bring your own components (fully headless)
127
+
128
+ Replace the card entirely. You get the full tour state and controls as props; the library still handles positioning, the spotlight and animations:
129
+
130
+ ```tsx
131
+ import type { TourCardProps } from "react-headless-tour";
132
+
133
+ function MyCard({ step, stepIndex, totalSteps, isFirst, isLast, next, prev, stop, arrow }: TourCardProps) {
134
+ return (
135
+ <div className="my-design-system-popover">
136
+ {arrow /* optional — skip it for an arrowless design */}
137
+ <h3>{step.title}</h3>
138
+ <p>{step.content}</p>
139
+ <progress value={stepIndex + 1} max={totalSteps} />
140
+ {!isFirst && <button onClick={prev}>Back</button>}
141
+ <button onClick={next}>{isLast ? "Done" : "Next"}</button>
142
+ <button onClick={() => stop("skipped")}>Skip</button>
143
+ </div>
144
+ );
145
+ }
146
+
147
+ <TourProvider steps={steps} components={{ Card: MyCard, Arrow: MyArrow }} />
148
+ ```
149
+
150
+ Pass anything your card needs per step through `step.data`.
151
+
152
+ ## API
153
+
154
+ ### `<TourProvider>`
155
+
156
+ | Prop | Type | Default | Description |
157
+ | --- | --- | --- | --- |
158
+ | `steps` | `TourStep[]` | — | The tour definition |
159
+ | `autoStart` | `boolean` | `false` | Start on mount |
160
+ | `stepIndex` / `onStepChange` | `number` / `(i, step) => void` | — | Controlled mode |
161
+ | `onStart` / `onStop` | callbacks | — | `onStop` receives a reason: `finished`, `skipped`, `escape`, `mask`, `programmatic` |
162
+ | `components` | `{ Card?, Arrow? }` | — | Component slots |
163
+ | `classNames` | `TourClassNames` | — | Class hooks per part |
164
+ | `theme` | CSS vars object | — | Inline `--tour-*` overrides |
165
+ | `overlayColor` | `string` | `rgba(0,0,0,0.55)` | Dim color |
166
+ | `overlayBlur` | `number` | `0` | Frosted-glass blur (px) |
167
+ | `showOverlay` | `boolean` | `true` | Render the dim layer |
168
+ | `closeOnMaskClick` | `boolean` | `false` | Click outside to stop |
169
+ | `keyboard` | `boolean` | `true` | Arrow keys / Enter / Esc |
170
+ | `spotlightPadding` | `number` | `8` | Space around targets (px) |
171
+ | `spotlightRadius` | `number` | `8` | Spotlight corner radius (px) |
172
+ | `offset` | `number` | `12` | Target ↔ popover gap (px) |
173
+ | `lockScroll` | `boolean` | `false` | Lock body scroll while active |
174
+ | `scrollIntoViewOptions` | `ScrollIntoViewOptions` | smooth/center | Auto-scroll behavior |
175
+ | `portalContainer` | `Element` | `document.body` | Portal destination |
176
+ | `zIndex` | `number` | `10000` | Root z-index |
177
+ | `labels` | object | — | `next`, `prev`, `finish`, `skip`, `progress(i, n)` — i18n-ready |
178
+
179
+ ### `TourStep`
180
+
181
+ | Field | Type | Description |
182
+ | --- | --- | --- |
183
+ | `target` | `string \| () => Element \| null` | CSS selector or resolver. Omit for a centered modal step |
184
+ | `title`, `content` | `ReactNode` | Used by the default card |
185
+ | `placement` | `"top" \| "bottom" \| "left" \| "right"` (+ `-start`/`-end`) | Preferred side; auto-flips |
186
+ | `interactable` | `boolean` | Allow clicks on the highlighted element |
187
+ | `spotlightPadding`, `spotlightRadius` | `number` | Per-step overrides |
188
+ | `disableScroll` | `boolean` | Skip auto scroll-into-view |
189
+ | `data` | `unknown` | Free-form payload for custom cards |
190
+ | `onEnter`, `onExit` | `(step, index) => void` | Step lifecycle hooks |
191
+
192
+ ### `useTour()`
193
+
194
+ Call it anywhere under the provider — perfect for "restart tour" menu items or driving the tour from app logic. Custom Cards receive all of this as props too.
195
+
196
+ | Member | Type | Description |
197
+ | --- | --- | --- |
198
+ | `isActive` | `boolean` | Whether the tour is running |
199
+ | `stepIndex` / `totalSteps` | `number` | Active step index (`-1` when off) and total step count |
200
+ | `step` | `TourStep \| null` | The active step object |
201
+ | `isFirst` / `isLast` | `boolean` | Position helpers for building custom cards |
202
+ | `start(atIndex?)` | `function` | Start the tour, optionally at a specific step |
203
+ | `stop(reason?)` | `function` | Stop the tour |
204
+ | `next()` / `prev()` / `goTo(i)` | `function` | Navigate between steps |
205
+
206
+ ## Multi-page tours
207
+
208
+ Tours are not limited to a single page. Mount `TourProvider` once in your root layout (so it survives route changes) and navigate inside a step's `onEnter`. If a step's target isn't in the DOM yet, the library keeps re-resolving it every frame — the popover simply attaches once the new page renders:
209
+
210
+ ```tsx
211
+ // app/providers.tsx ("use client"), rendered inside app/layout.tsx
212
+ function Providers({ children }: { children: React.ReactNode }) {
213
+ const router = useRouter();
214
+
215
+ const steps: TourStep[] = [
216
+ { target: "#dashboard-stats", title: "Your metrics" },
217
+ {
218
+ target: "#settings-form",
219
+ title: "Configure your workspace",
220
+ onEnter: () => router.push("/settings"), // navigate, target resolves after render
221
+ },
222
+ {
223
+ target: "#dashboard-stats",
224
+ title: "Back home",
225
+ onEnter: () => router.push("/"),
226
+ },
227
+ ];
228
+
229
+ return <TourProvider steps={steps}>{children}</TourProvider>;
230
+ }
231
+ ```
232
+
233
+ Tour state lives in React context above your pages, so `next`/`prev`/`stepIndex` all keep working across navigations. (For back-navigation with `prev`, trigger the route change from `onEnter` of the step you land on — as above — rather than from `onExit`.)
234
+
235
+ ## Demo
236
+
237
+ The [`demo/`](demo) folder contains a Next.js app showing all three theming levels:
238
+
239
+ ```bash
240
+ cd demo && npm install && npm run dev
241
+ ```
242
+
243
+ ## License
244
+
245
+ MIT