11import * as React from 'react' ;
22
33import * as logger from './logger' ;
4- import { Handler , WizardProps } from './types' ;
4+ import { Handler , StepName , WizardProps } from './types' ;
55import WizardContext from './wizardContext' ;
66
77const Wizard : React . FC < React . PropsWithChildren < WizardProps > > = React . memo (
@@ -20,6 +20,18 @@ const Wizard: React.FC<React.PropsWithChildren<WizardProps>> = React.memo(
2020 const hasPreviousStep = React . useRef ( false ) ;
2121 const nextStepHandler = React . useRef < Handler > ( ( ) => { } ) ;
2222 const stepCount = React . Children . toArray ( children ) . length ;
23+ const stepsArray = React . Children . toArray ( children ) ;
24+ const stepNames = stepsArray
25+ . map ( ( child ) => {
26+ if ( React . isValidElement ( child ) ) {
27+ const number = child . props . number ;
28+ const name = child . props . name || `Step ${ number } ` ;
29+
30+ return { name, number } ;
31+ }
32+ return null ;
33+ } )
34+ . filter ( Boolean ) as StepName [ ] ;
2335
2436 hasNextStep . current = activeStep < stepCount - 1 ;
2537 hasPreviousStep . current = activeStep > 0 ;
@@ -97,6 +109,7 @@ const Wizard: React.FC<React.PropsWithChildren<WizardProps>> = React.memo(
97109 isFirstStep : ! hasPreviousStep . current ,
98110 isLastStep : ! hasNextStep . current ,
99111 goToStep,
112+ stepNames,
100113 } ) ,
101114 [
102115 doNextStep ,
@@ -105,6 +118,7 @@ const Wizard: React.FC<React.PropsWithChildren<WizardProps>> = React.memo(
105118 activeStep ,
106119 stepCount ,
107120 goToStep ,
121+ stepNames ,
108122 ] ,
109123 ) ;
110124
0 commit comments