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.3 to 0.3.4

16

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 Omit<ProviderProps<DataT>, 'children' | 'initialData'> {
declare interface Props<DataT extends object, MetadataT = any> extends Omit<ProviderProps<DataT, MetadataT>, 'children' | 'initialData'> {
children?: (context: {

@@ -11,3 +11,3 @@ step: React.ReactNode;

declare interface ProviderProps<DataT extends object> extends PropsWithChildren {
declare interface ProviderProps<DataT extends object, MetadataT> extends PropsWithChildren {
initialStep?: number;

@@ -17,14 +17,16 @@ initialData: DataT;

onStepChange?: (step: number, direction: number) => void;
steps: Step<DataT>[];
steps: Step<DataT, MetadataT>[];
}
export declare type Step<DataT extends object> = React.FC | {
export declare type Step<DataT extends object = any, MetadataT = any> = React.FC | {
component: React.FC;
metadata?: MetadataT;
showIf?: (data: DataT) => boolean;
};
export declare function Stepper<DataT extends object>({ initialData, initialStep, onComplete, onStepChange, steps, children, }: Props<DataT>): JSX_2.Element;
export declare function Stepper<DataT extends object, MetadataT = any>({ initialData, initialStep, onComplete, onStepChange, steps, children, }: Props<DataT, MetadataT>): JSX_2.Element;
declare interface StepperContextType<DataT extends object> {
declare interface StepperContextType<DataT extends object, MetadataT> {
activeStep: number;
allSteps: Step<DataT, MetadataT>[];
data: DataT;

@@ -61,3 +63,3 @@ /**

export declare function useStepper<DataT extends object>(): StepperContextType<DataT>;
export declare function useStepper<DataT extends object, MetadataT = any>(): StepperContextType<DataT, MetadataT>;

@@ -64,0 +66,0 @@ declare type ValidationHandler = () => Promise<boolean> | boolean;

import { jsx as f } from "react/jsx-runtime";
import { createContext as b, useState as I, useRef as v, useContext as F } from "react";
const V = (n) => b(n), L = V({
const V = (r) => b(r), L = V({
activeStep: 0,
allSteps: [],
data: {},

@@ -24,17 +25,17 @@ direction: 0,

function j({
initialData: n,
initialStep: s = 0,
onComplete: a,
onStepChange: r,
steps: o,
initialData: r,
initialStep: a = 0,
onComplete: s,
onStepChange: o,
steps: n,
children: c
}) {
if (s < 0 || s >= o.length)
if (a < 0 || a >= n.length)
throw new Error("Invalid initial step");
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)
const [u, N] = I(a), l = v(r), [C, S] = I(!1), p = v(null), d = v(0), i = n.length, x = u === 0, g = u === i - 1, m = async () => {
if (!p.current)
return !0;
try {
S(!0);
const t = await l.current();
const t = await p.current();
if (S(!1), !t)

@@ -55,6 +56,6 @@ return !1;

t === i) {
a ? a() : console.warn("Stepper completed without an onComplete handler");
s ? s() : console.warn("Stepper completed without an onComplete handler");
return;
}
d.current = Math.sign(t - u), E(), N(t), r && r(t, d.current);
d.current = Math.sign(t - u), E(), N(t), o && o(t, d.current);
}

@@ -66,5 +67,5 @@ }, y = (t = 1) => {

for (e = u + 1 * t; t > 0 ? e < i : e >= 0; e = e + t) {
const w = o[e];
const w = n[e];
if ("showIf" in w && w.showIf) {
if (w.showIf(p.current))
if (w.showIf(l.current))
return e;

@@ -81,8 +82,9 @@ } else

}, D = (t) => {
l.current = t;
p.current = t;
}, E = () => {
l.current = null;
p.current = null;
}, $ = {
activeStep: u,
data: p.current,
allSteps: n,
data: l.current,
direction: d.current,

@@ -98,6 +100,6 @@ goToNextStep: T,

if (typeof t == "function") {
p.current = t(p.current);
l.current = t(l.current);
return;
}
p.current = t;
l.current = t;
},

@@ -113,14 +115,14 @@ setLoading: S,

function A({
children: n,
steps: s
children: r,
steps: a
}) {
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;
const { activeStep: s } = k(), o = a[s], n = "component" in o ? o.component : o, c = /* @__PURE__ */ f(n, {}, `step-${s}`);
return r ? r({ step: c }) : c;
}
function R({
initialData: n,
initialStep: s,
onComplete: a,
onStepChange: r,
steps: o,
initialData: r,
initialStep: a,
onComplete: s,
onStepChange: o,
steps: n,
children: c

@@ -131,8 +133,8 @@ }) {

{
initialData: n ?? {},
initialStep: s,
onComplete: a,
onStepChange: r,
steps: o,
children: /* @__PURE__ */ f(A, { steps: o, children: c })
initialData: r ?? {},
initialStep: a,
onComplete: s,
onStepChange: o,
steps: n,
children: /* @__PURE__ */ f(A, { steps: n, children: c })
}

@@ -139,0 +141,0 @@ );

{
"name": "stepper-hook",
"version": "0.3.3",
"version": "0.3.4",
"description": "React hook for creating custom stepper components",

@@ -5,0 +5,0 @@ "author": {

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