1.0.10 • Published 2 years ago

interactive-tutorial v1.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Interactive Tutorial

The interactive-tutorial plugin will allow for you to create an interactive tutorial on any page/app. It's easily configured and supports both highlighting areas and adding text in specific directions.

How it looks when you use it

How to use

First, install the package:

npm install --save interactive-tutorial

Now, given the following html:

<div data-id="tutorial-navigation">...</div>
<div data-id="tutorial-signup">...</div>
<div data-id="tutorial-information">...</div>
<div data-id="tutorial-footer">...</div>

Call the package like this:

import InteractiveTutorial from "interactive-tutorial";

InteractiveTutorial({
  options: [
    {
      elementSelector: '[data-id="tutorial-navigation"]',
      text: "This is the main navigation",
      preferredPosition: "bottom",
    },
    {
      elementSelector: '[data-id="tutorial-signup"]',
      text: "This is a signup with a <strong>robot check</strong>",
      preferredPosition: "right",
    },
    {
      elementSelector: '[data-id="tutorial-information"]',
      text: "This is some informative information",
      preferredPosition: "left",
    },
    {
      elementSelector: '[data-id="tutorial-footer"]',
      text: "This is a boring footer",
      preferredPosition: "top",
    },
  ],
  padding: 10,
  textOffsetX: 20,
  textOffsetY: 20,
});

You can use a template as well, if you need some, or all, of your textbox to follow a common design pattern. You declare you template as a general argument (called template) and then use the property templateArgs for the options that wants to use the template. In the example below you can see that an argument is described as {arg} in the template, or {arg?} if you want it to be optional. The arguments can be called anything as long as they are matched by the templateArgs.

Example using a template:

import InteractiveTutorial from "interactive-tutorial";

InteractiveTutorial({
  options: [
    {
      elementSelector: '[data-id="tutorial-footer-link1"]',
      text: "This is a small link",
      preferredPosition: "top",
    },
    {
      elementSelector: '[data-id="tutorial-footer-link2"]',
      preferredPosition: "top",
      templateArgs: { text: "This one uses a template." },
    },
    {
      elementSelector: '[data-id="tutorial-footer-link3"]',
      preferredPosition: "top",
      templateArgs: {
        text: "This one <b>also</b> uses a template.",
        optional: "This one also uses the optional argument.",
      },
  ],
  template: `<p>This is the general template!<p><br /><p>{text}</p><br /><p>It is sometimes useful.</p><br /><p><em>{optional?}</em></p>`,
});

Available options are:

Option nameTypeDescription
optionsobjectAn array of options, each describing an individual step of the tutorial. See the type definition below.
option.elementSelectorstringAny valid selector for the element to highlight/focus on.
option.textstring | undefinedThe text to show (optional).
option.preferredPosition"top" | "right" | "bottom" | "left" | undefinedIf you want to select where the text is going to show, select a preferred position.
option.paddingnumber | undefinedThe padding for this particular segment.
option.textOffsetXnumber | undefinedThe specific X offset for this particular text segment
option.textOffsetYnumber | undefinedThe specific Y offset for this particular text segment
options.templateArgsobject | undefinedArguments for the tmplate, if you are using it
paddingnumber | undefinedThe general padding of all tutorial areas.
textOffsetXnumber | undefinedThe general X offset for all text baloons.
textOffsetYnumber | undefinedThe general Y offset for all text baloons.
templatestring | undefinedA template that can be used for all, or some, textboxes.

And to style it using the available class selectors:

SelectorDescription
.interactive-tutorial-overlayThe main overlay ontop of which the tutorial is placed.
.interactive-tutorial-element-overlayThe overlay ontop of the currently showing section.
.interactive-tutorial-cloaking-rectangle-topThe top cloaking rectangle.
.interactive-tutorial-cloaking-rectangle-rightThe right cloaking rectangle.
.interactive-tutorial-cloaking-rectangle-bottomThe bottom cloaking rectangle.
.interactive-tutorial-cloaking-rectangle-leftThe left cloaking rectangle.
.interactive-tutorial-textThe text element.
.interactive-tutorial-text-topThe text element whenever it is positioned at the top.
.interactive-tutorial-text-rightThe text element whenever it is positioned at the right.
.interactive-tutorial-text-bottomThe text element whenever it is positioned at the bottom.
.interactive-tutorial-text-leftThe text element whenever it is positioned at the left.
.interactive-tutorial-text-top-rightThe text element whenever it is positioned above an element but starts from the right.
.interactive-tutorial-text-bottom-rightThe text element whenever it is positioned below an element but starts from the right.

There is a stylesheet available (which is used in the above demo) which you can import from inside the npm package.

import "./node_modules/interactive-tutorial/build/styles.css";

Working with the code

If you want to contribute or just play around with the code, just download or fork the repository.

To build the project, simply run:

npm install
npm run watch
// or
npm run build

To run the demo project to test your changes you must install the dependencies within the package.

cd demo/
npm install
npm start
1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago