1- import React , { cloneElement } from 'react' ;
1+ import React from 'react' ;
22import PropTypes from 'prop-types' ;
3- import WizardStep from './wizard/wizard-step' ;
4- import { Grid , Typography } from '@material-ui/core' ;
5- import Wizard , { wizardProps } from '@data-driven-forms/common/src/wizard/wizard' ;
3+ import clsx from 'clsx' ;
4+
5+ import { Grid } from '@material-ui/core' ;
6+ import { makeStyles } from '@material-ui/core/styles' ;
7+
8+ import Wizard from '@data-driven-forms/common/src/wizard/wizard' ;
9+ import WizardNav from './wizard/wizard-nav' ;
10+ import WizardStepButtons from './wizard/step-buttons' ;
11+
12+ const useStyles = makeStyles ( ( ) => ( {
13+ wizardBody : {
14+ padding : 24 ,
15+ margin : 0
16+ }
17+ } ) ) ;
18+
19+ const WizardInternal = ( {
20+ currentStep,
21+ formOptions,
22+ activeStepIndex,
23+ prevSteps,
24+ handleNext,
25+ handlePrev,
26+ buttonLabels,
27+ stepsInfo,
28+ ButtonContainerProps,
29+ StepperProps,
30+ WizardBodyProps,
31+ WizardProps,
32+ onKeyDown
33+ } ) => {
34+ const classes = useStyles ( ) ;
635
7- const WizardInternal = ( { title, description, currentStep, formOptions, prevSteps, handleNext, handlePrev, buttonLabels } ) => {
836 const buttonLabelsFinal = {
937 next : 'Continue' ,
1038 submit : 'Submit' ,
@@ -13,30 +41,56 @@ const WizardInternal = ({ title, description, currentStep, formOptions, prevStep
1341 ...buttonLabels
1442 } ;
1543
16- const step = < WizardStep { ...currentStep } formOptions = { formOptions } buttonLabels = { buttonLabelsFinal } /> ;
17-
1844 return (
19- < Grid container spacing = { 6 } >
20- < Grid item xs = { 12 } >
21- < Typography component = "h3" > { title } </ Typography >
22- < Typography paragraph > { description } </ Typography >
23- < Typography component = "h5" > { `Step ${ prevSteps . length + 1 } ` } </ Typography >
24- </ Grid >
25- < Grid item xs = { 12 } >
26- { cloneElement ( step , {
27- handleNext,
28- handlePrev,
29- disableBack : prevSteps . length === 0
30- } ) }
45+ < Grid container spacing = { 3 } { ...WizardProps } onKeyDown = { onKeyDown } >
46+ { stepsInfo && < WizardNav StepperProps = { StepperProps } stepsInfo = { stepsInfo } activeStepIndex = { activeStepIndex } /> }
47+ < Grid container spacing = { 2 } { ...WizardBodyProps } className = { clsx ( classes . wizardBody , WizardBodyProps . className ) } >
48+ { currentStep . fields . map ( ( item ) => formOptions . renderForm ( [ item ] , formOptions ) ) }
49+ < WizardStepButtons
50+ { ...currentStep }
51+ formOptions = { formOptions }
52+ buttonLabels = { buttonLabelsFinal }
53+ handleNext = { handleNext }
54+ handlePrev = { handlePrev }
55+ disableBack = { prevSteps . length === 0 }
56+ ButtonContainerProps = { ButtonContainerProps }
57+ />
3158 </ Grid >
3259 </ Grid >
3360 ) ;
3461} ;
3562
3663WizardInternal . propTypes = {
37- title : PropTypes . node ,
38- description : PropTypes . node ,
39- ...wizardProps
64+ currentStep : PropTypes . object ,
65+ handlePrev : PropTypes . func ,
66+ onKeyDown : PropTypes . func ,
67+ jumpToStep : PropTypes . func ,
68+ setPrevSteps : PropTypes . func ,
69+ handleNext : PropTypes . func ,
70+ activeStepIndex : PropTypes . number ,
71+ formOptions : PropTypes . shape ( {
72+ onCancel : PropTypes . func ,
73+ renderForm : PropTypes . func
74+ } ) ,
75+ prevSteps : PropTypes . array ,
76+ // ^^ common props
77+ buttonLabels : PropTypes . object ,
78+ stepsInfo : PropTypes . arrayOf (
79+ PropTypes . shape ( {
80+ title : PropTypes . node ,
81+ label : PropTypes . node ,
82+ StepLabelProps : PropTypes . object ,
83+ StepProps : PropTypes . object
84+ } )
85+ ) ,
86+ ButtonContainerProps : PropTypes . object ,
87+ StepperProps : PropTypes . object ,
88+ WizardBodyProps : PropTypes . object ,
89+ WizardProps : PropTypes . object
90+ } ;
91+
92+ WizardInternal . defaultProps = {
93+ WizardBodyProps : { }
4094} ;
4195
4296const MuiWizard = ( props ) => < Wizard Wizard = { WizardInternal } { ...props } /> ;
0 commit comments