Skip to content

Commit

Permalink
Fix [Wizard] remove hasSteps logic (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan7empest authored Jun 15, 2022
1 parent ffe1628 commit 6a970a3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 55 deletions.
59 changes: 17 additions & 42 deletions src/lib/components/Wizard/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ const Wizard = ({
return React.Children.count(children) - 1 || 0
}, [children])

const hasSteps = useMemo(() => {
return stepsConfig.some((step) => step.id)
}, [stepsConfig])

const isLastStep = useMemo(() => {
return activeStepNumber === totalSteps
}, [activeStepNumber, totalSteps])
Expand All @@ -48,7 +44,7 @@ const Wizard = ({
return stepsConfig?.map((step) => ({ id: step.id, label: step.label })) || []
}, [stepsConfig])

const wizardClasses = classNames('wizard-form', className, hasSteps && 'wizard-form__with-steps')
const wizardClasses = classNames('wizard-form', className)

const goToNextStep = () => {
setActiveStepNumber((prevStep) => Math.min(++prevStep, totalSteps))
Expand Down Expand Up @@ -91,36 +87,21 @@ const Wizard = ({
}
}

const getDefaultActions = () => {
if (hasSteps) {
return [
<Button
onClick={goToPreviousStep}
disabled={activeStepNumber === 0}
label="Back"
type="button"
/>,
<Button
onClick={handleSubmit}
disabled={FormState.submitting || (FormState.invalid && FormState.submitFailed)}
label={isLastStep ? submitButtonLabel : 'Next'}
type="button"
variant={SECONDARY_BUTTON}
/>
]
} else {
return [
<Button onClick={handleOnClose} label="Cancel" type="button" />,
<Button
onClick={handleSubmit}
disabled={FormState.submitting || (FormState.invalid && FormState.submitFailed)}
label={submitButtonLabel}
type="button"
variant={SECONDARY_BUTTON}
/>
]
}
}
const getDefaultActions = () => [
<Button
onClick={goToPreviousStep}
disabled={activeStepNumber === 0}
label="Back"
type="button"
/>,
<Button
onClick={handleSubmit}
disabled={FormState.submitting || (FormState.invalid && FormState.submitFailed)}
label={isLastStep ? submitButtonLabel : 'Next'}
type="button"
variant={SECONDARY_BUTTON}
/>
]

const renderModalActions = () => {
if (stepsConfig[activeStepNumber]?.getActions) {
Expand All @@ -147,13 +128,7 @@ const Wizard = ({
size={size}
title={title}
>
{hasSteps && (
<WizardSteps
activeStepNumber={activeStepNumber}
jumpToStep={jumpToStep}
steps={stepsMenu}
/>
)}
<WizardSteps activeStepNumber={activeStepNumber} jumpToStep={jumpToStep} steps={stepsMenu} />
<div className="wizard-form__content">{activeStepTemplate}</div>
</Modal>
)
Expand Down
24 changes: 11 additions & 13 deletions src/lib/components/Wizard/Wizard.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
.wizard-form {
&__with-steps {
.modal__body {
display: flex;
flex-flow: row nowrap;
overflow: hidden;
padding-right: 0;
}
.modal__body {
display: flex;
flex-flow: row nowrap;
overflow: hidden;
padding-right: 0;
}

.wizard-form__content {
overflow-y: auto;
height: 100%;
width: 100%;
padding-right: 2rem;
}
.wizard-form__content {
overflow-y: auto;
height: 100%;
width: 100%;
padding-right: 2rem;
}
}

0 comments on commit 6a970a3

Please sign in to comment.