react-shepherd 4.2.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +166 -0
- package/dist/Shepherd.es.js +11 -1
- package/dist/Shepherd.es.js.map +1 -1
- package/dist/Shepherd.js +11 -0
- package/dist/Shepherd.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/package.json +5 -5
- package/dist/index.d.ts.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# react-shepherd
|
|
2
|
+
|
|
3
|
+
<div>
|
|
4
|
+
<a href="https://shipshape.io">
|
|
5
|
+
<img align="left" src="http://i.imgur.com/DWHQjA5.png" alt="Ship Shape" width="50" height="50"/>
|
|
6
|
+
</a>
|
|
7
|
+
|
|
8
|
+
**[react-shepherd is built and maintained by Ship Shape. Contact us for web app consulting, development, and training for your project](https://shipshape.io/)**.
|
|
9
|
+
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
[](https://www.npmjs.com/package/react-shepherd)
|
|
13
|
+
[](https://github.com/shipshapecode/react-shepherd/actions?query=workflow%3ATest)
|
|
14
|
+
[](https://codeclimate.com/github/shipshapecode/react-shepherd/maintainability)
|
|
15
|
+
[](https://codeclimate.com/github/shipshapecode/react-shepherd/test_coverage)
|
|
16
|
+
[](https://standardjs.com)
|
|
17
|
+
|
|
18
|
+
This is a React wrapper for the [Shepherd](https://github.com/shipshapecode/shepherd), site tour, library.
|
|
19
|
+
It's mainly a wrapper around the Shepherd library that exposes the tour object and methods to the context object
|
|
20
|
+
that can be passed into props for dynamic interactivity.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install --save react-shepherd
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Via Provider/Context
|
|
31
|
+
|
|
32
|
+
```jsx
|
|
33
|
+
import React, { Component, useContext } from "react";
|
|
34
|
+
import { ShepherdTour, ShepherdTourContext } from "react-shepherd";
|
|
35
|
+
import newSteps from "./steps";
|
|
36
|
+
|
|
37
|
+
const tourOptions = {
|
|
38
|
+
defaultStepOptions: {
|
|
39
|
+
cancelIcon: {
|
|
40
|
+
enabled: true,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
useModalOverlay: true,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function Button() {
|
|
47
|
+
const tour = useContext(ShepherdTourContext);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<button className="button dark" onClick={tour.start}>
|
|
51
|
+
Start Tour
|
|
52
|
+
</button>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default function App() {
|
|
57
|
+
return (
|
|
58
|
+
<div>
|
|
59
|
+
<ShepherdTour steps={newSteps} tourOptions={tourOptions}>
|
|
60
|
+
<Button />
|
|
61
|
+
</ShepherdTour>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Via Hook
|
|
68
|
+
|
|
69
|
+
```jsx
|
|
70
|
+
import React, { Component } from "react";
|
|
71
|
+
import { useShepherdTour } from "react-shepherd";
|
|
72
|
+
import newSteps from "./steps";
|
|
73
|
+
|
|
74
|
+
const tourOptions = {
|
|
75
|
+
defaultStepOptions: {
|
|
76
|
+
cancelIcon: {
|
|
77
|
+
enabled: true,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
useModalOverlay: true,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default function App() {
|
|
84
|
+
const tour = useShepherdTour({ tourOptions, steps: newSteps });
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<button class="button dark" onClick={tour.start}>
|
|
88
|
+
Start Tour
|
|
89
|
+
</button>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Configuration
|
|
95
|
+
|
|
96
|
+
The following configuration options for a tour can be set on the ShepherdTour to control the way that Shepherd is used. This is simply a POJO passed to Shepherd to use the options noted in the Shepherd Tour [options](https://shepherdjs.dev/docs/Tour.html).
|
|
97
|
+
**The only required option is `steps`, which is an array passed to the props.**
|
|
98
|
+
|
|
99
|
+
### tourOptions
|
|
100
|
+
|
|
101
|
+
`PropTypes.object`
|
|
102
|
+
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.
|
|
103
|
+
|
|
104
|
+
### steps
|
|
105
|
+
|
|
106
|
+
`PropTypes.array`
|
|
107
|
+
You must pass an array of steps to `steps`, something like this:
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
const steps = [
|
|
111
|
+
{
|
|
112
|
+
id: 'intro',
|
|
113
|
+
attachTo: { element: '.first-element', on: 'bottom' },
|
|
114
|
+
beforeShowPromise: function () {
|
|
115
|
+
return new Promise(function (resolve) {
|
|
116
|
+
setTimeout(function () {
|
|
117
|
+
window.scrollTo(0, 0);
|
|
118
|
+
resolve();
|
|
119
|
+
}, 500);
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
buttons: [
|
|
123
|
+
{
|
|
124
|
+
classes: 'shepherd-button-secondary',
|
|
125
|
+
text: 'Exit',
|
|
126
|
+
type: 'cancel'
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
classes: 'shepherd-button-primary',
|
|
130
|
+
text: 'Back',
|
|
131
|
+
type: 'back'
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
classes: 'shepherd-button-primary',
|
|
135
|
+
text: 'Next',
|
|
136
|
+
type: 'next'
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
classes: 'custom-class-name-1 custom-class-name-2',
|
|
140
|
+
highlightClass: 'highlight',
|
|
141
|
+
scrollTo: false,
|
|
142
|
+
cancelIcon: {
|
|
143
|
+
enabled: true,
|
|
144
|
+
},
|
|
145
|
+
title: 'Welcome to React-Shepherd!',
|
|
146
|
+
text: ['React-Shepherd is a JavaScript library for guiding users through your React app.'],
|
|
147
|
+
when: {
|
|
148
|
+
show: () => {
|
|
149
|
+
console.log('show step');
|
|
150
|
+
},
|
|
151
|
+
hide: () => {
|
|
152
|
+
console.log('hide step');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
// ...
|
|
157
|
+
];
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Steps
|
|
161
|
+
|
|
162
|
+
The options are the same as Shepherd [options](https://shepherdjs.dev/docs/Step.html).
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
MIT
|
package/dist/Shepherd.es.js
CHANGED
|
@@ -4436,6 +4436,16 @@ var addSteps = function (steps, tour) {
|
|
|
4436
4436
|
});
|
|
4437
4437
|
return parsedStepsforAction.forEach(function (step) { return tour.addStep(step); });
|
|
4438
4438
|
};
|
|
4439
|
+
// for instances where Context can't be used or doesn't make sense
|
|
4440
|
+
var useShepherdTour = function (_a) {
|
|
4441
|
+
var tourOptions = _a.tourOptions, steps = _a.steps;
|
|
4442
|
+
var tourObject = useMemo(function () {
|
|
4443
|
+
var tourInstance = new Shepherd.Tour(tourOptions);
|
|
4444
|
+
addSteps(steps, tourInstance);
|
|
4445
|
+
return tourInstance;
|
|
4446
|
+
}, [tourOptions, steps]);
|
|
4447
|
+
return tourObject;
|
|
4448
|
+
};
|
|
4439
4449
|
var ShepherdTour = function (_a) {
|
|
4440
4450
|
var children = _a.children, tourOptions = _a.tourOptions, steps = _a.steps;
|
|
4441
4451
|
var tourObject = useMemo(function () {
|
|
@@ -4446,5 +4456,5 @@ var ShepherdTour = function (_a) {
|
|
|
4446
4456
|
return (React.createElement(ShepherdTourContext.Provider, { value: tourObject }, children));
|
|
4447
4457
|
};
|
|
4448
4458
|
|
|
4449
|
-
export { ShepherdTour, ShepherdTourContext, ShepherdTourContextConsumer as TourMethods };
|
|
4459
|
+
export { ShepherdTour, ShepherdTourContext, ShepherdTourContextConsumer as TourMethods, useShepherdTour };
|
|
4450
4460
|
//# sourceMappingURL=Shepherd.es.js.map
|