useTour New

Um composable para criar tours guiados reancorando um único Popover ao longo das etapas.

Uso

Use o composable useTour, importado automaticamente, para conduzir um tour guiado com um único Popover cuja âncora se move entre as etapas. O composable controla o estado das etapas e resolve o target de cada etapa em uma reference que você vincula ao <NPopover>, enquanto você mantém controle total sobre o conteúdo e a navegação.

Dashboard

Overview of your workspace.

Profile

Manage your account.

Settings

Configure your preferences.

Cada etapa exige um target no qual o popover se ancora. Ele aceita um seletor CSS, um elemento, um elemento virtual (qualquer coisa com getBoundingClientRect) ou um ref/getter que retorne um deles. Passe null para ancorar a etapa no centro da viewport. Qualquer outro campo de uma etapa (title, body, side, …) é repassado sem alterações e fica disponível via current.

<script setup lang="ts">
const card = useTemplateRef('card')

const tour = useTour([
  { target: '#cta', title: 'Get started' },
  { target: () => card.value, title: 'Profile', side: 'right' },
  { target: null, title: 'All set' }
])
</script>

<template>
  <NButton @click="tour.start()">Start tour</NButton>

  <NPopover :open="tour.open.value" :reference="tour.reference.value" :dismissible="false">
    <template #content>
      <!-- your content + buttons -->
      <NButton :disabled="!tour.hasPrev.value" @click="tour.prev()">Back</NButton>
      <NButton @click="tour.next()">{{ tour.hasNext.value ? 'Next' : 'Finish' }}</NButton>
    </template>
  </NPopover>
</template>
  • Built on the Popover's reactive reference prop, so the popover smoothly repositions when the active step changes.
  • The active target is scrolled into view automatically when a step becomes active.
  • Since you render the content yourself, there is no extra theme or locale to maintain.

API

useTour(steps, options?)

Parâmetros

steps
MaybeRefOrGetter<TourStep[]> required
The list of tour steps. Can be a static array, a ref, or a getter for reactive steps.
options
UseTourOptions
Configuration options for the tour.

Retorno

open
Ref<boolean>
Whether the tour is currently open.
index
Ref<number>
The current step index, clamped to the steps range.
current
ComputedRef<TourStep | undefined>
The current step object, or undefined when there are no steps.
reference
ComputedRef<ReferenceElement | undefined>
The resolved anchor for the current step, to pass to <NPopover :reference>.
total
ComputedRef<number>
The total number of steps.
hasNext
ComputedRef<boolean>
Whether a next step exists.
hasPrev
ComputedRef<boolean>
Whether a previous step exists.
start
(index?: number) => void
Open the tour, optionally at a given index.
next
() => void
Go to the next step. Loops or finishes at the end depending on the loop option.
prev
() => void
Go to the previous step.
goTo
(index: number) => void
Jump to a specific step and open the tour.
finish
() => void
Close the tour.