File tree 2 files changed +16
-6
lines changed
2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -15,10 +15,19 @@ class Demo extends Component {
15
15
return < div >
16
16
< h1 > react-props-editor Demo</ h1 >
17
17
< div > -----Prop Names-------</ div >
18
- < ReactPropsEditor onChange = { ( { propValues} ) => {
18
+ < ReactPropsEditor
19
+ onChange = { ( { propValues} ) => {
19
20
this . setState ( { propValues} )
20
- } } propObjects = { {
21
- name : PropObjects . string ,
21
+ } }
22
+ defaultValues = { {
23
+ name : 'sdfwer'
24
+ } }
25
+ propObjects = { {
26
+ name : PropObjects . string . render (
27
+ ( { onChange, propValues} ) => {
28
+ return < input type = 'text' value = { propValues . name }
29
+ onChange = { e => onChange ( e . target . value ) } />
30
+ } ) ,
22
31
location : PropObjects . string . render ( ( {
23
32
onChange,
24
33
propValues
Original file line number Diff line number Diff line change @@ -27,8 +27,8 @@ function toJsonOpts(options){
27
27
} )
28
28
}
29
29
30
- function cleanState ( state ) {
31
- const changedProps = Object . assign ( { } , state ) ;
30
+ function cleanState ( state , defaultValues ) {
31
+ const changedProps = Object . assign ( { } , defaultValues , state ) ;
32
32
delete changedProps . propsTypes ;
33
33
delete changedProps . propsTypeOptions ;
34
34
delete changedProps . propsTypeRender ;
@@ -70,6 +70,7 @@ export default class PropsEditor extends Component {
70
70
}
71
71
72
72
render ( ) {
73
+ const { defaultValues } = this . props ;
73
74
const { propsTypes, propsTypeOptions, propsTypeRender } = this . state ;
74
75
if ( ! propsTypes ) {
75
76
return < div > loading...</ div >
@@ -90,7 +91,7 @@ export default class PropsEditor extends Component {
90
91
await this . setState ( { [ pKey ] :value } ) ;
91
92
return this . triggerChange ( )
92
93
} ,
93
- propValues :cleanState ( this . state )
94
+ propValues :cleanState ( this . state , defaultValues )
94
95
} ) } </ div >
95
96
} ) }
96
97
</ div >
You can’t perform that action at this time.
0 commit comments