@@ -2,31 +2,41 @@ import React from 'react';
22import PropTypes from 'prop-types' ;
33import { AngleRightIcon , CaretDownIcon } from '@patternfly/react-icons' ;
44
5- const WizardToggle = ( { activeStepIndex, activeStepName, activeStepSubName, isOpen, dispatch } ) => (
6- < button
7- onClick = { ( ) => dispatch ( { type : isOpen ? 'closeNav' : 'openNav' } ) }
8- className = { `pf-c-wizard__toggle ${ isOpen ? 'pf-m-expanded' : '' } ` }
9- aria-label = "Wizard Toggle"
10- aria-expanded = { isOpen }
11- type = "button"
12- >
13- < ol className = "pf-c-wizard__toggle-list" >
14- < li className = "pf-c-wizard__toggle-list-item" >
15- < span className = "pf-c-wizard__toggle-num" > { activeStepIndex } </ span > { activeStepName }
16- { activeStepSubName && < AngleRightIcon className = "pf-c-wizard__toggle-separator" aria-hidden = "true" /> }
17- </ li >
18- { activeStepSubName && < li className = "pf-c-wizard__toggle-list-item" > { activeStepSubName } </ li > }
19- </ ol >
20- < span className = "pf-c-wizard__toggle-icon" >
21- < CaretDownIcon aria-hidden = "true" />
22- </ span >
23- </ button >
24- ) ;
5+ const WizardToggle = ( { activeStepIndex, currentStep, navSchema, isOpen, dispatch } ) => {
6+ const substepTitle = navSchema . find ( ( step ) => step . name === currentStep . name ) ?. substepOfTitle ;
7+ const substepName = navSchema . find ( ( step ) => step . name === currentStep . name ) ?. substepOf ;
8+
9+ const index = substepName ? navSchema . find ( ( step ) => step . substepOf === substepName ) ?. index : activeStepIndex ;
10+
11+ const activeStepName = substepTitle || currentStep . title ;
12+ const activeStepSubName = substepTitle ? currentStep . title : undefined ;
13+
14+ return (
15+ < button
16+ onClick = { ( ) => dispatch ( { type : isOpen ? 'closeNav' : 'openNav' } ) }
17+ className = { `pf-c-wizard__toggle ${ isOpen ? 'pf-m-expanded' : '' } ` }
18+ aria-label = "Wizard Toggle"
19+ aria-expanded = { isOpen }
20+ type = "button"
21+ >
22+ < ol className = "pf-c-wizard__toggle-list" >
23+ < li className = "pf-c-wizard__toggle-list-item" >
24+ < span className = "pf-c-wizard__toggle-num" > { index + 1 } </ span > { activeStepName }
25+ { activeStepSubName && < AngleRightIcon className = "pf-c-wizard__toggle-separator" aria-hidden = "true" /> }
26+ </ li >
27+ { activeStepSubName && < li className = "pf-c-wizard__toggle-list-item" > { activeStepSubName } </ li > }
28+ </ ol >
29+ < span className = "pf-c-wizard__toggle-icon" >
30+ < CaretDownIcon aria-hidden = "true" />
31+ </ span >
32+ </ button >
33+ ) ;
34+ } ;
2535
2636WizardToggle . propTypes = {
2737 activeStepIndex : PropTypes . number ,
28- activeStepName : PropTypes . node ,
29- activeStepSubName : PropTypes . node ,
38+ currentStep : PropTypes . object ,
39+ navSchema : PropTypes . array ,
3040 isOpen : PropTypes . bool ,
3141 dispatch : PropTypes . func
3242} ;
0 commit comments