Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stepper-hook

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stepper-hook - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

9

dist/stepper-hook.d.ts
import { JSX as JSX_2 } from 'react/jsx-runtime';
import { PropsWithChildren } from 'react';
declare interface Props<DataT extends object> extends PropsWithChildren {
declare interface Props<DataT extends object> {
children?: (context: {
step: React.ReactNode;
}) => React.ReactNode;
initialData?: DataT;
onComplete?: () => void;
stepComponentWrapper?: React.FC<PropsWithChildren>;
steps: Step<DataT>[];

@@ -16,3 +17,3 @@ }

export declare function Stepper<DataT extends object>({ initialData, onComplete, steps, stepComponentWrapper, children, }: Props<DataT>): JSX_2.Element;
export declare function Stepper<DataT extends object>({ initialData, onComplete, steps, children, }: Props<DataT>): JSX_2.Element;

@@ -19,0 +20,0 @@ declare interface StepperContextType<DataT extends object> {

@@ -1,4 +0,4 @@

import { jsx as u, jsxs as $ } from "react/jsx-runtime";
import { createContext as D, useState as w, useRef as g, useContext as b } from "react";
const j = (s) => D(s), y = j({
import { jsx as f } from "react/jsx-runtime";
import { createContext as D, useState as g, useRef as y, useContext as $ } from "react";
const b = (n) => D(n), m = b({
activeStep: 0,

@@ -23,14 +23,14 @@ data: {},

function E({
initialData: s,
onComplete: o,
steps: n,
children: a
initialData: n,
onComplete: s,
steps: r,
children: o
}) {
const [r, m] = w(0), c = g(s), [I, f] = w(!1), p = g(null), i = n.length, d = r === 0, h = r === i - 1, v = async () => {
const [a, u] = g(0), i = y(n), [I, l] = g(!1), p = y(null), c = r.length, v = a === 0, h = a === c - 1, w = async () => {
if (!p.current)
return !0;
try {
f(!0);
l(!0);
const t = await p.current();
if (f(!1), !t)
if (l(!1), !t)
return !1;

@@ -41,24 +41,24 @@ } catch {

return !0;
}, l = async (t, e = !1) => {
if (t < 0 || t > i)
}, S = async (t, e = !1) => {
if (t < 0 || t > c)
throw new Error(
`Invalid step ${t}, it should be between 0 and ${i}`
`Invalid step ${t}, it should be between 0 and ${c}`
);
if (!(!e && !await v())) {
if (!(!e && !await w())) {
if (h && // This check basically means that we are in the last step and
// we are trying to go to the next step, which means completing the stepper
t === i && o) {
o();
t === c && s) {
s();
return;
}
P(), m(t);
P(), u(t);
}
}, x = (t = 1) => {
if (t < 0 && d)
if (t < 0 && v)
throw new Error("You are already in the first step");
let e;
for (e = r + 1 * t; t > 0 ? e < i : e >= 0; e = e + t) {
const S = n[e];
if ("showIf" in S && S.showIf) {
if (S.showIf(c.current))
for (e = a + 1 * t; t > 0 ? e < c : e >= 0; e = e + t) {
const d = r[e];
if ("showIf" in d && d.showIf) {
if (d.showIf(i.current))
return e;

@@ -69,8 +69,8 @@ } else

return e;
}, L = () => l(x(-1), !0), C = async () => {
if (!await v())
}, L = () => S(x(-1), !0), N = async () => {
if (!await w())
return;
const t = x();
l(t, !0);
}, N = (t) => {
S(t, !0);
}, C = (t) => {
p.current = t;

@@ -80,50 +80,46 @@ }, P = () => {

}, T = {
activeStep: r,
data: c.current,
goToNextStep: C,
activeStep: a,
data: i.current,
goToNextStep: N,
goToPreviousStep: L,
handleStepValidation: N,
isFirstStep: d,
handleStepValidation: C,
isFirstStep: v,
isLastStep: h,
isLoading: I,
setActiveStep: l,
setActiveStep: S,
setData: (t) => {
if (typeof t == "function") {
c.current = t(c.current);
i.current = t(i.current);
return;
}
c.current = t;
i.current = t;
},
setLoading: f,
totalSteps: i
setLoading: l,
totalSteps: c
};
return /* @__PURE__ */ u(y.Provider, { value: T, children: a });
return /* @__PURE__ */ f(m.Provider, { value: T, children: o });
}
function F() {
return b(y);
return $(m);
}
function V({
steps: s,
stepComponentWrapper: o
children: n,
steps: s
}) {
const { activeStep: n } = F(), a = s[n], r = "component" in a ? a.component : a;
return o ? /* @__PURE__ */ u(o, { children: /* @__PURE__ */ u(r, {}, `step-${n}`) }) : /* @__PURE__ */ u(r, {}, `step-${n}`);
const { activeStep: r } = F(), o = s[r], a = "component" in o ? o.component : o, u = /* @__PURE__ */ f(a, {}, `step-${r}`);
return n ? n({ step: u }) : u;
}
function H({
initialData: s,
onComplete: o,
steps: n,
stepComponentWrapper: a,
children: r
function A({
initialData: n,
onComplete: s,
steps: r,
children: o
}) {
return /* @__PURE__ */ $(
return /* @__PURE__ */ f(
E,
{
initialData: s ?? {},
steps: n,
onComplete: o,
children: [
/* @__PURE__ */ u(V, { steps: n, stepComponentWrapper: a }),
r
]
initialData: n ?? {},
steps: r,
onComplete: s,
children: /* @__PURE__ */ f(V, { steps: r, children: o })
}

@@ -133,4 +129,4 @@ );

export {
H as Stepper,
A as Stepper,
F as useStepper
};
{
"name": "stepper-hook",
"version": "0.3.0",
"version": "0.3.1",
"description": "React hook for creating custom stepper components",

@@ -23,10 +23,2 @@ "author": {

},
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"build-docs": "tsc -b && vite build -c vite.config.docs.ts",
"lint": "eslint .",
"preview": "vite preview",
"prepublish": "pnpm build"
},
"dependencies": {

@@ -50,3 +42,10 @@ "react": "^18.3.1",

"vite-plugin-dts": "^4.0.3"
},
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"build-docs": "tsc -b && vite build -c vite.config.docs.ts",
"lint": "eslint .",
"preview": "vite preview"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc