react-tourlight

API Reference

Complete reference for all react-tourlight components, hooks, and types.

SpotlightProviderProps

Props for the <SpotlightProvider> component that wraps your application and manages all tour state.

PropTypeDefaultDescription
childrenReactNode--Your application content
theme'light' | 'dark' | 'auto' | SpotlightTheme'light'Theme preset or custom theme object
overlayColorstring'rgba(0, 0, 0, 0.5)'Overlay background color (with alpha)
transitionDurationnumber300Transition duration in milliseconds
escToDismissbooleantrueWhether pressing Escape dismisses the tour
overlayClickToDismissbooleantrueWhether clicking the overlay dismisses the tour
showProgressbooleantrueWhether to show a progress bar
showSkipbooleantrueWhether to show a skip button
labelsSpotlightLabels--Custom labels for i18n
onComplete(tourId: string) => void--Called when any tour completes
onSkip(tourId: string, stepIndex: number) => void--Called when any tour is skipped
onStateChange(tourId: string, state: TourState) => void--Called with tour state for persistence
initialStateRecord<string, TourState>--Initial state for restoring persisted tours

SpotlightTourProps

Props for the <SpotlightTour> component that registers a tour's steps with the provider.

PropTypeDefaultDescription
idstring--Unique identifier for this tour
stepsSpotlightStep[]--Array of step configurations
onComplete() => void--Called when this tour completes
onSkip(stepIndex: number) => void--Called when this tour is skipped
renderTooltip(props: TooltipRenderProps) => ReactNode--Custom tooltip render function

SpotlightStep

Configuration for a single tour step.

PropTypeDefaultDescription
targetstring | RefObject<HTMLElement | null>--CSS selector or React ref for the target element
titlestring--Step title shown in the tooltip header
contentReactNode--Step content -- string or React element
placement'top' | 'bottom' | 'left' | 'right' | 'auto''auto'Tooltip placement relative to target
spotlightPaddingnumber--Padding around the spotlight cutout (px)
spotlightRadiusnumber--Border radius of the spotlight cutout (px)
action{ label: string; onClick: () => void }--Optional CTA button inside the tooltip
when() => boolean | Promise<boolean>--Condition -- step is skipped if this returns false
onBeforeShow() => void | Promise<void>--Called before the step is shown (can be async)
onAfterShow() => void--Called after the step is visible
onHide() => void--Called when the step is hidden
disableOverlayClosebooleanfalsePrevent overlay click from dismissing
interactivebooleanfalseAllow clicking the highlighted element

SpotlightHighlightProps

Props for the <SpotlightHighlight> component for single-element highlights.

PropTypeDefaultDescription
targetstring | RefObject<HTMLElement | null>--CSS selector or React ref for the target element
titlestring--Tooltip title
contentReactNode--Tooltip content
activebooleantrueWhether the highlight is currently visible
placement'top' | 'bottom' | 'left' | 'right' | 'auto''auto'Tooltip placement relative to target
spotlightPaddingnumber--Padding around the spotlight cutout (px)
spotlightRadiusnumber--Border radius of the spotlight cutout (px)
onDismiss() => void--Called when the highlight is dismissed

useSpotlight()

Hook to access spotlight context. Must be used within a <SpotlightProvider>.

const spotlight = useSpotlight()

Return value: SpotlightContextValue

PropertyTypeDescription
start(tourId: string) => voidStart a tour by its ID
stop() => voidStop the currently active tour
next() => voidAdvance to the next step
previous() => voidGo back to the previous step
skip() => voidSkip the current tour
goToStep(index: number) => voidJump to a specific step by index
isActivebooleanWhether a tour or highlight is currently active
activeTourIdstring | nullID of the currently active tour, or null
currentStepnumberIndex of the current step (zero-based)
totalStepsnumberTotal number of steps in the active tour
registerTour(id, steps, callbacks?) => voidRegister a tour (used internally by SpotlightTour)
unregisterTour(id: string) => voidUnregister a tour (used internally)
highlight(step: SpotlightStep) => voidShow a single-element highlight
dismissHighlight() => voidDismiss the active highlight

useSpotlightControl()

A convenience hook that wraps useSpotlight() with memoized callbacks. Provides the same control methods without the internal registration methods.

const spotlight = useSpotlightControl()

Return value: SpotlightControl

PropertyTypeDescription
start(tourId: string) => voidStart a tour by its ID
stop() => voidStop the currently active tour
next() => voidAdvance to the next step
previous() => voidGo back to the previous step
skip() => voidSkip the current tour
goToStep(index: number) => voidJump to a specific step by index
highlight(step: SpotlightStep) => voidShow a single-element highlight
dismissHighlight() => voidDismiss the active highlight
isActivebooleanWhether a tour or highlight is currently active

useSpotlightTarget()

Hook that returns a RefObject to attach to a target element. Use this instead of CSS selectors when you want type-safe, refactor-friendly targets.

const ref = useSpotlightTarget<HTMLInputElement>()

// Use in steps:
{ target: ref, title: 'Search', content: '...' }

// Attach to element:
<input ref={ref} />

Return value

TypeDescription
RefObject<T | null>A React ref to attach to the target DOM element

SpotlightLabels

Labels for i18n. All properties are optional and fall back to English defaults.

PropertyTypeDefaultDescription
nextstring'Next'Next button label
previousstring'Previous'Previous button label
skipstring'Skip'Skip button label
donestring'Done'Done button label (last step)
closestring'Close'Close button aria-label
stepOf(current: number, total: number) => string'Step {n} of {m}'Step counter format function

TooltipRenderProps

Props passed to the renderTooltip function on <SpotlightTour>.

PropertyTypeDescription
stepSpotlightStepThe current step configuration
next() => voidAdvance to the next step or complete the tour
previous() => voidGo back to the previous step
skip() => voidSkip the tour
currentIndexnumberZero-based index of the current step
totalStepsnumberTotal number of steps

TourState

Persisted state for a tour, provided via the onStateChange callback.

PropertyTypeDescription
status'idle' | 'active' | 'completed'Current lifecycle status
currentStepIndexnumberIndex of the current step (when active)
seenStepsnumber[]Indices of steps the user has seen
completedAtnumber | undefinedTimestamp when the tour was completed
skippedAt{ stepIndex: number; timestamp: number } | undefinedStep index and timestamp when the tour was skipped

SpotlightTheme

Full theme interface. See the Customization page for usage examples.

SectionProperties
overlaybackground: string
tooltipbackground: string, color: string, borderRadius: string, boxShadow: string, padding: string, maxWidth: string
titlefontSize: string, fontWeight: string, color: string, marginBottom: string
contentfontSize: string, color: string, lineHeight: string
buttonbackground: string, color: string, borderRadius: string, padding: string, fontSize: string, fontWeight: string, border: string, cursor: string, hoverBackground: string
buttonSecondarybackground: string, color: string, border: string, hoverBackground: string
progressbackground: string, fill: string, height: string, borderRadius: string
arrowfill: string
closeButtoncolor: string, hoverColor: string