@@ -16,38 +16,13 @@ const useMainState = INITIAL_VALUE => {
1616export const useStepNavigation = ( totalSteps , lockMode ) => {
1717 const [ currentStep , setCurrentStep ] = React . useState ( 1 ) ;
1818
19- const stepLocks = [ ...Array ( totalSteps ) . keys ( ) ] . map ( ( x , i ) => ( {
20- step : x + 1 ,
21- locked : ! lockMode || i === 0 ? false : true
22- } ) ) ;
23-
24- const [ locks , setLocks ] = React . useState ( stepLocks ) ;
25-
26- const unlockNextStep = ( ) =>
27- setLocks (
28- locks . map ( item =>
29- item . step <= currentStep + 1 ? { ...item , locked : false } : item
30- )
31- ) ;
32-
33- const lockNextStep = ( ) => {
34- setLocks (
35- locks . map ( item =>
36- item . step === currentStep + 1 ? { ...item , locked : true } : item
37- )
38- ) ;
39- } ;
40-
4119 const prevStep = ( ) => setCurrentStep ( currentStep > 2 ? currentStep - 1 : 1 ) ;
4220 const nextStep = ( ) =>
4321 setCurrentStep ( currentStep < totalSteps ? currentStep + 1 : totalSteps ) ;
4422 const jumpToStep = step => setCurrentStep ( Number ( step ) ) ;
4523
4624 return [
47- { current : currentStep , total : totalSteps } ,
48- locks ,
49- lockNextStep ,
50- unlockNextStep ,
25+ { current : currentStep , total : totalSteps , lock : currentStep + 1 } ,
5126 prevStep ,
5227 nextStep ,
5328 jumpToStep
@@ -56,26 +31,26 @@ export const useStepNavigation = (totalSteps, lockMode) => {
5631
5732const Steps = ( { totalSteps, lockMode, children } ) => {
5833 const [ mainState , setMainState , handleChange ] = useMainState ( { } ) ;
59- const [
60- steps ,
61- locks ,
62- lockNextStep ,
63- unlockNextStep ,
34+ const [ steps , prevStep , nextStep , jumpToStep ] = useStepNavigation (
35+ totalSteps ,
36+ lockMode
37+ ) ;
38+ console . log ( {
39+ mainState,
40+ setMainState,
41+ handleChange,
42+ steps : { total : steps . total , current : steps . current , lock : steps . lock } ,
6443 prevStep,
6544 nextStep,
6645 jumpToStep
67- ] = useStepNavigation ( totalSteps , lockMode ) ;
68-
46+ } ) ;
6947 return (
7048 < StepContext . Provider
7149 value = { {
7250 mainState,
7351 setMainState,
7452 handleChange,
75- steps : { total : steps . total , current : steps . current } ,
76- locks,
77- lockNextStep,
78- unlockNextStep,
53+ steps : { total : steps . total , current : steps . current , lock : steps . lock } ,
7954 prevStep,
8055 nextStep,
8156 jumpToStep
0 commit comments