• Stars
    star
    196
  • Rank 191,516 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated 6 months ago

Reviews

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

Repository Details

An Angular wrapper for the site tour library Shepherd

angular-shepherd

Ship Shape

angular-shepherd is built and maintained by Ship Shape. Contact us for web app consulting, development, and training for your project.

npm version Download count all time npm CI Build

This is an Angular wrapper for the Shepherd, site tour, library. It provides additional functionality, on top of Shepherd, as well.

Compatibility

  • Angular 8: 0.5.0
  • Angular 9: 0.6.0
  • Angular 10: 0.7.0
  • Angular 11: 11.x
  • Angular 12: 12.x
  • Angular 13: 13.x
  • Angular 14: 14.x
  • Angular 15: 15.x

This has not been tested in anything but Angular 8+. It may or may not work in previous versions or subsequent versions of Angular. We would love to support multiple versions, if people with more Angular knowledge would be willing to help us out!

Installation

npm install angular-shepherd --save

Usage

NOTE: This may not be the proper Angular way to do everything, as I am not an Angular dev, so please let me know if you have suggestions!

Shepherd ships a single style file, which you will need to include. You can do so by adding it to your angular.json.

  "styles": [
     "node_modules/shepherd.js/dist/css/shepherd.css"
  ],

Then, you will need to inject the ShepherdService to be able to interact with Shepherd and call addSteps to add your steps, start to start the tour, etc.

You could either do this at the application level, in your application component or on a per component or per route/view basis.

NOTE: It is highly recommended to inject ShepherdService into your app.component.ts. Injecting it at the app level ensures you only create one instance of Shepherd.

In that component you will want to use AfterViewInit to addSteps to the Shepherd service.

import { Component, AfterViewInit } from '@angular/core';
import { ShepherdService } from 'angular-shepherd';
import { steps as defaultSteps, defaultStepOptions} from '../data';

@Component({
  selector: 'shepherd',
  templateUrl: './shepherd.component.html',
  styleUrls: ['./shepherd.component.css']
})
export class ShepherdComponent implements AfterViewInit {

  constructor(private shepherdService: ShepherdService) { }

  ngAfterViewInit() {
    this.shepherdService.defaultStepOptions = defaultStepOptions;
    this.shepherdService.modal = true;
    this.shepherdService.confirmCancel = false;
    this.shepherdService.addSteps(defaultSteps);
    this.shepherdService.start();
  }
}

Configuration

The following configuration options can be set on the ShepherdService to control the way that Shepherd is used. The only required option is steps, which is set via addSteps.

confirmCancel

confirmCancel is a boolean flag, when set to true it will pop up a native browser confirm window on cancel, to ensure you want to cancel.

confirmCancelMessage

confirmCancelMessage is a string to display in the confirm dialog when confirmCancel is set to true.

defaultStepOptions

defaultStepOptions is used to set the options that will be applied to each step by default. You can pass in any of the options that you can with Shepherd.

โš ๏ธ You must set defaultStepOptions BEFORE calling addSteps to set the steps.

It will be an object of a form something like:

this.shepherdService.defaultStepOptions = {
  classes: 'custom-class-name-1 custom-class-name-2',
  scrollTo: false,
  cancelIcon: {
    enabled: true
  }
};

default value: {}

requiredElements

requiredElements is an array of objects that indicate DOM elements that are REQUIRED by your tour and must exist and be visible for the tour to start. If any elements are not present, it will keep the tour from starting.

You can also specify a message, which will tell the user what they need to do to make the tour work.

โš ๏ธ You must set requiredElements BEFORE calling addSteps to set the steps.

Example

this.shepherdService.requiredElements = [
  {
    selector: '.search-result-element',
    message: 'No search results found. Please execute another search, and try to start the tour again.',
    title: 'No results'
  },
  {
    selector: '.username-element',
    message: 'User not logged in, please log in to start this tour.',
    title: 'Please login'
  },
];

default value: []

modal

modal is a boolean, that should be set to true, if you would like the rest of the screen, other than the current element, greyed out, and the current element highlighted. If you do not need modal functionality, you can remove this option or set it to false.

default value: false

addSteps

You must pass an array of steps to addSteps, something like this:

