Skip to content

Commit 537c015

Browse files
committed
Update wizard docs to contain new changes
1 parent 76b0ab1 commit 537c015

File tree

4 files changed

+73
-133
lines changed

4 files changed

+73
-133
lines changed

packages/react-renderer-demo/src/doc-components/examples-texts/blueprint/blueprint-wizard.md

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import CommonWizard from '../wizard.md';
2+
13
This a custom component. OnSubmit will send only values from visited steps.
24

35
**Props**
@@ -34,30 +36,4 @@ You can rewrite only selection of them, e.g.
3436

3537
(Others will stay default)
3638

37-
**Docs for steps**
38-
39-
| Props | Type | Description |
40-
| ------------- | ------------- | ------------- |
41-
| name | string, number | Name of the step |
42-
| nextStep | object/stepKey of next step/function | See below |
43-
| fields | array | As usual |
44-
45-
- nextStep can be name of the next step
46-
- or you can branch the way by using of object:
47-
48-
```jsx
49-
nextStep: {
50-
when: 'source-type', // name of field, where deciding value is stored
51-
stepMapper: {
52-
aws: 'aws', // value: 'name' of next step
53-
google: 'google',
54-
...
55-
},
56-
},
57-
```
58-
59-
- 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.
60-
61-
```jsx
62-
nextStep: ({ values }) => (values.aws === '123' &&& values.password === 'secret') ? 'secretStep' : 'genericStep'
63-
```
39+
<CommonWizard />

packages/react-renderer-demo/src/doc-components/examples-texts/pf3/pf3-wizard.md

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import CommonWizard from '../wizard.md';
2+
13
This a custom component. OnSubmit will send only values from visited steps.
24

35
**Props**
@@ -43,27 +45,7 @@ You can rewrite only selection of them, e.g.
4345

4446
![image](https://user-images.githubusercontent.com/32869456/52336077-393c4e00-2a04-11e9-9aad-d591515cdba6.png)
4547

46-
**Docs for steps**
47-
48-
| Props | Type | Description |
49-
| ------------- | ------------- | ------------- |
50-
| stepKey | string, number | For first step: 1, otherwise anything |
51-
| nextStep | object/stepKey of next step | See below |
52-
| fields | array | As usual |
53-
54-
- nextStep can be stepKey of the next step
55-
- or you can branch the way by using of object:
56-
57-
```jsx
58-
nextStep: {
59-
when: 'source-type', // name of field, where deciding value is stored
60-
stepMapper: {
61-
aws: 'aws', // value: 'stepKey' of next step
62-
google: 'google',
63-
...
64-
},
65-
},
66-
```
48+
<CommonWizard />
6749

6850
**Useful links**
6951

packages/react-renderer-demo/src/doc-components/examples-texts/pf4/pf4-wizard.md

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import CommonWizard from '../wizard.md';
2+
13
This a custom component. OnSubmit will send only values from visited steps.
24

35
Don't forget hide form controls by setting \`showFormControls\` to \`false\` as a prop of the renderer component.
@@ -43,40 +45,7 @@ With the help of `crossroads` you can manually defined which fields change next
4345

4446
Ex.: `crossroads: ['name', 'nested.password']`
4547

46-
**Docs for steps**
47-
48-
| Props | Type | Description |
49-
| ------------- | ------------- | ------------- |
50-
| name | string, number | For first step: 1, otherwise anything |
51-
| nextStep | object/name of next step | See below |
52-
| fields | array | As usual |
53-
| substepOf | string | Substep title (steps are grouped by this title) |
54-
| title | string | Step title |
55-
| buttons | node, func | Custom buttons component|
56-
|showTitle|bool|If true, step titles will (not if false) be shown in the wizard body|
57-
|customTitle|node|Use if you want to render as the title different/custom title (for example, title with a popover|
58-
|disableForwardJumping|bool|When use return to this step, jumping forward in the navigation is disabled.|
59-
60-
61-
- nextStep can be name of the next step
62-
- or you can branch the way by using of object:
63-
64-
```jsx
65-
nextStep: {
66-
when: 'source-type', // name of field, where deciding value is stored
67-
stepMapper: {
68-
aws: 'aws', // value: 'name' of next step
69-
google: 'google',
70-
...
71-
},
72-
},
73-
```
74-
75-
- 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.
76-
77-
```jsx
78-
nextStep: ({ values }) => (values.aws === '123' &&& values.password === 'secret') ? 'secretStep' : 'genericStep'
79-
```
48+
<CommonWizard />
8049

8150
**Buttons**
8251

Lines changed: 64 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,91 @@
1-
This a custom component. OnSubmit will send only values from visited steps.
1+
**Docs for steps**
22

3-
**Props**
3+
|Props|Type|Description|
4+
|----|-------------|----------------|
5+
|name|string,number|Name of the step|
6+
|nextStep|object/stepKey of next step/function|See below|
7+
|fields|array|As usual|
48

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 |
9+
**nextStep**
1310

14-
**Default buttonLabels**
11+
A) **string** - no branching, name of the next step
1512

1613
```jsx
1714
{
18-
cancel: 'Cancel',
19-
back: 'Back',
20-
next: 'Next',
21-
submit: 'Submit',
15+
nextStep: 'next-step-name'
2216
}
2317
```
2418

25-
You can rewrite only selection of them, e.g.
19+
B) **object** - simple branching
2620

