stepper-hook
Advanced tools
Comparing version 0.3.2 to 0.3.3
import { JSX as JSX_2 } from 'react/jsx-runtime'; | ||
import { PropsWithChildren } from 'react'; | ||
declare interface Props<DataT extends object> { | ||
declare interface Props<DataT extends object> extends Omit<ProviderProps<DataT>, 'children' | 'initialData'> { | ||
children?: (context: { | ||
@@ -8,3 +9,9 @@ step: React.ReactNode; | ||
initialData?: DataT; | ||
} | ||
declare interface ProviderProps<DataT extends object> extends PropsWithChildren { | ||
initialStep?: number; | ||
initialData: DataT; | ||
onComplete?: () => void; | ||
onStepChange?: (step: number, direction: number) => void; | ||
steps: Step<DataT>[]; | ||
@@ -18,3 +25,3 @@ } | ||
export declare function Stepper<DataT extends object>({ initialData, onComplete, steps, children, }: Props<DataT>): JSX_2.Element; | ||
export declare function Stepper<DataT extends object>({ initialData, initialStep, onComplete, onStepChange, steps, children, }: Props<DataT>): JSX_2.Element; | ||
@@ -21,0 +28,0 @@ declare interface StepperContextType<DataT extends object> { |
@@ -26,10 +26,10 @@ import { jsx as f } from "react/jsx-runtime"; | ||
initialStep: s = 0, | ||
onComplete: r, | ||
onStepChange: o, | ||
steps: c, | ||
children: p | ||
onComplete: a, | ||
onStepChange: r, | ||
steps: o, | ||
children: c | ||
}) { | ||
if (s < 0 || s >= c.length) | ||
if (s < 0 || s >= o.length) | ||
throw new Error("Invalid initial step"); | ||
const [i, N] = I(s), u = v(n), [C, S] = I(!1), l = v(null), d = v(0), a = c.length, x = i === 0, g = i === a - 1, m = async () => { | ||
const [u, N] = I(s), p = v(n), [C, S] = I(!1), l = v(null), d = v(0), i = o.length, x = u === 0, g = u === i - 1, m = async () => { | ||
if (!l.current) | ||
@@ -47,5 +47,5 @@ return !0; | ||
}, h = async (t, e = !1) => { | ||
if (t < 0 || t > a) | ||
if (t < 0 || t > i) | ||
throw new Error( | ||
`Invalid step ${t}, it should be between 0 and ${a}` | ||
`Invalid step ${t}, it should be between 0 and ${i}` | ||
); | ||
@@ -55,7 +55,7 @@ if (!(!e && !await m())) { | ||
// we are trying to go to the next step, which means completing the stepper | ||
t === a) { | ||
r ? r() : console.warn("Stepper completed without an onComplete handler"); | ||
t === i) { | ||
a ? a() : console.warn("Stepper completed without an onComplete handler"); | ||
return; | ||
} | ||
d.current = Math.sign(t - i), E(), N(t), o && o(t, d.current); | ||
d.current = Math.sign(t - u), E(), N(t), r && r(t, d.current); | ||
} | ||
@@ -66,6 +66,6 @@ }, y = (t = 1) => { | ||
let e; | ||
for (e = i + 1 * t; t > 0 ? e < a : e >= 0; e = e + t) { | ||
const w = c[e]; | ||
for (e = u + 1 * t; t > 0 ? e < i : e >= 0; e = e + t) { | ||
const w = o[e]; | ||
if ("showIf" in w && w.showIf) { | ||
if (w.showIf(u.current)) | ||
if (w.showIf(p.current)) | ||
return e; | ||
@@ -86,4 +86,4 @@ } else | ||
}, $ = { | ||
activeStep: i, | ||
data: u.current, | ||
activeStep: u, | ||
data: p.current, | ||
direction: d.current, | ||
@@ -99,11 +99,11 @@ goToNextStep: T, | ||
if (typeof t == "function") { | ||
u.current = t(u.current); | ||
p.current = t(p.current); | ||
return; | ||
} | ||
u.current = t; | ||
p.current = t; | ||
}, | ||
setLoading: S, | ||
totalSteps: a | ||
totalSteps: i | ||
}; | ||
return /* @__PURE__ */ f(L.Provider, { value: $, children: p }); | ||
return /* @__PURE__ */ f(L.Provider, { value: $, children: c }); | ||
} | ||
@@ -117,10 +117,12 @@ function k() { | ||
}) { | ||
const { activeStep: r } = k(), o = s[r], c = "component" in o ? o.component : o, p = /* @__PURE__ */ f(c, {}, `step-${r}`); | ||
return n ? n({ step: p }) : p; | ||
const { activeStep: a } = k(), r = s[a], o = "component" in r ? r.component : r, c = /* @__PURE__ */ f(o, {}, `step-${a}`); | ||
return n ? n({ step: c }) : c; | ||
} | ||
function R({ | ||
initialData: n, | ||
onComplete: s, | ||
steps: r, | ||
children: o | ||
initialStep: s, | ||
onComplete: a, | ||
onStepChange: r, | ||
steps: o, | ||
children: c | ||
}) { | ||
@@ -131,5 +133,7 @@ return /* @__PURE__ */ f( | ||
initialData: n ?? {}, | ||
steps: r, | ||
onComplete: s, | ||
children: /* @__PURE__ */ f(A, { steps: r, children: o }) | ||
initialStep: s, | ||
onComplete: a, | ||
onStepChange: r, | ||
steps: o, | ||
children: /* @__PURE__ */ f(A, { steps: o, children: c }) | ||
} | ||
@@ -136,0 +140,0 @@ ); |
{ | ||
"name": "stepper-hook", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "React hook for creating custom stepper components", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10307
202