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 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
- { name: "business", title: "Business info", component: StepBusiness },
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 D, ref as y, watch as b, computed as w, createElementBlock as i, openBlock as l, createElementVNode as c, createCommentVNode as f, toDisplayString as S, Fragment as F, renderList as I, normalizeClass as L, createBlock as M, resolveDynamicComponent as W, mergeProps as H } from "vue";
2
- const P = { class: "__wizard-page" }, $ = { class: "__wizard" }, j = {
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
- }, q = { class: "__eyebrow" }, A = { class: "__step-list" }, G = ["onClick"], J = { class: "__step-index" }, K = { class: "__step-title" }, O = { class: "__wizard-panel" }, Q = {
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__ */ D({
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(u, { expose: V, emit: z }) {
20
- const s = u, p = z, k = (e) => s.steps.length ? Math.max(0, Math.min(e, s.steps.length - 1)) : 0, n = y(k(s.modelValue ?? 0));
21
- b(
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 = k(e ?? 0);
24
+ const t = S(e ?? 0);
25
25
  t !== n.value && (n.value = t);
26
26
  }
27
27
  );
28
- const _ = w(() => s.steps[n.value]), o = y(new Set(s.hiddenSteps));
29
- b(
28
+ const l = c(() => s.steps[n.value]), i = g(new Set(s.hiddenSteps));
29
+ V(
30
30
  () => s.hiddenSteps,
31
31
  (e) => {
32
- o.value = new Set(e ?? []), x();
32
+ i.value = new Set(e ?? []), C();
33
33
  }
34
34
  );
35
- const m = (e) => o.value.has(e), B = w(
36
- () => s.steps.map((e, t) => ({ step: e, index: t })).filter(({ step: e }) => !m(e.name))
37
- ), r = (e) => {
38
- var h, d;
39
- const t = k(e);
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 = ((h = s.steps[n.value]) == null ? void 0 : h.name) ?? null, v = (d = s.steps[t]) == null ? void 0 : d.name;
43
- n.value = t, p("update:modelValue", t), p("change", t), v && p("step-changed", { from: a, to: v });
44
- }, N = w(() => n.value >= s.steps.length - 1), C = () => {
45
- n.value >= s.steps.length - 1 || r(n.value + 1);
46
- }, g = () => {
47
- n.value <= 0 || r(n.value - 1);
48
- }, E = (e) => {
49
- p("custom-event", e);
50
- }, T = (e) => {
51
- s.allowStepClick && (s.steps[e], r(e));
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 && !m(e.name))
66
+ if (e && !h(e.name))
55
67
  return;
56
- const t = s.steps.findIndex((a) => !m(a.name));
57
- t >= 0 && r(t);
68
+ const t = s.steps.findIndex((a) => !h(a.name));
69
+ t >= 0 && p(t);
58
70
  };
59
- return V({
71
+ return y({
60
72
  moveTo: (e) => {
61
73
  const t = s.steps.findIndex((a) => a.name === e);
62
- t !== -1 && (m(e) || r(t));
74
+ t !== -1 && (h(e) || p(t));
63
75
  },
64
76
  hideStep: (e) => {
65
- o.value = new Set(o.value).add(e), x();
77
+ i.value = new Set(i.value).add(e), C();
66
78
  },
67
79
  showStep: (e) => {
68
- if (!o.value.has(e))
80
+ if (!i.value.has(e))
69
81
  return;
70
- const t = new Set(o.value);
71
- t.delete(e), o.value = t;
82
+ const t = new Set(i.value);
83
+ t.delete(e), i.value = t;
72
84
  }
73
- }), (e, t) => (l(), i("main", P, [
74
- c("section", $, [
75
- u.steps.length ? (l(), i("aside", j, [
76
- c("p", q, S(u.sidebarTitle), 1),
77
- c("div", A, [
78
- (l(!0), i(F, null, I(B.value, ({ step: a, index: v }, h) => {
79
- var d;
80
- return l(), i("div", {
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: L(["__step-item", {
83
- __active: a.name === ((d = _.value) == null ? void 0 : d.name),
84
- __clickable: u.allowStepClick
94
+ class: P(["__step-item", {
95
+ __active: a.name === ((_ = l.value) == null ? void 0 : _.name),
96
+ __clickable: d.allowStepClick
85
97
  }]),
86
- onClick: (Y) => T(v)
98
+ onClick: (ae) => L(f)
87
99
  }, [
88
- c("span", J, S(h + 1), 1),
89
- c("span", K, S(a.title), 1)
90
- ], 10, G);
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
- ])) : f("", !0),
94
- c("div", O, [
95
- _.value ? (l(), M(W(_.value.component), H({ key: 0 }, _.value.props, {
96
- onNext: C,
97
- onBack: g,
98
- onCustomEvent: E
99
- }), null, 16)) : f("", !0),
100
- u.showControls ? (l(), i("div", Q, [
101
- n.value > 0 ? (l(), i("button", {
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
- onClick: g
106
- }, " Back ")) : f("", !0),
107
- c("button", {
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
- onClick: C
111
- }, S(N.value ? "Finish" : "Next"), 1)
112
- ])) : f("", !0)
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
- ee as Wizard
134
+ oe as Wizard
120
135
  };
@@ -1 +1 @@
1
- (function(l,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(l=typeof globalThis<"u"?globalThis:l||self,e(l.Vue3StepWizard={},l.Vue))})(this,function(l,e){"use strict";const g={class:"__wizard-page"},w={class:"__wizard"},y={key:0,class:"__wizard-sidebar"},C={class:"__eyebrow"},B={class:"__step-list"},E=["onClick"],b={class:"__step-index"},x={class:"__step-title"},N={class:"__wizard-panel"},z={key:1,class:"__wizard-controls"},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(i,{expose:D,emit:v}){const o=i,p=v,f=t=>o.steps.length?Math.max(0,Math.min(t,o.steps.length-1)):0,s=e.ref(f(o.modelValue??0));e.watch(()=>o.modelValue,t=>{const n=f(t??0);n!==s.value&&(s.value=n)});const m=e.computed(()=>o.steps[s.value]),c=e.ref(new Set(o.hiddenSteps));e.watch(()=>o.hiddenSteps,t=>{c.value=new Set(t??[]),V()});const u=t=>c.value.has(t),M=e.computed(()=>o.steps.map((t,n)=>({step:t,index:n})).filter(({step:t})=>!u(t.name))),r=t=>{var h,d;const n=f(t);if(n===s.value)return;const a=((h=o.steps[s.value])==null?void 0:h.name)??null,_=(d=o.steps[n])==null?void 0:d.name;s.value=n,p("update:modelValue",n),p("change",n),_&&p("step-changed",{from:a,to:_})},W=e.computed(()=>s.value>=o.steps.length-1),S=()=>{s.value>=o.steps.length-1||r(s.value+1)},k=()=>{s.value<=0||r(s.value-1)},j=t=>{p("custom-event",t)},F=t=>{o.allowStepClick&&(o.steps[t],r(t))},V=()=>{const t=o.steps[s.value];if(t&&!u(t.name))return;const n=o.steps.findIndex(a=>!u(a.name));n>=0&&r(n)};return D({moveTo:t=>{const n=o.steps.findIndex(a=>a.name===t);n!==-1&&(u(t)||r(n))},hideStep:t=>{c.value=new Set(c.value).add(t),V()},showStep:t=>{if(!c.value.has(t))return;const n=new Set(c.value);n.delete(t),c.value=n}}),(t,n)=>(e.openBlock(),e.createElementBlock("main",g,[e.createElementVNode("section",w,[i.steps.length?(e.openBlock(),e.createElementBlock("aside",y,[e.createElementVNode("p",C,e.toDisplayString(i.sidebarTitle),1),e.createElementVNode("div",B,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(M.value,({step:a,index:_},h)=>{var d;return e.openBlock(),e.createElementBlock("div",{key:a.name,class:e.normalizeClass(["__step-item",{__active:a.name===((d=m.value)==null?void 0:d.name),__clickable:i.allowStepClick}]),onClick:q=>F(_)},[e.createElementVNode("span",b,e.toDisplayString(h+1),1),e.createElementVNode("span",x,e.toDisplayString(a.title),1)],10,E)}),128))])])):e.createCommentVNode("",!0),e.createElementVNode("div",N,[m.value?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(m.value.component),e.mergeProps({key:0},m.value.props,{onNext:S,onBack:k,onCustomEvent:j}),null,16)):e.createCommentVNode("",!0),i.showControls?(e.openBlock(),e.createElementBlock("div",z,[s.value>0?(e.openBlock(),e.createElementBlock("button",{key:0,class:"__cta __ghost",type:"button",onClick:k}," Back ")):e.createCommentVNode("",!0),e.createElementVNode("button",{class:"__cta __primary",type:"button",onClick:S},e.toDisplayString(W.value?"Finish":"Next"),1)])):e.createCommentVNode("",!0)])])]))}});l.Wizard=T,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
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.4",
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
  },