@stepperize/react
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { Step, Utils, Get, Stepper } from '@stepperize/core'; | ||
import { Step, Utils, Get, Metadata, Stepper } from '@stepperize/core'; | ||
export { Get, Step, Stepper } from '@stepperize/core'; | ||
@@ -7,2 +7,4 @@ | ||
initialStep?: Get.Id<Steps>; | ||
/** The initial metadata. */ | ||
initialMetadata?: Record<Get.Id<Steps>, Metadata>; | ||
}>; | ||
@@ -26,2 +28,3 @@ type StepperReturn<Steps extends Step[]> = { | ||
* @param props.initialStep - The ID of the step to start with (optional). | ||
* @param props.initialMetadata - The initial metadata (optional). | ||
* @param props.children - The child elements to be wrapped by the `Scoped` component. | ||
@@ -37,5 +40,9 @@ * @returns A React element that wraps the children with the stepper context. | ||
* @param initialStep - The ID of the step to start with (optional). | ||
* @param initialMetadata - The initial metadata (optional). | ||
* @returns An object containing properties and methods to interact with the stepper. | ||
*/ | ||
useStepper: (initialStep?: Get.Id<Steps>) => Stepper<Steps>; | ||
useStepper: (props?: { | ||
initialStep?: Get.Id<Steps>; | ||
initialMetadata?: Partial<Record<Get.Id<Steps>, Metadata>>; | ||
}) => Stepper<Steps>; | ||
}; | ||
@@ -42,0 +49,0 @@ |
@@ -1,1 +0,1 @@ | ||
'use strict';var t=require('react'),core=require('@stepperize/core');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var t__namespace=/*#__PURE__*/_interopNamespace(t);var C=(...r)=>{let S=t__namespace.createContext(null),h=core.generateStepperUtils(...r),d=s=>{let p=t__namespace.useMemo(()=>core.getInitialStepIndex(r,s),[s]),[o,a]=t__namespace.useState(p);return t__namespace.useMemo(()=>{let f=r[o],u=o===r.length-1,i=o===0;return {all:r,current:f,isLast:u,isFirst:i,async beforeNext(e){if(u)throw new Error("Cannot navigate to the next step because it is the last step.");await core.executeStepCallback(e,!0)&&this.next();},async afterNext(e){this.next(),await core.executeStepCallback(e,!1);},async beforePrev(e){if(i)throw new Error("Cannot navigate to the previous step because it is the first step.");await core.executeStepCallback(e,!0)&&this.prev();},async afterPrev(e){if(i)throw new Error("Cannot navigate to the previous step because it is the first step.");this.prev(),await core.executeStepCallback(e,!1);},next(){if(u)throw new Error("Cannot navigate to the next step because it is the last step.");a(o+1);},prev(){if(i)throw new Error("Cannot navigate to the previous step because it is the first step.");a(o-1);},get(e){return r.find(n=>n.id===e)},goTo(e){let n=r.findIndex(l=>l.id===e);a(n);},reset(){a(p);},...core.generateCommonStepperUseFns(r,f,o)}},[o])};return {steps:r,utils:h,Scoped:({initialStep:s,children:p})=>t__namespace.createElement(S.Provider,{value:d(s)},p),useStepper:s=>t__namespace.useContext(S)??d(s)}};exports.defineStepper=C; | ||
'use strict';var t=require('react'),core=require('@stepperize/core');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var t__namespace=/*#__PURE__*/_interopNamespace(t);var y=(...r)=>{let f=t__namespace.createContext(null),v=core.generateStepperUtils(...r),h=o=>{let{initialStep:s,initialMetadata:p}=o??{},x=t__namespace.useMemo(()=>core.getInitialStepIndex(r,s),[s]),[n,c]=t__namespace.useState(x),[S,m]=t__namespace.useState(()=>core.getInitialMetadata(r,p));return t__namespace.useMemo(()=>{let w=r[n],l=n===r.length-1,u=n===0;return {all:r,current:w,isLast:l,isFirst:u,metadata:S,setMetadata(e,a){m(i=>i[e]===a?i:{...i,[e]:a});},getMetadata(e){return S[e]},resetMetadata(e){m(core.getInitialMetadata(r,e?p:void 0));},async beforeNext(e){if(l)throw new Error("Cannot navigate to the next step because it is the last step.");await core.executeStepCallback(e,!0)&&this.next();},async afterNext(e){this.next(),await core.executeStepCallback(e,!1);},async beforePrev(e){if(u)throw new Error("Cannot navigate to the previous step because it is the first step.");await core.executeStepCallback(e,!0)&&this.prev();},async afterPrev(e){if(u)throw new Error("Cannot navigate to the previous step because it is the first step.");this.prev(),await core.executeStepCallback(e,!1);},next(){if(l)throw new Error("Cannot navigate to the next step because it is the last step.");c(n+1);},prev(){if(u)throw new Error("Cannot navigate to the previous step because it is the first step.");c(n-1);},get(e){return r.find(a=>a.id===e)},goTo(e){let a=r.findIndex(i=>i.id===e);c(a);},reset(){c(x);},...core.generateCommonStepperUseFns(r,w,n)}},[n,S])};return {steps:r,utils:v,Scoped:({initialStep:o,initialMetadata:s,children:p})=>t__namespace.createElement(f.Provider,{value:h({initialStep:o,initialMetadata:s})},p),useStepper:(o={})=>t__namespace.useContext(f)??h(o)}};exports.defineStepper=y; |
{ | ||
"name": "@stepperize/react", | ||
"version": "4.2.0", | ||
"version": "5.0.0", | ||
"private": false, | ||
@@ -32,3 +32,3 @@ "publishConfig": { | ||
"dependencies": { | ||
"@stepperize/core": "1.1.0" | ||
"@stepperize/core": "1.1.1" | ||
}, | ||
@@ -35,0 +35,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
12104
11.66%46
17.95%+ Added
- Removed
Updated