vue3-step-wizard 0.5.4 → 0.5.6
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 +22 -1
- package/dist/vue3-step-wizard.es.js +81 -66
- package/dist/vue3-step-wizard.umd.cjs +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -8,6 +8,12 @@ A Vue 3 + TypeScript wizard component.
|
|
|
8
8
|
npm install vue3-step-wizard
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
Then import the stylesheet once in your app entry:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import "vue3-step-wizard/wizard-style.css";
|
|
15
|
+
```
|
|
16
|
+
|
|
11
17
|
## Usage
|
|
12
18
|
|
|
13
19
|
```vue
|
|
@@ -22,7 +28,15 @@ import StepFinish from "./steps/StepFinish.vue";
|
|
|
22
28
|
|
|
23
29
|
const steps: WizardStep[] = [
|
|
24
30
|
{ name: "domain", title: "Domain", component: StepDomain },
|
|
25
|
-
{
|
|
31
|
+
{
|
|
32
|
+
name: "business",
|
|
33
|
+
title: "Business info",
|
|
34
|
+
component: StepBusiness,
|
|
35
|
+
backVisible: true,
|
|
36
|
+
nextVisible: true,
|
|
37
|
+
nextDisabled: false,
|
|
38
|
+
backDisabled: false,
|
|
39
|
+
},
|
|
26
40
|
{ name: "finish", title: "Finish", component: StepFinish },
|
|
27
41
|
];
|
|
28
42
|
|
|
@@ -78,6 +92,13 @@ Wizard emits:
|
|
|
78
92
|
- `step-changed` with `{ from, to }` step names.
|
|
79
93
|
- `custom-event` forwarded from the active step component.
|
|
80
94
|
|
|
95
|
+
Each step can optionally control the wizard buttons when `show-controls` is true:
|
|
96
|
+
|
|
97
|
+
- `nextVisible` (boolean, default `true`)
|
|
98
|
+
- `nextDisabled` (boolean, default `false`)
|
|
99
|
+
- `backVisible` (boolean, default `currentStep > 0`)
|
|
100
|
+
- `backDisabled` (boolean, default `false`)
|
|
101
|
+
|
|
81
102
|
Example step component:
|
|
82
103
|
|
|
83
104
|
```vue
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
const
|
|
1
|
+
import { defineComponent as M, ref as g, watch as V, computed as c, createElementBlock as u, openBlock as o, createElementVNode as r, createCommentVNode as v, toDisplayString as k, Fragment as W, renderList as H, normalizeClass as P, createBlock as $, resolveDynamicComponent as j, mergeProps as q } from "vue";
|
|
2
|
+
const A = { class: "__wizard-page" }, G = { class: "__wizard" }, J = {
|
|
3
3
|
key: 0,
|
|
4
4
|
class: "__wizard-sidebar"
|
|
5
|
-
},
|
|
5
|
+
}, K = { class: "__eyebrow" }, O = { class: "__step-list" }, Q = ["onClick"], R = { class: "__step-index" }, U = { class: "__step-title" }, X = { class: "__wizard-panel" }, Y = {
|
|
6
6
|
key: 1,
|
|
7
7
|
class: "__wizard-controls"
|
|
8
|
-
}, ee = /* @__PURE__ */
|
|
8
|
+
}, Z = ["disabled"], ee = ["disabled"], oe = /* @__PURE__ */ M({
|
|
9
9
|
__name: "Wizard",
|
|
10
10
|
props: {
|
|
11
11
|
steps: {},
|
|
@@ -16,105 +16,120 @@ const P = { class: "__wizard-page" }, $ = { class: "__wizard" }, j = {
|
|
|
16
16
|
showControls: { type: Boolean, default: !0 }
|
|
17
17
|
},
|
|
18
18
|
emits: ["update:modelValue", "change", "custom-event", "step-changed"],
|
|
19
|
-
setup(
|
|
20
|
-
const s =
|
|
21
|
-
|
|
19
|
+
setup(d, { expose: y, emit: z }) {
|
|
20
|
+
const s = d, m = z, S = (e) => s.steps.length ? Math.max(0, Math.min(e, s.steps.length - 1)) : 0, n = g(S(s.modelValue ?? 0));
|
|
21
|
+
V(
|
|
22
22
|
() => s.modelValue,
|
|
23
23
|
(e) => {
|
|
24
|
-
const t =
|
|
24
|
+
const t = S(e ?? 0);
|
|
25
25
|
t !== n.value && (n.value = t);
|
|
26
26
|
}
|
|
27
27
|
);
|
|
28
|
-
const
|
|
29
|
-
|
|
28
|
+
const l = c(() => s.steps[n.value]), i = g(new Set(s.hiddenSteps));
|
|
29
|
+
V(
|
|
30
30
|
() => s.hiddenSteps,
|
|
31
31
|
(e) => {
|
|
32
|
-
|
|
32
|
+
i.value = new Set(e ?? []), C();
|
|
33
33
|
}
|
|
34
34
|
);
|
|
35
|
-
const
|
|
36
|
-
() => s.steps.map((e, t) => ({ step: e, index: t })).filter(({ step: e }) => !
|
|
37
|
-
),
|
|
38
|
-
var
|
|
39
|
-
const t =
|
|
35
|
+
const h = (e) => i.value.has(e), B = c(
|
|
36
|
+
() => s.steps.map((e, t) => ({ step: e, index: t })).filter(({ step: e }) => !h(e.name))
|
|
37
|
+
), p = (e) => {
|
|
38
|
+
var b, _;
|
|
39
|
+
const t = S(e);
|
|
40
40
|
if (t === n.value)
|
|
41
41
|
return;
|
|
42
|
-
const a = ((
|
|
43
|
-
n.value = t,
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}, T = (
|
|
51
|
-
|
|
42
|
+
const a = ((b = s.steps[n.value]) == null ? void 0 : b.name) ?? null, f = (_ = s.steps[t]) == null ? void 0 : _.name;
|
|
43
|
+
n.value = t, m("update:modelValue", t), m("change", t), f && m("step-changed", { from: a, to: f });
|
|
44
|
+
}, D = c(() => n.value >= s.steps.length - 1), N = c(() => {
|
|
45
|
+
const e = l.value;
|
|
46
|
+
return !e || e.backVisible === void 0 ? n.value > 0 : e.backVisible;
|
|
47
|
+
}), E = c(() => {
|
|
48
|
+
const e = l.value;
|
|
49
|
+
return (e == null ? void 0 : e.backDisabled) ?? !1;
|
|
50
|
+
}), T = c(() => {
|
|
51
|
+
const e = l.value;
|
|
52
|
+
return !e || e.nextVisible === void 0 ? !0 : e.nextVisible;
|
|
53
|
+
}), F = c(() => {
|
|
54
|
+
const e = l.value;
|
|
55
|
+
return (e == null ? void 0 : e.nextDisabled) ?? !1;
|
|
56
|
+
}), w = () => {
|
|
57
|
+
n.value >= s.steps.length - 1 || p(n.value + 1);
|
|
52
58
|
}, x = () => {
|
|
59
|
+
n.value <= 0 || p(n.value - 1);
|
|
60
|
+
}, I = (e) => {
|
|
61
|
+
m("custom-event", e);
|
|
62
|
+
}, L = (e) => {
|
|
63
|
+
s.allowStepClick && (s.steps[e], p(e));
|
|
64
|
+
}, C = () => {
|
|
53
65
|
const e = s.steps[n.value];
|
|
54
|
-
if (e && !
|
|
66
|
+
if (e && !h(e.name))
|
|
55
67
|
return;
|
|
56
|
-
const t = s.steps.findIndex((a) => !
|
|
57
|
-
t >= 0 &&
|
|
68
|
+
const t = s.steps.findIndex((a) => !h(a.name));
|
|
69
|
+
t >= 0 && p(t);
|
|
58
70
|
};
|
|
59
|
-
return
|
|
71
|
+
return y({
|
|
60
72
|
moveTo: (e) => {
|
|
61
73
|
const t = s.steps.findIndex((a) => a.name === e);
|
|
62
|
-
t !== -1 && (
|
|
74
|
+
t !== -1 && (h(e) || p(t));
|
|
63
75
|
},
|
|
64
76
|
hideStep: (e) => {
|
|
65
|
-
|
|
77
|
+
i.value = new Set(i.value).add(e), C();
|
|
66
78
|
},
|
|
67
79
|
showStep: (e) => {
|
|
68
|
-
if (!
|
|
80
|
+
if (!i.value.has(e))
|
|
69
81
|
return;
|
|
70
|
-
const t = new Set(
|
|
71
|
-
t.delete(e),
|
|
82
|
+
const t = new Set(i.value);
|
|
83
|
+
t.delete(e), i.value = t;
|
|
72
84
|
}
|
|
73
|
-
}), (e, t) => (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
(
|
|
79
|
-
var
|
|
80
|
-
return
|
|
85
|
+
}), (e, t) => (o(), u("main", A, [
|
|
86
|
+
r("section", G, [
|
|
87
|
+
d.steps.length ? (o(), u("aside", J, [
|
|
88
|
+
r("p", K, k(d.sidebarTitle), 1),
|
|
89
|
+
r("div", O, [
|
|
90
|
+
(o(!0), u(W, null, H(B.value, ({ step: a, index: f }, b) => {
|
|
91
|
+
var _;
|
|
92
|
+
return o(), u("div", {
|
|
81
93
|
key: a.name,
|
|
82
|
-
class:
|
|
83
|
-
__active: a.name === ((
|
|
84
|
-
__clickable:
|
|
94
|
+
class: P(["__step-item", {
|
|
95
|
+
__active: a.name === ((_ = l.value) == null ? void 0 : _.name),
|
|
96
|
+
__clickable: d.allowStepClick
|
|
85
97
|
}]),
|
|
86
|
-
onClick: (
|
|
98
|
+
onClick: (ae) => L(f)
|
|
87
99
|
}, [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
], 10,
|
|
100
|
+
r("span", R, k(b + 1), 1),
|
|
101
|
+
r("span", U, k(a.title), 1)
|
|
102
|
+
], 10, Q);
|
|
91
103
|
}), 128))
|
|
92
104
|
])
|
|
93
|
-
])) :
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
onNext:
|
|
97
|
-
onBack:
|
|
98
|
-
onCustomEvent:
|
|
99
|
-
}), null, 16)) :
|
|
100
|
-
|
|
101
|
-
|
|
105
|
+
])) : v("", !0),
|
|
106
|
+
r("div", X, [
|
|
107
|
+
l.value ? (o(), $(j(l.value.component), q({ key: 0 }, l.value.props, {
|
|
108
|
+
onNext: w,
|
|
109
|
+
onBack: x,
|
|
110
|
+
onCustomEvent: I
|
|
111
|
+
}), null, 16)) : v("", !0),
|
|
112
|
+
d.showControls ? (o(), u("div", Y, [
|
|
113
|
+
N.value ? (o(), u("button", {
|
|
102
114
|
key: 0,
|
|
103
115
|
class: "__cta __ghost",
|
|
104
116
|
type: "button",
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
117
|
+
disabled: E.value,
|
|
118
|
+
onClick: x
|
|
119
|
+
}, " Back ", 8, Z)) : v("", !0),
|
|
120
|
+
T.value ? (o(), u("button", {
|
|
121
|
+
key: 1,
|
|
108
122
|
class: "__cta __primary",
|
|
109
123
|
type: "button",
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
124
|
+
disabled: F.value,
|
|
125
|
+
onClick: w
|
|
126
|
+
}, k(D.value ? "Finish" : "Next"), 9, ee)) : v("", !0)
|
|
127
|
+
])) : v("", !0)
|
|
113
128
|
])
|
|
114
129
|
])
|
|
115
130
|
]));
|
|
116
131
|
}
|
|
117
132
|
});
|
|
118
133
|
export {
|
|
119
|
-
|
|
134
|
+
oe as Wizard
|
|
120
135
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.Vue3StepWizard={},c.Vue))})(this,function(c,e){"use strict";const V={class:"__wizard-page"},y={class:"__wizard"},B={key:0,class:"__wizard-sidebar"},C={class:"__eyebrow"},g={class:"__step-list"},w=["onClick"],x={class:"__step-index"},E={class:"__step-title"},N={class:"__wizard-panel"},z={key:1,class:"__wizard-controls"},D=["disabled"],v=["disabled"],T=e.defineComponent({__name:"Wizard",props:{steps:{},modelValue:{default:0},sidebarTitle:{default:"Setup steps"},allowStepClick:{type:Boolean,default:!0},hiddenSteps:{default:()=>[]},showControls:{type:Boolean,default:!0}},emits:["update:modelValue","change","custom-event","step-changed"],setup(r,{expose:M,emit:W}){const s=r,m=W,h=t=>s.steps.length?Math.max(0,Math.min(t,s.steps.length-1)):0,o=e.ref(h(s.modelValue??0));e.watch(()=>s.modelValue,t=>{const n=h(t??0);n!==o.value&&(o.value=n)});const l=e.computed(()=>s.steps[o.value]),i=e.ref(new Set(s.hiddenSteps));e.watch(()=>s.hiddenSteps,t=>{i.value=new Set(t??[]),S()});const u=t=>i.value.has(t),j=e.computed(()=>s.steps.map((t,n)=>({step:t,index:n})).filter(({step:t})=>!u(t.name))),d=t=>{var f,p;const n=h(t);if(n===o.value)return;const a=((f=s.steps[o.value])==null?void 0:f.name)??null,_=(p=s.steps[n])==null?void 0:p.name;o.value=n,m("update:modelValue",n),m("change",n),_&&m("step-changed",{from:a,to:_})},F=e.computed(()=>o.value>=s.steps.length-1),I=e.computed(()=>{const t=l.value;return!t||t.backVisible===void 0?o.value>0:t.backVisible}),L=e.computed(()=>{const t=l.value;return(t==null?void 0:t.backDisabled)??!1}),P=e.computed(()=>{const t=l.value;return!t||t.nextVisible===void 0?!0:t.nextVisible}),q=e.computed(()=>{const t=l.value;return(t==null?void 0:t.nextDisabled)??!1}),k=()=>{o.value>=s.steps.length-1||d(o.value+1)},b=()=>{o.value<=0||d(o.value-1)},H=t=>{m("custom-event",t)},O=t=>{s.allowStepClick&&(s.steps[t],d(t))},S=()=>{const t=s.steps[o.value];if(t&&!u(t.name))return;const n=s.steps.findIndex(a=>!u(a.name));n>=0&&d(n)};return M({moveTo:t=>{const n=s.steps.findIndex(a=>a.name===t);n!==-1&&(u(t)||d(n))},hideStep:t=>{i.value=new Set(i.value).add(t),S()},showStep:t=>{if(!i.value.has(t))return;const n=new Set(i.value);n.delete(t),i.value=n}}),(t,n)=>(e.openBlock(),e.createElementBlock("main",V,[e.createElementVNode("section",y,[r.steps.length?(e.openBlock(),e.createElementBlock("aside",B,[e.createElementVNode("p",C,e.toDisplayString(r.sidebarTitle),1),e.createElementVNode("div",g,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(j.value,({step:a,index:_},f)=>{var p;return e.openBlock(),e.createElementBlock("div",{key:a.name,class:e.normalizeClass(["__step-item",{__active:a.name===((p=l.value)==null?void 0:p.name),__clickable:r.allowStepClick}]),onClick:J=>O(_)},[e.createElementVNode("span",x,e.toDisplayString(f+1),1),e.createElementVNode("span",E,e.toDisplayString(a.title),1)],10,w)}),128))])])):e.createCommentVNode("",!0),e.createElementVNode("div",N,[l.value?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(l.value.component),e.mergeProps({key:0},l.value.props,{onNext:k,onBack:b,onCustomEvent:H}),null,16)):e.createCommentVNode("",!0),r.showControls?(e.openBlock(),e.createElementBlock("div",z,[I.value?(e.openBlock(),e.createElementBlock("button",{key:0,class:"__cta __ghost",type:"button",disabled:L.value,onClick:b}," Back ",8,D)):e.createCommentVNode("",!0),P.value?(e.openBlock(),e.createElementBlock("button",{key:1,class:"__cta __primary",type:"button",disabled:q.value,onClick:k},e.toDisplayString(F.value?"Finish":"Next"),9,v)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)])])]))}});c.Wizard=T,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue3-step-wizard",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A Vue 3 step-wizard component, with no dependencies",
|
|
6
6
|
"main": "./dist/vue3-step-wizard.umd.cjs",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./index.d.ts",
|
|
12
|
-
"development": "./src/index.ts",
|
|
13
12
|
"import": "./dist/vue3-step-wizard.es.js",
|
|
14
13
|
"require": "./dist/vue3-step-wizard.umd.cjs"
|
|
15
14
|
},
|