@@ -17,24 +17,65 @@ RenderTitle.propTypes = {
1717 customTitle : PropTypes . node
1818} ;
1919
20- const WizardStep = ( { name, title, description, fields, formOptions, showTitles, showTitle, customTitle, hasNoBodyPadding, ...rest } ) => {
20+ const DefaultStepTemplate = ( { formFields, formRef, title, customTitle, showTitle, showTitles } ) => (
21+ < div ref = { formRef } className = "pf-c-form" >
22+ { ( ( showTitles && showTitle !== false ) || showTitle ) && < RenderTitle title = { title } customTitle = { customTitle } /> }
23+ { formFields }
24+ </ div >
25+ ) ;
26+
27+ DefaultStepTemplate . propTypes = {
28+ title : PropTypes . node ,
29+ formFields : PropTypes . array . isRequired ,
30+ formOptions : PropTypes . shape ( {
31+ renderForm : PropTypes . func . isRequired
32+ } ) . isRequired ,
33+ showTitles : PropTypes . bool ,
34+ showTitle : PropTypes . bool ,
35+ customTitle : PropTypes . node ,
36+ formRef : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . shape ( { current : PropTypes . instanceOf ( Element ) } ) ] )
37+ } ;
38+
39+ const WizardStep = ( {
40+ name,
41+ title,
42+ description,
43+ fields,
44+ formOptions,
45+ showTitles,
46+ showTitle,
47+ customTitle,
48+ hasNoBodyPadding,
49+ StepTemplate,
50+ ...rest
51+ } ) => {
2152 const formRef = useRef ( ) ;
2253
2354 useEffect ( ( ) => {
2455 // HACK: I can not pass ref to WizardBody because it is not
2556 // wrapped by forwardRef. However, the step body (the one that overflows)
2657 // is the grand parent of the form element.
2758 const stepBody = formRef . current && formRef . current . parentNode . parentNode ;
28- stepBody . scrollTo ( { top : 0 , left : 0 , behavior : 'smooth' } ) ;
59+ stepBody && stepBody . scrollTo ( { top : 0 , left : 0 , behavior : 'smooth' } ) ;
2960 } , [ name ] ) ;
3061
3162 return (
3263 < Fragment >
3364 < WizardBody hasNoBodyPadding = { hasNoBodyPadding } >
34- < div ref = { formRef } className = "pf-c-form" >
35- { ( ( showTitles && showTitle !== false ) || showTitle ) && < RenderTitle title = { title } customTitle = { customTitle } /> }
36- { fields . map ( ( item ) => formOptions . renderForm ( [ item ] , formOptions ) ) }
37- </ div >
65+ < StepTemplate
66+ formFields = { fields . map ( ( item ) => formOptions . renderForm ( [ item ] , formOptions ) ) }
67+ name = { name }
68+ title = { title }
69+ description = { description }
70+ formOptions = { formOptions }
71+ showTitles = { showTitles }
72+ showTitle = { showTitle }
73+ customTitle = { customTitle }
74+ hasNoBodyPadding = { hasNoBodyPadding }
75+ formRef = { formRef }
76+ fields = { fields }
77+ { ...rest }
78+ />
3879 </ WizardBody >
3980 < WizardStepButtons formOptions = { formOptions } { ...rest } />
4081 </ Fragment >
@@ -52,7 +93,12 @@ WizardStep.propTypes = {
5293 showTitle : PropTypes . bool ,
5394 customTitle : PropTypes . node ,
5495 name : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
55- hasNoBodyPadding : PropTypes . bool
96+ hasNoBodyPadding : PropTypes . bool ,
97+ StepTemplate : PropTypes . elementType
98+ } ;
99+
100+ WizardStep . defaultProps = {
101+ StepTemplate : DefaultStepTemplate
56102} ;
57103
58104export default WizardStep ;
0 commit comments