Intro.js React Wrapper

1.0.0 · active · verified Sun Apr 19

intro.js-react is a lightweight and actively maintained React wrapper for the Intro.js library, designed to simplify the creation of step-by-step product tours and hints within React applications. Currently at version 1.0.0, this package provides two primary components: `Steps` for guided tours and `Hints` for contextual popovers. It abstracts away direct Intro.js imperative API calls, allowing developers to manage tours declaratively using React props for configuration, steps, and lifecycle callbacks. Key differentiators include its adherence to React's component model, handling Intro.js instance management, and providing a more idiomatic React experience compared to integrating Intro.js directly. While it requires `intro.js` and `react` as peer dependencies, it handles the synchronization between React state and the underlying Intro.js instance, offering callbacks for various tour events like `onStart`, `onChange`, and `onComplete`. The package also supports Intro.js options directly through a dedicated `options` prop.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to integrate `intro.js-react` to create a guided product tour using the `Steps` component, including state management for enabling/disabling the tour and defining tour steps with CSS selectors.

import React, { useState } from 'react';
import { Steps } from 'intro.js-react';
import 'intro.js/introjs.css'; // Don't forget to import Intro.js CSS

// Simulate some elements for the tour
const MyComponent = () => {
  const [stepsEnabled, setStepsEnabled] = useState(true);
  const [initialStep, setInitialStep] = useState(0);

  const steps = [
    {
      element: '.step-one-selector', // Make sure this selector exists in your DOM
      intro: 'This is the first step of our tour!',
      position: 'right',
    },
    {
      element: '.step-two-selector',
      intro: 'And here is the second important element.',
    },
    {
      element: '.step-three-selector',
      intro: 'Finally, this is the last piece of information.',
      position: 'bottom',
    },
  ];

  const onExit = () => {
    setStepsEnabled(false);
    setInitialStep(0); // Reset for next time
  };

  return (
    <div>
      <h1 className="step-one-selector">Welcome to My App</h1>
      <p className="step-two-selector">This is some content.</p>
      <button className="step-three-selector" onClick={() => setStepsEnabled(true)}>
        Start Tour
      </button>

      <Steps
        enabled={stepsEnabled}
        steps={steps}
        initialStep={initialStep}
        onExit={onExit}
        // You can also pass Intro.js options directly
        options={{
          showButtons: true,
          showStepNumbers: false,
          exitOnOverlayClick: false,
        }}
      />
    </div>
  );
};

export default MyComponent;

view raw JSON →