Quick Example

useTour Usage

ตัวอย่าง import และการใช้งานแบบสั้นสำหรับหน้า `use-tour`

Code

                <script lang="ts">
 import { useTour, Tour, type TourStep } from 'svelora';
 import { goto } from '$app/navigation';

 const steps: TourStep[] = [
   { id: 'home', route: '/', target: '#hero', title: 'Welcome' },
   { id: 'settings', route: '/settings', target: '#prefs', title: 'Settings' }
 ];

 const tour = useTour({
   steps,
   persist: true,
   onStepChange: (index) => {
     const route = steps[index]?.route;
     if (route) goto(route);
   }
 });
</script>

<Button onclick={() => tour.start()}>Start tour</Button>
<Tour {steps} controller={tour} />
            

useTour

Headless controller สำหรับ Tour — เก็บ state แบบ reactive โดยไม่ render UI เอง เหมาะกับ multi-page tour เมื่อใช้ร่วมกับ persist และนำทาง route ใน onStepChange

ดูตัวอย่าง multi-page เต็มรูปแบบที่ /tour/multi

Interactive demo

Hero target — ขั้นตอนแรกจะ spotlight ตรงนี้
Closed Step 0

Options

NameTypeDescription
stepsTourStep[]Tour step definitions shared with <Tour />.
defaultStepnumberInitial step index. Default: 0.
persistboolean | TourPersistOptionsResume in-progress tours across reloads.
onStart() => voidCalled when the tour opens.
onComplete() => voidCalled when the last step finishes.
onSkip() => voidCalled when the user dismisses the tour.
onStepChange(index: number) => voidCalled after the active step changes.

Controller API

NameTypeDescription
isActivebooleanWhether the tour is active.
currentIndexnumberCurrent step index.
currentStepDataTourStep | undefinedCurrent step object.
start()() => voidOpen the tour at the first enabled step.
stop()() => voidClose the tour and clear persisted state.
next()() => Promise<void>Advance, honoring onBeforeNext guards.
prev()() => Promise<void>Go back, honoring onBeforePrev guards.
goTo(step)(number | string) => Promise<void>Jump to a step by index or id.