Skip to content

Commit c631624

Browse files
committed
feat(mui): allow to buttonLabels to wizard
1 parent a2a7d89 commit c631624

2 files changed

Lines changed: 31 additions & 13 deletions

File tree

packages/mui-component-mapper/src/files/wizard.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ import WizardStep from './wizard/wizard-step';
44
import { Grid, Typography } from '@material-ui/core';
55
import Wizard, { wizardProps } from '@data-driven-forms/common/src/wizard/wizard';
66

7-
const WizardInternal = ({ title, description, currentStep, formOptions, prevSteps, handleNext, handlePrev }) => {
8-
const step = <WizardStep {...currentStep} formOptions={formOptions} />;
7+
const WizardInternal = ({ title, description, currentStep, formOptions, prevSteps, handleNext, handlePrev, buttonLabels }) => {
8+
const buttonLabelsFinal = {
9+
next: 'Continue',
10+
submit: 'Submit',
11+
cancel: 'Cancel',
12+
back: 'Back',
13+
...buttonLabels
14+
};
15+
16+
const step = <WizardStep {...currentStep} formOptions={formOptions} buttonLabels={buttonLabelsFinal} />;
917

1018
return (
1119
<Grid container spacing={6}>

packages/mui-component-mapper/src/files/wizard/step-buttons.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import NavigateBackIcon from '@material-ui/icons/NavigateBefore';
66
import Send from '@material-ui/icons/Send';
77
import { useFieldApi } from '@data-driven-forms/react-form-renderer';
88

9-
const SimpleNext = ({ next, valid, handleNext, submit }) => (
9+
const SimpleNext = ({ next, valid, handleNext, submit, buttonLabels }) => (
1010
<Button variant="contained" type="button" color="primary" onClick={() => (valid ? handleNext(next) : submit())}>
11-
Continue
11+
{buttonLabels.next}
1212
<NavigateNextIcon />
1313
</Button>
1414
);
@@ -17,7 +17,10 @@ SimpleNext.propTypes = {
1717
next: PropTypes.string,
1818
valid: PropTypes.bool,
1919
handleNext: PropTypes.func.isRequired,
20-
submit: PropTypes.func.isRequired
20+
submit: PropTypes.func.isRequired,
21+
buttonLabels: PropTypes.shape({
22+
next: PropTypes.node
23+
})
2124
};
2225

2326
const ConditionalNext = ({ nextStep, ...rest }) => {
@@ -34,37 +37,38 @@ ConditionalNext.propTypes = {
3437
}).isRequired
3538
};
3639

37-
const submitButton = (handleSubmit) => (
40+
const submitButton = (handleSubmit, label) => (
3841
<Button type="button" variant="contained" color="primary" onClick={handleSubmit}>
39-
Submit <Send />
42+
{label} <Send />
4043
</Button>
4144
);
4245

4346
const renderNextButton = ({ nextStep, handleSubmit, ...rest }) =>
4447
!nextStep ? (
45-
submitButton(handleSubmit)
48+
submitButton(handleSubmit, rest.buttonLabels.submit)
4649
) : typeof nextStep === 'object' ? (
4750
<ConditionalNext nextStep={nextStep} {...rest} />
4851
) : (
4952
<SimpleNext next={nextStep} {...rest} />
5053
);
5154

52-
const WizardStepButtons = ({ formOptions, disableBack, handlePrev, nextStep, handleNext }) => (
55+
const WizardStepButtons = ({ formOptions, disableBack, handlePrev, nextStep, handleNext, buttonLabels }) => (
5356
<div>
5457
{formOptions.onCancel && (
5558
<Button type="button" variant="contained" color="secondary" onClick={formOptions.onCancel}>
56-
Cancel
59+
{buttonLabels.cancel}
5760
</Button>
5861
)}
5962

6063
<Button type="button" variant="contained" disabled={disableBack} onClick={handlePrev}>
6164
<NavigateBackIcon />
62-
Back
65+
{buttonLabels.back}
6366
</Button>
6467
{renderNextButton({
6568
...formOptions,
6669
handleNext,
67-
nextStep
70+
nextStep,
71+
buttonLabels
6872
})}
6973
</div>
7074
);
@@ -83,7 +87,13 @@ WizardStepButtons.propTypes = {
8387
when: PropTypes.string.isRequired,
8488
stepMapper: PropTypes.object.isRequired
8589
})
86-
])
90+
]),
91+
buttonLabels: PropTypes.shape({
92+
submit: PropTypes.node,
93+
cancel: PropTypes.node,
94+
back: PropTypes.node,
95+
next: PropTypes.node
96+
})
8797
};
8898

8999
export default WizardStepButtons;

0 commit comments

Comments
 (0)