@stepperize/react
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { Step, Get, Metadata, Utils, Stepper } from '@stepperize/core'; | ||
import { Step, Utils, Get, Metadata, Stepper } from '@stepperize/core'; | ||
export { Get, Step, Stepper } from '@stepperize/core'; | ||
@@ -47,4 +47,10 @@ | ||
/** | ||
* Creates a stepper context and utility functions for managing stepper state. | ||
* | ||
* @param steps - The steps to be included in the stepper. | ||
* @returns An object containing the stepper context and utility functions. | ||
*/ | ||
declare const defineStepper: <const Steps extends Step[]>(...steps: Steps) => StepperReturn<Steps>; | ||
export { type ScopedProps, type StepperReturn, defineStepper }; |
@@ -1,1 +0,1 @@ | ||
'use strict';var r=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 r__namespace=/*#__PURE__*/_interopNamespace(r);var b=(...a)=>{let S=r__namespace.createContext(null),v=core.generateStepperUtils(...a),h=i=>{let{initialStep:p,initialMetadata:c}=i??{},x=r__namespace.useMemo(()=>core.getInitialStepIndex(a,p),[p]),[o,u]=r__namespace.useState(x),[f,m]=r__namespace.useState(()=>core.getInitialMetadata(a,c));return r__namespace.useMemo(()=>{let w=a[o],l=o===a.length-1,d=o===0;return {all:a,current:w,isLast:l,isFirst:d,metadata:f,setMetadata(e,t){m(n=>n[e]===t?n:{...n,[e]:t});},getMetadata(e){return f[e]},resetMetadata(e){m(core.getInitialMetadata(a,e?c: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(d)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(d)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.");u(o+1);},prev(){if(d)throw new Error("Cannot navigate to the previous step because it is the first step.");u(o-1);},get(e){return a.find(t=>t.id===e)},async beforeGoTo(e,t){await core.executeStepCallback(t,!0)&&this.goTo(e);},async afterGoTo(e,t){this.goTo(e),await core.executeStepCallback(t,!1);},goTo(e){let t=a.findIndex(n=>n.id===e);u(t);},reset(){u(x);},...core.generateCommonStepperUseFns(a,w,o)}},[o,f])};return {steps:a,utils:v,Scoped:({initialStep:i,initialMetadata:p,children:c})=>r__namespace.createElement(S.Provider,{value:h({initialStep:i,initialMetadata:p})},c),useStepper:(i={})=>r__namespace.useContext(S)??h(i)}};exports.defineStepper=b; | ||
'use strict';var r=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 r__namespace=/*#__PURE__*/_interopNamespace(r);var b=(...a)=>{let S=r__namespace.createContext(null),v=core.generateStepperUtils(...a),h=i=>{let{initialStep:p,initialMetadata:c}=i??{},x=r__namespace.useMemo(()=>core.getInitialStepIndex(a,p),[p]),[o,u]=r__namespace.useState(x),[f,m]=r__namespace.useState(()=>core.getInitialMetadata(a,c));return r__namespace.useMemo(()=>{let w=a[o],l=o===a.length-1,d=o===0;return {all:a,current:w,isLast:l,isFirst:d,metadata:f,setMetadata(e,t){m(n=>n[e]===t?n:{...n,[e]:t});},getMetadata(e){return f[e]},resetMetadata(e){m(core.getInitialMetadata(a,e?c: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,true)&&this.next();},async afterNext(e){this.next(),await core.executeStepCallback(e,false);},async beforePrev(e){if(d)throw new Error("Cannot navigate to the previous step because it is the first step.");await core.executeStepCallback(e,true)&&this.prev();},async afterPrev(e){if(d)throw new Error("Cannot navigate to the previous step because it is the first step.");this.prev(),await core.executeStepCallback(e,false);},next(){if(l)throw new Error("Cannot navigate to the next step because it is the last step.");u(o+1);},prev(){if(d)throw new Error("Cannot navigate to the previous step because it is the first step.");u(o-1);},get(e){return a.find(t=>t.id===e)},async beforeGoTo(e,t){await core.executeStepCallback(t,true)&&this.goTo(e);},async afterGoTo(e,t){this.goTo(e),await core.executeStepCallback(t,false);},goTo(e){let t=a.findIndex(n=>n.id===e);u(t);},reset(){u(x);},...core.generateCommonStepperUseFns(a,w,o)}},[o,f])};return {steps:a,utils:v,Scoped:({initialStep:i,initialMetadata:p,children:c})=>r__namespace.createElement(S.Provider,{value:h({initialStep:i,initialMetadata:p})},c),useStepper:(i={})=>r__namespace.useContext(S)??h(i)}};exports.defineStepper=b; |
{ | ||
"name": "@stepperize/react", | ||
"version": "5.1.0", | ||
"version": "5.1.1", | ||
"private": false, | ||
@@ -32,3 +32,3 @@ "publishConfig": { | ||
"dependencies": { | ||
"@stepperize/core": "1.2.0" | ||
"@stepperize/core": "1.2.1" | ||
}, | ||
@@ -41,4 +41,4 @@ "peerDependencies": { | ||
"react": "^18.3.1", | ||
"tsup": "^8.3.6", | ||
"typescript": "^5.7.3" | ||
"tsup": "^8.4.0", | ||
"typescript": "^5.8.2" | ||
}, | ||
@@ -45,0 +45,0 @@ "scripts": { |
@@ -14,3 +14,3 @@ <p align="center"> | ||
- 📦 Lightweight (< 1kB gzipped) | ||
- 🪄 Fully typesafe | ||
- 🪄 Fully type-safe | ||
- 🔗 Composable architecture | ||
@@ -68,4 +68,5 @@ - 🎨 Unstyled for maximum customization | ||
- An array of `steps` for rendering | ||
- An `utils` object with useful functions | ||
The only required field for each step is the `id`. You can add any additional properties you need, and they'll be fully typesafe when using the hook. | ||
The only required field for each step is the `id`. You can add any additional properties you need, and they'll be fully type-safe when using the hook. | ||
@@ -82,2 +83,2 @@ ## Documentation | ||
Stepperize is [MIT licensed](LICENSE). | ||
Stepperize is [MIT licensed](LICENSE). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
12991
4.21%52
13.04%82
2.5%+ Added
- Removed
Updated