this.shepherdService.addSteps([
  {
    id: 'intro',
    attachTo: { 
      element: '.first-element', 
      on: 'bottom'
    },
    beforeShowPromise: function() {
      return new Promise(function(resolve) {
        setTimeout(function() {
          window.scrollTo(0, 0);
          resolve();
        }, 500);
      });
    },
    buttons: [
      {
        classes: 'shepherd-button-secondary',
        text: 'Exit',
        type: 'cancel'
      },
      {
        classes: 'shepherd-button-primary',
        text: 'Back',
        type: 'back'
      },
      {
        classes: 'shepherd-button-primary',
        text: 'Next',
        type: 'next'
      }
    ],
    cancelIcon: {
      enabled: true
    },
    classes: 'custom-class-name-1 custom-class-name-2',
    highlightClass: 'highlight',
    scrollTo: false,
    title: 'Welcome to Angular-Shepherd!',
    text: ['Angular-Shepherd is a JavaScript library for guiding users through your Angular app.'],
    when: {
      show: () => {
        console.log('show step');
      },
      hide: () => {
        console.log('hide step');
      }
    }
  },
  ...
]);

Buttons

In Shepherd, you can have as many buttons as you want inside a step. You can build an object with some premade buttons, making it easier to manipulate and insert in new steps. Buttons by default accept three different types: back, cancel, next. In this simple example, we have three buttons: each one with different types and classes.

const builtInButtons = {
  cancel: {
    classes: "cancel-button",
    text: "Cancel",
    type: "cancel"
  },
  next: {
    classes: "next-button",
    text: "Next",
    type: "next"
  },
  back: {
    classes: "back-button",
    secondary: true,
    text: "Back",
    type: "back"
  }
};

Buttons have an action property, which must be a function. Whenever the button is clicked, the function will be executed. You can use it for default shepherd functions, like this.shepherdService.complete() or this.shepherdService.next(), or create your own function to use for the action.

const builtInButtons = {
  complete: {
    classes: "complete-button",
    text: "Finish Tutorial",
    action: function() {
      return console.log('button clicked');
    }
  }
};

โš ๏ธ You can't set up a type and an action at the same time inside a button.

To learn more about button properties, look at the documentation.

Step Options

See the Step docs for all available Step options.

More Repositories

1

shepherd

Guide your users through a tour of your app
JavaScript
11,579
star
2

tether

A positioning engine to make overlays, tooltips and dropdowns better
JavaScript
8,493
star
3

react-shepherd

A React wrapper for the site tour library Shepherd
CSS
549
star
4

vue-shepherd

A Vue wrapper for the site tour library Shepherd
Vue
260
star
5

ember-cli-release

Ember CLI addon for versioned release management
JavaScript
90
star
6

swach

A robust color management tool for the modern age
TypeScript
46
star
7

ember-prism

Easy ember components for syntax highlighting a-la PrismJS
JavaScript
34
star
8

ember-cli-capacitor

Add Capacitor to your Ember app.
JavaScript
28
star
9

ember-x-editable

X-editable like library for Ember
JavaScript
22
star
10

ember-3d-nav

A 3d rotating top navigation bar for Ember apps
JavaScript
22
star
11

website-ember

The code for shipshape.io
JavaScript
20
star
12

website-nuxt

Nuxt port of shipshape.io
Vue
16
star
13

ember-cli-netlify

Ember addon to configure Netlify headers and redirects
JavaScript
14
star
14

ember-drop

An Ember addon that wraps Drop.js
JavaScript
11
star
15

prember-sitemap-generator

A sitemap generator for prember apps
JavaScript
6
star
16

ember-service-worker-prember

An Ember Service Worker plugin that caches the index.html files for each prember route
JavaScript
6
star
17

website-astro

The code for the current Ship Shape website
Astro
5
star
18

ember-3d-folding-panel

An Ember addon for 3d folding panels
JavaScript
5
star
19

ember-performance-workshop

The code for the EmberConf 2018 Performance Workshop
HTML
4
star
20

ember-newton-cradle-loader

Ember addon for showing a newton cradle loading animation
JavaScript
4
star
21

ember-headroom

Ember addon to include headroom.js as an ES2015 module in your app
JavaScript
4
star
22

ember-async-await-for-each

async/await aware forEach for Ember
JavaScript
4
star
23

prember-rss-feed

Ship RSS feeds for your Prember site
JavaScript
3
star
24

ember-assign-polyfill

A polyfill for Ember.assign in <= 2.4
JavaScript
2
star
25

ember-journal

A blogging engine for Ember apps
JavaScript
2
star
26

ember-isometric-grids

JavaScript
2
star
27

bootcamp-loader

TypeScript
1
star
28

1787-astro

Astro
1
star
29

ember-debonair

Get your Ember code in ship shape
JavaScript
1
star
30

ember-showdown-highlight

JavaScript
1
star
31

glimmer-context-menu

TypeScript
1
star
32

www-website

whiskeywebandwhatnot.fm
JavaScript
1
star