@trailguide/recorder
v0.0.2
Published
Record Trailguide tours by clicking on elements. Capture CSS selectors and export trail JSON.
Maintainers
Readme
@trailguide/recorder
Capture Trailguide steps by clicking on elements. Records CSS selectors and lets you export trail JSON.
Installation
pnpm add @trailguide/recorder
# or
npm install @trailguide/recorderUsage
import { RecorderOverlay, useRecorder } from '@trailguide/recorder';
function App() {
const [showRecorder, setShowRecorder] = useState(false);
const recorder = useRecorder({
trailId: 'my-trail',
trailTitle: 'My Trail',
});
return (
<>
<YourApp />
<button onClick={() => setShowRecorder(true)}>
Open Recorder
</button>
{showRecorder && <RecorderOverlay recorder={recorder} />}
</>
);
}How It Works
- Click "Record" to enter recording mode
- Click on any element in your app
- Fill in the step title, content, and placement
- Repeat for each step
- Click "Export JSON" to download the trail file
API
useRecorder(options)
const {
isRecording, // boolean - recording mode active
steps, // Step[] - captured steps
pendingStep, // current element being configured
startRecording, // () => void
stopRecording, // () => void
toggleRecording, // () => void
addStep, // (step) => void
removeStep, // (index) => void
updateStep, // (index, updates) => void
clearSteps, // () => void
confirmPendingStep, // (details) => void
cancelPendingStep, // () => void
exportTrail, // () => Trail
downloadTrail, // (filename?) => void
} = useRecorder({ trailId, trailTitle });<RecorderOverlay>
Pre-built UI for recording.
<RecorderOverlay recorder={recorder} />Selector Generation
The recorder generates selectors with this priority:
#id- Element ID[data-testid="..."]- Test ID attribute[data-tour-target="..."]- Tour target attribute.unique-class- Unique class selectortag:nth-child(n)- Path-based selector
Tips
- Add
data-testidordata-tour-targetattributes to important elements for stable selectors - Review generated selectors before exporting
- Test the exported trail to ensure selectors still work
