HomeBytesheetsUI TemplatesUI ToolsRoad MapsStack DiscussionByte Camp
BytesUIv0.5.3
⌘K

Tour

Context-aware step-by-step walkthroughs with route sync, target highlights, and custom overlays.

Interactive Demo

Preview tour triggers and test step interactions across routes.

1. Setup Provider in Main Component (App.jsx)

Wrap your routes with `ToursProvider` using React Router's `useLocation` hook for route tracking.

import { BrowserRouter, useLocation, useNavigate } from 'react-router-dom';
import { ToursProvider } from '@bytesui/react';
import { Guides } from './guides';

function AppRoutes({ children }) {
  const location = useLocation();
  const navigate = useNavigate();

  const currentPath = location.pathname + location.search;

  return (
    <ToursProvider
      currentRoutePath={currentPath}
      guides={Guides}
      onNavigate={(path) => navigate(path)}
      onTourComplete={(tourName) => console.log('Tour Complete:', tourName)}
    >
      {children}
    </ToursProvider>
  );
}

2. Render Overlay & Control Tour via Hook

Use `useTour` within child components wrapped by `ToursProvider` to trigger tours and custom completion overlays.

import { useEffect } from 'react';
import { TourOverlay, useTour } from '@bytesui/react';

export default function Page() {
  const tour = useTour();

  useEffect(() => {
    tour.initializeTour('portfolio');
    tour.setCompletionOverlayDuration(5000);
    tour.setCompletionOverlay(
      <div className="celebration-overlay">🎉 Congratulations! Tour Completed.</div>
    );
  }, []);

  return (
    <>
      <div>Page Content</div>
      <TourOverlay />
    </>
  );
}

Overlay Color & Variant

`TourOverlay` is a themed component. Pass `color` (any of the 8 semantic colors) and `variant` (`solid` | `outlined` | `soft` | `plain`) to match the overlay's highlight ring, card background, and action button color to your brand. Defaults to `color="primary"` and `variant="outlined"`.

import { TourOverlay } from '@bytesui/react';

export default function Page() {
  return (
    <>
      <div>Page Content</div>
      <TourOverlay color="secondary" variant="solid" />
    </>
  );
}

Overlay Slot Styling

For deeper customization, pass a `style` prop keyed by `Bui.*` slot names. Slot styles are merged on top of the resolved theme colors and always take precedence.

import { TourOverlay } from '@bytesui/react';

export default function Page() {
  return (
    <>
      <div>Page Content</div>
      <TourOverlay
        color="info"
        variant="soft"
        style={{
          'Bui.cardBox': { borderRadius: '16px', padding: '20px' },
          'Bui.image': { height: '70%' },
          'Bui.actionButton': { fontWeight: 700, textDecoration: 'underline' },
          'Bui.cancelButton': { opacity: 0.6 }
        }}
      />
    </>
  );
}

Default Avatar

ToursProvider's `avatar` prop is optional. If you don't pass one, BytesUI automatically uses a bundled illustrated avatar shipped inside the package — no extra asset setup required. Pass your own image URL or import to override it.

import { ToursProvider } from '@bytesui/react';

// Uses the built-in default avatar automatically
<ToursProvider currentRoutePath={path} guides={Guides}>
  {children}
</ToursProvider>

// Or provide your own avatar image
<ToursProvider currentRoutePath={path} guides={Guides} avatar="/images/guide-avatar.png">
  {children}
</ToursProvider>

3. Guides Schema Definition

Define steps, target CSS selectors, route gates, and navigation actions.

export const Guides = {
  portfolio: {
    name: 'portfolio',
    steps: [
      {
        message: "Hey! Let's build a portfolio that enhances your landing chances.",
        action: '/profile',
        showOnPage: '/',
        showAction: true,
        actionLabel: 'Yes',
        showCancel: true,
        cancelLabel: 'Later',
        modal: true,
        targetSelector: ''
      },
      {
        message: "Please complete required fields and open 'My Account'.",
        showOnPage: '/profile',
        actionLabel: 'Got it',
        showAction: true,
        modal: true,
        targetSelector: "[data-tour-target='tour-navbar-my-account']"
      }
    ]
  }
};

ToursProvider API

PropTypeDefaultDescription
currentRoutePathstringrequiredActive page path used to match step showOnPage routes.
guidesRecord<string, Guide>{}Object containing step configurations grouped by tour key.
avatarstringbundled default avatarAvatar image URL or path displayed inside tour speech bubbles. If omitted, BytesUI automatically uses its bundled default illustrated avatar.
customRouteCompare(showOnPage?: string) => booleanundefinedOptional custom matcher used when route comparison differs from a direct pathname equality check.
onNavigate(path: string) => voidundefinedCallback triggered when a step requests programmatic route navigation.
onTourComplete(tourName: string) => voidundefinedTriggered after user completes the final step of a tour.

useTour Hook Methods

MethodParametersDescription
initializeTour(tourKey: string) => voidStarts a registered guide from its initial step.
setCompletionOverlay(node: ReactNode) => voidSets custom JSX element to display upon tour completion.
setCompletionOverlayDuration(ms: number) => voidDefines duration in milliseconds before auto-hiding the completion overlay.

TourOverlay Props

PropTypeDefaultDescription
color'primary' | 'secondary' | 'tertiary' | 'success' | 'warning' | 'error' | 'neutral' | 'info'"primary"Semantic color used for the target highlight ring, card background tint, and action button.
variant'solid' | 'outlined' | 'soft' | 'plain'"outlined"Visual style variant used to resolve the overlay's color tokens.
styleTourOverlaySlotStyleundefinedSlot-based style overrides keyed by `Bui.*` slot names. See the slots reference below.

TourOverlay Style Slots

SlotDescription
Bui.rootFull-screen overlay/backdrop container.
Bui.cardPositioned card wrapper containing the avatar and message box.
Bui.cardBoxMessage bubble background, padding, and shadow.
Bui.imageAvatar `<img>` element.
Bui.messageStep message text (`<p>`).
Bui.actionsWrapper around the action and cancel buttons.
Bui.actionButtonPrimary action button (e.g. 'Next').
Bui.cancelButtonSecondary/cancel button (e.g. 'Skip').