2721
```jsx
28-
{
29-
submit: 'Deploy',
30-
}
22+
nextStep: {
23+
when: 'source-type',
24+
stepMapper: {
25+
aws: 'aws-step',
26+
google: 'google-step',
27+
...
28+
},
29+
},
3130
```
3231

33-
(Others will stay default)
32+
i.e.: When `source-type` is `asw` go to to the `aws-step`.
3433

35-
**Format of stepsInfo**
34+
C) **function** - complex branching
3635

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|
36+
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.
4237

4338
```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-
],
39+
nextStep: ({ values }) => (values.aws === '123' &&& values.password === 'secret') ? 'secretStep' : 'genericStep'
5040
```
5141

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 |
42+
**initialState**
5943

60-
- nextStep can be name of the next step
61-
- or you can branch the way by using of object:
44+
It is possible to set the initial state of the wizard component. This can be useful when an application returns users to a specific step.
6245

6346
```jsx
64-
nextStep: {
65-
when: 'source-type', // name of field, where deciding value is stored
66-
stepMapper: {
67-
aws: 'aws', // value: 'name' of next step
68-
google: 'google',
69-
...
70-
},
71-
},
47+
{
48+
component: 'wizard',
49+
..., // fields, etc.
50+
initialState: {
51+
activeStep: 'second-step', // name of the active step
52+
activeStepIndex: 1, // active index
53+
maxStepIndex: 1, // max achieved index
54+
prevSteps: ['first-step'], // array with names of previously visited steps
55+
registeredFieldsHistory: { 'first-step': ['field'] }
56+
// array of registered fields for each visited step
57+
// only values from registered fields will be submitted
58+
}
59+
}
7260
```
7361

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.
62+
How to get the state from existing wizard? The state is passed to both `onCancel` and `onSubmit`:
63+
64+
A) `onSubmit` - `(values, formApi, wizardState) => ...`
65+
B) `onCancel` - `(values, wizardState) => ...`
66+
67+
**WizardContext**
68+
69+
Wizard share its configuration and props via `WizardContext`.
7570

7671
```jsx
77-
nextStep: ({ values }) => (values.aws === '123' &&& values.password === 'secret') ? 'secretStep' : 'genericStep'
72+
import { WizardContext } from '@data-driven-forms/react-form-renderer';
73+
74+
const {
75+
crossroads, // variables changing the navigation
76+
formOptions, // modified formOptions with submit and cancel handlers
77+
currentStep, // curent step object
78+
handlePrev, // going back in the wizard
79+
onKeyDown, // overrides form onKeyDown event for the wizard
80+
jumpToStep, // jump to step, jumpToStep(index, formOptions.valid)
81+
setPrevSteps, // rewrites the nav schema, use to change the navigation
82+
handleNext, // jumps to the nextStep: handleNext(nextStep)
83+
navSchema, // internal object representing the schema of current wizard flow
84+
activeStepIndex, // active index of the step
85+
maxStepIndex, // maximal achieved step
86+
isDynamic, // if form is dynamic (= it is branching steps)
87+
prevSteps // array with names of previous steps
88+
} = useContext(WizardContext);
7889
```
90+
91+
*This API is subject to change. If you implement custom components using these variables and functions, make sure that it is fully tested to prevent bugs when updating.*

0 commit comments

Comments
 (0)