1
1
import React , { useState } from 'react' ;
2
2
import FormRenderer from '@data-driven-forms/react-form-renderer/dist/cjs/form-renderer' ;
3
+ import useFormApi from '@data-driven-forms/react-form-renderer/dist/cjs/use-form-api' ;
3
4
import componentTypes from '@data-driven-forms/react-form-renderer/dist/cjs/component-types' ;
4
5
import FormTemplate from '@data-driven-forms/pf4-component-mapper/dist/cjs/form-template' ;
5
6
import TextField from '@data-driven-forms/pf4-component-mapper/dist/cjs/text-field' ;
@@ -10,14 +11,20 @@ import { Title } from '@patternfly/react-core/dist/js/components/Title/Title';
10
11
const componentMapper = {
11
12
[ componentTypes . TEXT_FIELD ] : TextField ,
12
13
[ componentTypes . WIZARD ] : Wizard ,
13
- [ componentTypes . SELECT ] : Select
14
+ [ componentTypes . SELECT ] : Select ,
15
+ Summary : ( ) => {
16
+ const { getState } = useFormApi ( ) ;
17
+
18
+ return < Title size = "md" > { getState ( ) . values [ 'chosen-way' ] } </ Title > ;
19
+ }
14
20
} ;
15
21
16
22
const schema = {
17
23
fields : [
18
24
{
19
25
component : componentTypes . WIZARD ,
20
26
name : 'wizard' ,
27
+ crossroads : [ 'selection' ] ,
21
28
fields : [
22
29
{
23
30
title : 'Choose your way' ,
@@ -50,6 +57,10 @@ const schema = {
50
57
hideField : true ,
51
58
name : 'chosen-way' ,
52
59
initialValue : 'User chose the first way'
60
+ } ,
61
+ {
62
+ component : 'Summary' ,
63
+ name : 'summary'
53
64
}
54
65
]
55
66
} ,
@@ -63,6 +74,10 @@ const schema = {
63
74
hideField : true ,
64
75
name : 'chosen-way' ,
65
76
initialValue : 'User chose the second way'
77
+ } ,
78
+ {
79
+ component : 'Summary' ,
80
+ name : 'summary'
66
81
}
67
82
]
68
83
}
@@ -71,22 +86,23 @@ const schema = {
71
86
]
72
87
} ;
73
88
89
+ const FormTemplateWrapper = ( props ) => < FormTemplate { ...props } showFormControls = { false } /> ;
90
+
74
91
const InitializeOnMountWizardExample = ( ) => {
75
92
const [ values , setValues ] = useState ( { } ) ;
76
93
return (
77
94
< div className = "pf4" >
95
+ < div style = { { marginTop : 16 , marginBottom : 16 } } >
96
+ < Title size = "md" > Form values</ Title >
97
+ < pre > { JSON . stringify ( values , null , 2 ) } </ pre >
98
+ </ div >
78
99
< FormRenderer
79
- FormTemplate = { ( props ) => < FormTemplate { ... props } showFormControls = { false } /> }
100
+ FormTemplate = { FormTemplateWrapper }
80
101
componentMapper = { componentMapper }
81
102
schema = { schema }
82
103
onSubmit = { console . log }
83
104
debug = { ( { values } ) => setValues ( values ) }
84
- showFormControls = { false }
85
105
/>
86
- < div style = { { marginTop : 16 } } >
87
- < Title size = "md" > Form values</ Title >
88
- < pre > { JSON . stringify ( values , null , 2 ) } </ pre >
89
- </ div >
90
106
</ div >
91
107
) ;
92
108
} ;
0 commit comments