Skip to content

Commit 403bf1e

Browse files
committed
Add docs for MUI wizard enhanced
1 parent 06598c7 commit 403bf1e

File tree

3 files changed

+50
-21
lines changed

3 files changed

+50
-21
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const WizardInternal = ({
2828
ButtonContainerProps,
2929
StepperProps,
3030
WizardBodyProps,
31-
WizardProps
31+
WizardProps,
32+
onKeyDown
3233
}) => {
3334
const classes = useStyles();
3435

@@ -41,7 +42,7 @@ const WizardInternal = ({
4142
};
4243

4344
return (
44-
<Grid container spacing={3} {...WizardProps}>
45+
<Grid container spacing={3} {...WizardProps} onKeyDown={onKeyDown}>
4546
{stepsInfo && <WizardNav StepperProps={StepperProps} stepsInfo={stepsInfo} activeStepIndex={activeStepIndex} />}
4647
<Grid container spacing={2} {...WizardBodyProps} className={clsx(classes.wizardBody, WizardBodyProps.className)}>
4748
{currentStep.fields.map((item) => formOptions.renderForm([item], formOptions))}
@@ -60,29 +61,25 @@ const WizardInternal = ({
6061
};
6162

6263
WizardInternal.propTypes = {
63-
title: PropTypes.node,
64-
description: PropTypes.node,
6564
currentStep: PropTypes.object,
6665
handlePrev: PropTypes.func,
6766
onKeyDown: PropTypes.func,
6867
jumpToStep: PropTypes.func,
6968
setPrevSteps: PropTypes.func,
7069
handleNext: PropTypes.func,
71-
navSchema: PropTypes.array,
7270
activeStepIndex: PropTypes.number,
73-
maxStepIndex: PropTypes.number,
7471
formOptions: PropTypes.shape({
7572
onCancel: PropTypes.func,
7673
renderForm: PropTypes.func
7774
}),
7875
prevSteps: PropTypes.array,
76+
// ^^ common props
7977
buttonLabels: PropTypes.object,
8078
stepsInfo: PropTypes.arrayOf(
8179
PropTypes.shape({
8280
title: PropTypes.node,
8381
label: PropTypes.node,
84-
key: PropTypes.string,
85-
LabelProps: PropTypes.object,
82+
StepLabelProps: PropTypes.object,
8683
StepProps: PropTypes.object
8784
})
8885
),

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const WizardNav = ({ StepperProps, stepsInfo, activeStepIndex }) => {
1616

1717
return (
1818
<Stepper {...StepperProps} className={clsx(classes.stepper, StepperProps.className)} activeStep={activeStepIndex}>
19-
{stepsInfo.map(({ title, label, LabelProps, StepProps }, idx) => (
19+
{stepsInfo.map(({ title, label, StepLabelProps, StepProps }, idx) => (
2020
<Step {...StepProps} key={idx}>
21-
<StepLabel {...LabelProps}>{title || label}</StepLabel>
21+
<StepLabel {...StepLabelProps}>{title || label}</StepLabel>
2222
</Step>
2323
))}
2424
</Stepper>
@@ -31,8 +31,7 @@ WizardNav.propTypes = {
3131
PropTypes.shape({
3232
title: PropTypes.node,
3333
label: PropTypes.node,
34-
key: PropTypes.string,
35-
LabelProps: PropTypes.object,
34+
StepLabelProps: PropTypes.object,
3635
StepProps: PropTypes.object
3736
})
3837
),

packages/react-renderer-demo/src/app/src/doc-components/wizard.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
This a custom component. OnSubmit will send only values from visited steps.
22

3-
**Docs for steps**
3+
**Props**
44

5-
| Props | Type | Description |
6-
| ------------- | ------------- | ------------- |
7-
| stepKey | string, number | For first step: 1, otherwise anything |
8-
| buttonLabels | object | See below |
9-
| nextStep | object/stepKey of next step | See below |
10-
| fields | array | As usual |
5+
| Prop | Type | Default | Description |
6+
| ------------- | ------------- | ------------- | ------------- |
7+
| buttonLabels | object of nodes | see below | Labels for buttons |
8+
| stepsInfo | object | undefined | Information for building the stepper |
9+
| ButtonContainerProps | object | {} | Props passed to Grid wrapping buttons |
10+
| StepperProps | object | {} | Props passed to the Stepper component |
11+
| WizardBodyProps | object | {} | Props passed to Grid wrapping fields and the button container |
12+
| WizardProps | object | {} | Props passed to the root Grid |
1113

1214
**Default buttonLabels**
1315

@@ -30,16 +32,47 @@ You can rewrite only selection of them, e.g.
3032

3133
(Others will stay default)
3234

33-
- nextStep can be stepKey of the next step
35+
**Format of stepsInfo**
36+
37+
|Key|Type|Default|Description|
38+
|---|----|-------|-----------|
39+
|label/title|string|undefined|Text for the title|
40+
|StepLabelProps|object|{}|Props passed to StepLabel component|
41+
|StepProps|object|{}|Props passed to Step component|
42+
43+
```jsx
44+
[
45+
{ title: 'Add a source', StepLabelProps: { style: { color: 'red' } } }, // step 1
46+
{ title: 'Configure a source' }, // step 2
47+
{ title: 'Summary' }, // step 3
48+
...
49+
],
50+
```
51+
52+
**Docs for steps**
53+
54+
| Props | Type | Description |
55+
| ------------- | ------------- | ------------- |
56+
| name | string, number | Name of the step |
57+
| nextStep | object/stepKey of next step/function | See below |
58+
| fields | array | As usual |
59+
60+
- nextStep can be name of the next step
3461
- or you can branch the way by using of object:
3562

3663
```jsx
3764
nextStep: {
3865
when: 'source-type', // name of field, where deciding value is stored
3966
stepMapper: {
40-
aws: 'aws', // value: 'stepKey' of next step
67+
aws: 'aws', // value: 'name' of next step
4168
google: 'google',
4269
...
4370
},
4471
},
4572
```
73+
74+
- another option is to use custom function. The custom function receives as the first argument an object with values and the function has to return a `name` in string.
75+
76+
```jsx
77+
nextStep: ({ values }) => (values.aws === '123' &&& values.password === 'secret') ? 'secretStep' : 'genericStep'
78+
```

0 commit comments

Comments
 (0)