File tree Expand file tree Collapse file tree 3 files changed +29
-14
lines changed
docs/client/components/PlaygroundPage/PlaygroundWithPreview Expand file tree Collapse file tree 3 files changed +29
-14
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,25 @@ class Playground extends React.Component {
23
23
theme : 'custom' ,
24
24
readOnly : false ,
25
25
} ) ;
26
+ this . editor . on ( 'change' , this . handleChange ) ;
26
27
}
28
+
29
+ componentDidUpdate ( prevProps ) {
30
+ if ( this . props . code !== prevProps . code ) {
31
+ this . editor . setValue ( this . props . code ) ;
32
+ }
33
+ }
34
+
35
+ setCode = ( code ) => {
36
+ this . editor . getDoc ( ) . setValue ( code ) ;
37
+ this . handleChange ( ) ;
38
+ }
39
+
40
+ handleChange = ( ) => {
41
+ console . log ( 'changed ' , this . editor . getValue ( ) ) ;
42
+ this . props . onChange ( this . editor . getValue ( ) ) ;
43
+ } ;
44
+
27
45
28
46
render ( ) {
29
47
return (
Original file line number Diff line number Diff line change @@ -80,17 +80,6 @@ class Preview extends React.Component {
80
80
</ div >
81
81
) ;
82
82
}
83
-
84
- // render() {
85
- // return (
86
- // <div className={styles.preview}>
87
- // <div className="header">
88
- // Preview
89
- // </div>
90
- // {code}
91
- // </div>
92
- // );
93
- // }
94
83
}
95
84
96
85
Preview . propTypes = {
Original file line number Diff line number Diff line change @@ -19,7 +19,15 @@ const defaultCode = `
19
19
class PlaygroundWithPreview extends React . Component {
20
20
constructor ( props ) {
21
21
super ( props ) ;
22
- this . state = { } ;
22
+ this . state = {
23
+ code : defaultCode ,
24
+ } ;
25
+ }
26
+
27
+ handleOnChangeCode = ( code ) => {
28
+ this . setState ( {
29
+ code,
30
+ } ) ;
23
31
}
24
32
25
33
render ( ) {
@@ -32,13 +40,13 @@ class PlaygroundWithPreview extends React.Component {
32
40
< div className = "header" >
33
41
PlaygroundWithPreview
34
42
</ div >
35
-
36
43
< div >
37
44
< Playground
38
45
code = { defaultCode }
46
+ onChange = { this . handleOnChangeCode }
39
47
/>
40
48
< Preview
41
- code = { defaultCode }
49
+ code = { this . state . code }
42
50
/>
43
51
</ div >
44
52
{ activeComponent }
You can’t perform that action at this time.
0 commit comments