Skip to content

Commit 6c62d30

Browse files
fm96-devFederico MameliRobbieTheWagner
authored
Vue 3 Support (#99)
* feat: add support for vue 3 * docs: add vue 3 and composition API usage * feat: add vue 3 support Drop vue 2 support * fix: yarn.lock file * feat: add support for vue 3 * docs: add vue 3 and composition API usage * feat: add vue 3 support Drop vue 2 support * Format some things * Update dist * Update cypress config Co-authored-by: Federico Mameli <[email protected]> Co-authored-by: Robert Wagner <[email protected]>
1 parent f6d3e5a commit 6c62d30

File tree

17 files changed

+1379
-7177
lines changed

17 files changed

+1379
-7177
lines changed

.eslintrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"parser": "vue-eslint-parser",
6+
"parserOptions": {
7+
"parser": "babel-eslint",
8+
"ecmaVersion": 2020,
9+
"sourceType": "module"
10+
},
11+
"extends": [
12+
"plugin:vue/vue3-essential",
13+
"eslint:recommended"
14+
],
15+
"rules": {
16+
"vue/multi-word-component-names": "off"
17+
},
18+
"root": true
19+
}

README.md

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,63 +13,95 @@
1313

1414
This is a Vue wrapper for the [Shepherd](https://github.com/shipshapecode/shepherd), site tour, library.
1515

16-
## Installation
17-
18-
### NPM
19-
2016
```bash
2117
npm install vue-shepherd --save
2218
```
2319

24-
When using with a module system, you must explicitly install vue-shepherd via Vue.use():
20+
## Usage
2521

26-
```js
27-
import Vue from 'vue';
28-
import VueShepherd from 'vue-shepherd';
22+
### Composition API (suggested)
2923

30-
Vue.use(VueShepherd);
31-
```
24+
```vue
25+
<template>
26+
<div ref="el">
27+
Testing
28+
</div>
29+
</template>
3230
33-
## Usage
31+
<script setup>
32+
import { ref, onMounted } from 'vue'
33+
import { useShepherd } from 'vue-shepherd'
34+
35+
const el = ref(null);
3436
35-
You will need to import the styles first:
37+
const tour = useShepherd({
38+
useModalOverlay: true
39+
});
40+
41+
onMounted(() => {
42+
tour.addStep({
43+
attachTo: { element: el.value, on: 'top' },
44+
text: 'Test'
45+
});
3646
37-
```css
38-
@import '~shepherd.js/dist/css/shepherd.css';
47+
tour.start();
48+
});
49+
</script>
3950
```
4051

41-
The plugin extends Vue with a set of directives and $shepherd() constructor function.
52+
### Option API
4253

43-
### Constructor Function
54+
To use vue-shepherd with Option API you have to install the plugin which will add the '$shepherd' function to your vue app.
55+
56+
```js
57+
import { createApp } from 'vue';
58+
import VueShepherdPlugin from 'vue-shepherd';
59+
import '~shepherd.js/dist/css/shepherd.css';
60+
61+
createApp().use(VueShepherdPlugin).mount('#app');
62+
```
4463

4564
```vue
4665
<template>
47-
<div>
66+
<div ref="el">
4867
Testing
4968
</div>
5069
</template>
5170
5271
<script>
53-
export default {
54-
name: 'ShepherdExample',
55-
mounted() {
56-
this.$nextTick(() => {
57-
const tour = this.$shepherd({
72+
import { defineComponent } from 'vue'
73+
74+
export default defineComponent({
75+
data(){
76+
return {
77+
tour: null
78+
}
79+
},
80+
81+
methods: {
82+
createTour(){
83+
this.tour = this.$shepherd({
5884
useModalOverlay: true
5985
});
6086
61-
tour.addStep({
62-
attachTo: { element: this.$el, on: 'top' },
87+
this.tour.addStep({
88+
attachTo: { element: this.$refs.el, on: 'top' },
6389
text: 'Test'
6490
});
91+
}
92+
},
93+
94+
created(){
95+
this.createTour();
96+
},
6597
66-
tour.start();
67-
});
98+
mounted(){
99+
this.tour.start();
68100
}
69-
};
101+
});
70102
</script>
71103
```
72104

73-
### Directives
105+
## Directives
74106

75107
WIP

cypress.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { defineConfig } = require('cypress')
2+
3+
module.exports = defineConfig({
4+
fixturesFolder: 'tests/e2e/fixtures',
5+
screenshotsFolder: 'tests/e2e/screenshots',
6+
videosFolder: 'tests/e2e/videos',
7+
e2e: {
8+
// We've imported your old cypress plugins here.
9+
// You may want to clean this up later by importing these.
10+
setupNodeEvents(on, config) {
11+
return require('./tests/e2e/plugins/index.js')(on, config)
12+
},
13+
specPattern: 'tests/e2e/specs/**/*.cy.{js,jsx,ts,tsx}',
14+
supportFile: 'tests/e2e/support/index.js',
15+
},
16+
})

cypress.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

dev/components/ShepherdExample.vue

Lines changed: 73 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
1+
<script setup>
2+
import { ref, onMounted } from 'vue';
3+
import { useShepherd } from '@/entry.js';
4+
5+
const installElement = ref(null);
6+
const usageElement = ref(null);
7+
8+
const tour = useShepherd({
9+
useModalOverlay: true,
10+
});
11+
12+
const createTourSteps = () => {
13+
tour.addSteps([
14+
{
15+
attachTo: {
16+
element: installElement.value,
17+
on: 'top',
18+
},
19+
buttons: [
20+
{
21+
action: function () {
22+
return this.cancel();
23+
},
24+
secondary: true,
25+
text: 'Exit',
26+
},
27+
{
28+
action: function () {
29+
return this.next();
30+
},
31+
text: 'Next',
32+
},
33+
],
34+
text: 'Install test',
35+
},
36+
{
37+
attachTo: {
38+
element: usageElement.value,
39+
on: 'top',
40+
},
41+
buttons: [
42+
{
43+
action: function () {
44+
return this.back();
45+
},
46+
secondary: true,
47+
text: 'Back',
48+
},
49+
{
50+
action: function () {
51+
return this.next();
52+
},
53+
text: 'Next',
54+
},
55+
],
56+
text: 'Usage test',
57+
},
58+
]);
59+
60+
return tour;
61+
};
62+
63+
onMounted(() => {
64+
createTourSteps().start();
65+
});
66+
</script>
67+
168
<template>
269
<div class="page">
370
<div class="container">
@@ -9,11 +76,15 @@
976

1077
<h5>Installation</h5>
1178

12-
<div class="install-element">Install instructions go here</div>
79+
<div class="install-element" ref="installElement">
80+
Install instructions go here
81+
</div>
1382

1483
<h5>Usage</h5>
1584

16-
<div class="usage-element">Usage instructions go here</div>
85+
<div class="usage-element" ref="usageElement">
86+
Usage instructions go here
87+
</div>
1788

1889
<div class="medium-8 columns medium-centered text-center">
1990
<a
@@ -273,65 +344,3 @@
273344
</div>
274345
</div>
275346
</template>
276-
277-
<script>
278-
export default {
279-
name: 'ShepherdExample',
280-
mounted() {
281-
this.$nextTick(() => {
282-
const tour = this.$shepherd({
283-
useModalOverlay: true,
284-
});
285-
286-
tour.addSteps([
287-
{
288-
attachTo: {
289-
element: this.$el.querySelector('.install-element'),
290-
on: 'top',
291-
},
292-
buttons: [
293-
{
294-
action: function () {
295-
return this.cancel();
296-
},
297-
secondary: true,
298-
text: 'Exit',
299-
},
300-
{
301-
action: function () {
302-
return this.next();
303-
},
304-
text: 'Next',
305-
},
306-
],
307-
text: 'Install test',
308-
},
309-
{
310-
attachTo: {
311-
element: this.$el.querySelector('.usage-element'),
312-
on: 'top',
313-
},
314-
buttons: [
315-
{
316-
action: function () {
317-
return this.back();
318-
},
319-
secondary: true,
320-
text: 'Back',
321-
},
322-
{
323-
action: function () {
324-
return this.next();
325-
},
326-
text: 'Next',
327-
},
328-
],
329-
text: 'Usage test',
330-
},
331-
]);
332-
333-
tour.start();
334-
});
335-
},
336-
};
337-
</script>

dev/serve.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import Vue from 'vue';
1+
import { createApp } from 'vue';
22
import Dev from './serve.vue';
33
import plugin from '@/entry';
44

5-
Vue.use(plugin);
6-
7-
Vue.config.productionTip = false;
8-
9-
new Vue({
10-
render: (h) => h(Dev),
11-
}).$mount('#app');
5+
createApp(Dev).use(plugin).mount('#app');

dev/serve.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
<script setup>
2+
import ShepherdExample from './components/ShepherdExample.vue';
3+
</script>
4+
15
<template>
26
<shepherd-example />
37
</template>
48

5-
69
<style>
710
@import '~shepherd.js/dist/css/shepherd.css';
11+
812
#app {
913
font-family: 'Avenir', Helvetica, Arial, sans-serif;
1014
-webkit-font-smoothing: antialiased;
@@ -14,10 +18,3 @@
1418
margin-top: 60px;
1519
}
1620
</style>
17-
<script>
18-
import ShepherdExample from './components/ShepherdExample.vue';
19-
20-
export default {
21-
components: { ShepherdExample },
22-
};
23-
</script>

0 commit comments

Comments
 (0)