• Stars
    star
    152
  • Rank 244,685 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A ReactJS mixin to give new users a popup-based tour of your application.

react-tour-guide npm version

A ReactJS mixin to give new users a popup-based tour of your application. An example can be seen here.


Getting Started

  1. npm install --save react-tour-guide
  2. var TourGuideMixin = require('react-tour-guide').Mixin
var TourGuideMixin = require('react-tour-guide').Mixin;
var tour = {
  startIndex: 0,
  scrollToSteps: true,
  steps: [
    {
      text: 'This is the first step in the tour.',
      element: 'header',
      position: 'bottom',
      closeButtonText: 'Next'
    },
    {
      text: 'This is the second step in the tour.',
      element: '.navigation',
      position: 'right'
    }
  ]
};
var cb = function() {
  console.log('User has completed tour!');
};

var App = React.createClass({

  mixins: [TourGuideMixin(tour, cb)],

  ...

});

If you're going to initialize the mixin without steps and add them later asynchronously, set your startIndex to a negative value

...
startIndex: -1,
steps: []
...

Options

A Javascript object is passed to the TourGuideMixin to specify options, as well as the steps of your tour as an array (there is also a method to define these asynchronously, discussed below). The options are:

  • startIndex (int): the index from which to begin the steps of the tour. This can be retrieved and saved via getUserTourProgress (discussed below), in order to be specified when a user returns. Defaults to 0.
  • scrollToSteps (bool): if true, the page will be automatically scrolled to the next indicator (if one exists) after a tooltip is dismissed. Defaults to true.
  • steps (array): the array of steps to be included in your tour. Defaults to an empty array.

Each "step" in the array represents one indicator and tooltip that a user must click through in the guided tour. A step has the following structure:

{
  "text": "The helpful tip or information the user should read at this step.",
  "element": "A jQuery selector for the element which the step relates to.",
  "position": "Where to position the indicator in relation to the element.",
  "closeButtonText": "An optional string to be used as the text for the tooltip close button."
}

Positions can be chosen from: top-left, top-right, right, bottom-right, bottom, bottom-left, left, and center. This defaults to center.


Completion Callback

An optional callback may be passed as the second parameter to TourGuideMixin, which will be called once the current user has completed all the steps of your tour.


Methods

setTourSteps(steps, cb)

This function is intended to provide you with a method to asynchronously define your steps (if they need to be fetched from a database, etc.) It takes a list of steps (of the form discussed earlier), along with an optional callback function as parameters. This will completely overwrite any existing steps or progress. Once the state is updated, the callback function will be invoked.

getUserTourProgress()

Upon including the mixin, this will be available to your component. At any point, this method can be called to retrieve information about the current user's progress through the guided tour. The object returned looks like this:

{
  "index": 2,
  "percentageComplete": 50,
  "step": {
    "text": "...",
    "element": "...",
    "position": "..."
  }
}

This information can be used to save a user's progress upon navigation from the page or application, allowing you to return them back to their correct spot when they visit next using the startIndex option (discussed above).


Styling

Some basic styling is provided in /dist/css/tour-guide.css. This can either be included directly in your project, or used as a base for your own custom styles. Below, the HTML structure of the tour is also outlined for custom styling.

The guided tour consists of two main elements for each step: an indicator and a tooltip. An indicator is a flashing element positioned on a specific element on the page, cueing the user to click. Upon click, the associated tooltip is triggered which the user must then read and dismiss.

Note: Elements are dynamically positioned by initially setting their top and left CSS properties to -1000px. Once they have been initially rendered and measured, they are then positioned correctly. Animations on these CSS properties should be avoided.

Indicator
<div class="tour-indicator"></div>
Tooltip
<div>
  <div class="tour-backdrop"></div>
  <div class="tour-tooltip">
    <p>{The step's text goes here.}</p>
    <div class="tour-btn close">Close</div>
  </div>
</div>

More Repositories

1

angularjs-gulp-browserify-boilerplate

Boilerplate using AngularJS, SASS, Gulp, and Browserify and utilizing best practices.
JavaScript
1,033
star
2

react-rocket-boilerplate

A boilerplate written in ES6 using ReactJS (along with React Router and RefluxJS), SASS, Gulp, and Browserify.
JavaScript
361
star
3

neural-network-stock-predictor

Semester project for COS 470 (Artifical Intelligence) at the University of Maine.
Python
88
star
4

expressed-boilerplate

A boilerplate for quickly building APIs on node.js and Express.
JavaScript
59
star
5

node-soundcloud

node.js wrapper for the Soundcloud SDK
JavaScript
32
star
6

grunt-requirejs-angularjs-sass-boilerplate

A boilerplate for Grunt, RequireJS, AngularJS, and SASS.
CSS
25
star
7

node-bandcamp

node.js (unofficial) Bandcamp API.
JavaScript
16
star
8

react-native-diff-view

A React Native module for parsing and displaying git diffs.
TypeScript
15
star
9

react-annotator

A React mixin to allow for user annotations directly on images.
JavaScript
14
star
10

acadeME

interactive eLearning platform for University of Maine senior capstone project
JavaScript
12
star
11

reddit-tumblr-bot

a Reddit-to-Tumblr bot in Python
Python
9
star
12

assemble-static-boilerplate

A boilerplate using Assemble and Gulp to quickly and efficiently create static websites.
JavaScript
5
star
13

playback-queue

A fully-featured and generic playback queue for music objects including history, shuffle, and repeat.
JavaScript
5
star
14

mono-ts-starter

A boilerplate for starting and publishing a TypeScript npm module.
JavaScript
2
star
15

ebs-setup

Custom build hooks and configuration for Elastic Beanstalk.
Shell
2
star
16

golang-api

A basic API in Go.
Go
1
star
17

craigslist.js

A Javascript API wrapper for craigslist.org.
JavaScript
1
star
18

gulp-git-status

A Gulp plugin for selectively including source files based on their Git status.
JavaScript
1
star
19

coyote-moves

Internal web app to visually search for fellow employees and initiate desk moves.
JavaScript
1
star
20

downloadr

A simple file-sharing web app built on the MEAN stack.
JavaScript
1
star
21

Gifft

A React-Native iOS app for managing upcoming occasions with reminders and gift ideas.
JavaScript
1
star
22

monolist-music-web

The web application for the now-defunct music app Monolist.
JavaScript
1
star
23

monolist-music-api

node.js server and Express API for the now-defunct music app Monolist.
JavaScript
1
star
24

jakemmarsh.github.io

source for my personal website, hosted on Github Pages
CSS
1
star
25

nftea

A simple dapp for minting NFTs on IPFS.
TypeScript
1
star