0.0.1-beta · Beta · TypeScript · MIT
Dim the page. Light the next step.
Step-by-step product tours. A step is done when the user really clicks or types what it asks, not when a timer runs out. The example below is made with it.
import { createSpotlight, click, input, en } from '@spotlight-kit/dom';
const tour = createSpotlight(
{
id: 'first-project',
steps: [
{ id: 'welcome', title: 'Welcome' },
{
id: 'name',
title: 'Name your project',
target: '#project-name',
completion: input(undefined, (value) => value.trim().length >= 3),
},
{
id: 'create',
title: 'Create it',
target: '#create-project',
completion: click(),
},
// Not on the page yet: the tour waits for it
{ id: 'card', title: 'Your project', target: '#project-card' },
],
},
{ labels: en },
);
tour.start();
The tour’s state
{ status: 'idle' }
Type with an input method: a draft does not count until it is committed. Escape leaves, the arrow keys go back and forth.
How to use
Four steps into your page.
Install it, say where each step points and when it is done, and start. The overlay, popover, scrolling and following are taken care of.
Install
For a plain HTML page the DOM package is all you need; the engine comes with it.
$ npm i @spotlight-kit/dom@betaWrite the steps
A step is plain data: a title, a body, and what it points at. Without a target it sits in the middle; a target not rendered yet is waited for.
const tour = createSpotlight({ id: 'onboarding', steps: [ { id: 'hello', title: 'Welcome' }, { id: 'export', title: 'Export', target: '#export', placement: 'top' }, ], });Say when a step is done
A step with a completion cannot be skipped with “Next” until the user does it, and moves on by itself once they have. A function returning true works too, for routes, requests or a store.
Ready-made conditions
click()input()change()submit()event()appears()disappears()attr()hasClass()elementState()
{ id: 'name', target: '#name', completion: input() } { id: 'save', target: '#save', completion: click() } { id: 'list', target: '#list', completion: appears('#list .row') }Start, and remember
The tour keeps nothing itself. Save progress from its events, then pick up with tour.start(index), or never show it again.
tour.start(); tour.on('finish', () => { localStorage.setItem('tour-done', '1'); });
Frameworks
Plain HTML, Vue, React, or your own UI.
The engine is plain TypeScript that never touches the DOM, so the whole UI can be swapped out.
HTML
@spotlight-kit/domIts own overlay and popover, in one function call.
import { createSpotlight } from '@spotlight-kit/dom'; createSpotlight({ id: 'tour', steps }).start();Vue 3
@spotlight-kit/vueA <SpotlightTour> component and useTour(); a slot replaces the popover’s content and keeps its placement.
const tour = createTour({ ...createDomPlatform(), id: 'tour', steps, }); const { state, start } = useTour(tour); <SpotlightTour :tour="tour" />React
@spotlight-kit/reactA <SpotlightTour> component and a useTour() hook, built on useSyncExternalStore.
const tour = createTour({ ...createDomPlatform(), id: 'tour', steps, }); const { state, start } = useTour(tour); <SpotlightTour tour={tour} />Core
@spotlight-kit/coreJust the state machine: subscribe to immutable snapshots and draw them with your own components.
const tour = createTour({ ...createDomPlatform(), id: 'tour', steps, }); tour.subscribe((state) => render(state));
Status
It is in beta.
The API may still change. Try it in your own project, and raise anything on GitHub.