@equinor/amplify-component-lib 9.3.3 → 9.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import{createContext as t,useState as r,useContext as s}from"react";import{useParams as n,useNavigate as o,useLocation as i}from"react-router";const p=t(void 0);function u(){const e=s(p);if(!e)throw new Error("useStepper must be used within a StepperProvider");return e}const a=({steps:t,children:s,...u})=>{const{step:a}=n(),c=o(),m=i().pathname.
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{createContext as t,useState as r,useContext as s}from"react";import{useParams as n,useNavigate as o,useLocation as i}from"react-router";const p=t(void 0);function u(){const e=s(p);if(!e)throw new Error("useStepper must be used within a StepperProvider");return e}const a=({steps:t,children:s,...u})=>{const{step:a}=n(),c=o(),m=i().pathname.split("/").slice(0,-1).join("/"),S=u.syncToURLParam?Number(a):u?.initialStep??0;if(u.syncToURLParam&&a&&isNaN(Number(a)))throw new Error('Step URL param must be a valid number when using "syncToURLParam"');const[b,h]=r(S),l=u.syncToURLParam?Number(a):b,[d,f]=r(0);if(S>=t.length||S<0)throw new Error("initialStep must be a valid index of the steps array");const g=e=>{u.syncToURLParam?c(`${m}/${e}`):h(e)};return e(p.Provider,{value:{steps:t,currentStep:l,currentSubStep:d,setCurrentStep:g,goToNextStep:()=>{"subSteps"in t[l]&&t[l].subSteps&&d<t[l].subSteps.length-1?f((e=>e+1)):l!==t.length-1&&(g(l+1),0!==d&&f(0))},goToPreviousStep:()=>{if(d>0&&"subSteps"in t[l]&&t[l].subSteps&&t[l].subSteps.length>0)return void f((e=>e-1));if(0===l)return;g(l-1);const e=t.at(l-1);e&&"subSteps"in e&&e.subSteps&&f(e.subSteps.length-1)}},children:s})};export{p as StepperContext,a as StepperProvider,u as useStepper};
|