1
- import React , { Component } from 'react' ;
2
- import { withStyles } from '@material-ui/core/styles' ;
3
- import Tabs from '@material-ui/core/Tabs' ;
4
- import Tab from '@material-ui/core/Tab' ;
5
- import Tree from 'react-d3-tree' ;
6
- import Props from './Props.jsx' ;
7
- import HtmlAttr from './HtmlAttr.jsx' ;
8
- import CodePreview from './CodePreview.tsx' ;
1
+ import React , { Component } from "react" ;
2
+ import { withStyles } from "@material-ui/core/styles" ;
3
+ import Tabs from "@material-ui/core/Tabs" ;
4
+ import Tab from "@material-ui/core/Tab" ;
5
+ import Tree from "react-d3-tree" ;
6
+ import Props from "./Props.tsx" ;
7
+ import HtmlAttr from "./HtmlAttr.tsx" ;
8
+ import CodePreview from "./CodePreview.tsx" ;
9
+ import { ComponentInt , ComponentsInt , ChildInt } from "../utils/interfaces" ;
9
10
// import Tree from "./Tree.jsx";
10
11
11
- const styles = theme => ( {
12
+ interface PropsInt {
13
+ focusChild : ChildInt ;
14
+ components : ComponentsInt ;
15
+ focusComponent : ComponentInt ;
16
+ deleteProp : any ;
17
+ addProp : any ;
18
+ classes : any ;
19
+ }
20
+
21
+ // interface TreeAttributesInt {
22
+ // key: string;
23
+ // value: string;
24
+ // }
25
+
26
+ interface TreeInt {
27
+ name : string ;
28
+ attributes : { [ key : string ] : { value : string } } ;
29
+ children : TreeInt [ ] ;
30
+ }
31
+
32
+ const styles = ( theme : any ) : any => ( {
12
33
root : {
13
34
flexGrow : 1 ,
14
35
// backgroundColor: "#212121",
15
- backgroundColor : ' #333333' ,
16
- height : ' 100%' ,
17
- color : ' #fff' ,
18
- boxShadow : ' 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)' ,
36
+ backgroundColor : " #333333" ,
37
+ height : " 100%" ,
38
+ color : " #fff" ,
39
+ boxShadow : " 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)"
19
40
} ,
20
41
tabsRoot : {
21
- borderBottom : ' 0.5px solid #424242' ,
42
+ borderBottom : " 0.5px solid #424242"
22
43
// backgroundColor: "#424242"
23
44
} ,
24
45
tabsIndicator : {
25
- backgroundColor : ' #1de9b6' ,
46
+ backgroundColor : " #1de9b6"
26
47
} ,
27
48
tabRoot : {
28
- textTransform : ' initial' ,
49
+ textTransform : " initial" ,
29
50
minWidth : 72 ,
30
51
fontWeight : theme . typography . fontWeightRegular ,
31
52
marginRight : theme . spacing . unit * 4 ,
32
53
33
54
fontFamily : [
34
- ' -apple-system' ,
35
- ' BlinkMacSystemFont' ,
55
+ " -apple-system" ,
56
+ " BlinkMacSystemFont" ,
36
57
'"Segoe UI"' ,
37
- ' Roboto' ,
58
+ " Roboto" ,
38
59
'"Helvetica Neue"' ,
39
- ' Arial' ,
40
- ' sans-serif' ,
60
+ " Arial" ,
61
+ " sans-serif" ,
41
62
'"Apple Color Emoji"' ,
42
63
'"Segoe UI Emoji"' ,
43
- '"Segoe UI Symbol"' ,
44
- ] . join ( ',' ) ,
45
- '&:hover' : {
46
- color : '#1de9b6' ,
47
- opacity : 1 ,
48
- } ,
49
- '&$tabSelected' : {
50
- color : '#33eb91' ,
51
- fontWeight : theme . typography . fontWeightMedium ,
64
+ '"Segoe UI Symbol"'
65
+ ] . join ( "," ) ,
66
+ "&:hover" : {
67
+ color : "#1de9b6" ,
68
+ opacity : 1
52
69
} ,
53
- '&:focus' : {
54
- color : '#4aedc4' ,
70
+ "&$tabSelected" : {
71
+ color : "#33eb91" ,
72
+ fontWeight : theme . typography . fontWeightMedium
55
73
} ,
74
+ "&:focus" : {
75
+ color : "#4aedc4"
76
+ }
56
77
} ,
57
78
tabSelected : { } ,
58
79
typography : {
59
- padding : theme . spacing . unit * 3 ,
80
+ padding : theme . spacing . unit * 3
60
81
} ,
61
82
padding : {
62
- padding : `0 ${ theme . spacing . unit * 2 } px` ,
63
- } ,
83
+ padding : `0 ${ theme . spacing . unit * 2 } px`
84
+ }
64
85
} ) ;
65
86
66
- class BottomTabs extends Component {
87
+ class BottomTabs extends Component < PropsInt > {
67
88
state = {
68
- value : 0 ,
89
+ value : 0
69
90
} ;
70
91
71
92
componentDidMount ( ) {
@@ -74,49 +95,55 @@ class BottomTabs extends Component {
74
95
this . setState ( {
75
96
translate : {
76
97
x : dimensions . width / 12 ,
77
- y : dimensions . height / 2.2 ,
78
- } ,
98
+ y : dimensions . height / 2.2
99
+ }
79
100
} ) ;
80
101
}
81
102
82
- handleChange = ( event , value ) => {
103
+ handleChange = ( event : any , value : number ) => {
83
104
this . setState ( { value } ) ;
84
105
} ;
85
106
86
- findChildren ( component , components , tree ) {
107
+ findChildren ( component : ComponentInt , components : ComponentsInt , tree : any ) {
87
108
if ( ! component . childrenArray . length ) {
88
109
return tree ;
89
110
}
90
111
const newChildrenArray = [ ] ;
91
112
92
113
for ( let i = 0 ; i < component . childrenArray . length ; i ++ ) {
93
114
const name = component . childrenArray [ i ] . componentName ;
94
- const newTree = {
115
+ const newTree : TreeInt = {
95
116
name,
96
117
attributes : { } ,
97
- children : [ ] ,
118
+ children : [ ]
98
119
} ;
99
120
newChildrenArray . push ( newTree ) ;
100
121
tree . children = newChildrenArray ;
101
- if ( component . childrenArray [ i ] . childType === ' COMP' ) {
122
+ if ( component . childrenArray [ i ] . childType === " COMP" ) {
102
123
const newFocusComp = components . find (
103
- comp => comp . title === component . childrenArray [ i ] . componentName ,
124
+ comp => comp . title === component . childrenArray [ i ] . componentName
104
125
) ;
105
126
this . findChildren ( newFocusComp , components , newTree ) ;
106
127
}
107
128
}
108
129
return tree ;
109
130
}
110
131
111
- generateComponentTree ( componentId , components ) {
132
+ generateComponentTree ( componentId : number , components : ComponentsInt ) {
112
133
const component = components . find ( comp => comp . id === componentId ) ;
113
134
const tree = { name : component . title , attributes : { } , children : [ ] } ;
114
135
115
- component . childrenArray . forEach ( ( child ) => {
116
- if ( child . childType === 'COMP' ) {
117
- tree . children . push ( this . generateComponentTree ( child . childComponentId , components ) ) ;
136
+ component . childrenArray . forEach ( child => {
137
+ if ( child . childType === "COMP" ) {
138
+ tree . children . push (
139
+ this . generateComponentTree ( child . childComponentId , components )
140
+ ) ;
118
141
} else {
119
- tree . children . push ( { name : child . componentName , attributes : { } , children : [ ] } ) ;
142
+ tree . children . push ( {
143
+ name : child . componentName ,
144
+ attributes : { } ,
145
+ children : [ ]
146
+ } ) ;
120
147
}
121
148
} ) ;
122
149
return tree ;
@@ -129,21 +156,22 @@ class BottomTabs extends Component {
129
156
focusComponent,
130
157
deleteProp,
131
158
addProp,
132
- focusChild,
159
+ focusChild
133
160
// rightColumnOpen
134
161
} = this . props ;
135
162
const { value } = this . state ;
136
163
137
164
// display count on the tab. user can see without clicking into tab
138
165
const propCount = focusComponent . props . length ;
139
- const htmlAttribCount = focusComponent . childrenArray . filter ( child => child . childType === 'HTML' )
140
- . length ;
166
+ const htmlAttribCount = focusComponent . childrenArray . filter (
167
+ child => child . childType === "HTML"
168
+ ) . length ;
141
169
142
170
// const counters = focusComponent.ch
143
171
const tree = {
144
172
name : focusComponent . title ,
145
173
attributes : { } ,
146
- children : [ ] ,
174
+ children : [ ]
147
175
} ;
148
176
149
177
return (
@@ -166,12 +194,14 @@ class BottomTabs extends Component {
166
194
< Tab
167
195
disableRipple
168
196
classes = { { root : classes . tabRoot , selected : classes . tabSelected } }
169
- label = { `Component Props ${ propCount ? `(${ propCount } )` : '' } ` }
197
+ label = { `Component Props ${ propCount ? `(${ propCount } )` : "" } ` }
170
198
/>
171
199
< Tab
172
200
disableRipple
173
201
classes = { { root : classes . tabRoot , selected : classes . tabSelected } }
174
- label = { `HTML Element Attributes ${ htmlAttribCount ? `(${ htmlAttribCount } )` : '' } ` }
202
+ label = { `HTML Element Attributes ${
203
+ htmlAttribCount ? `(${ htmlAttribCount } )` : ""
204
+ } `}
175
205
/>
176
206
{ /* <Tab
177
207
disableRipple
@@ -184,8 +214,8 @@ class BottomTabs extends Component {
184
214
< div
185
215
id = "treeWrapper"
186
216
style = { {
187
- width : ' 100%' ,
188
- height : ' 100%' ,
217
+ width : " 100%" ,
218
+ height : " 100%"
189
219
} }
190
220
ref = { node => ( this . treeWrapper = node ) }
191
221
>
@@ -199,30 +229,35 @@ class BottomTabs extends Component {
199
229
nodes : {
200
230
node : {
201
231
name : {
202
- fill : ' #D3D3D3' ,
203
- stroke : ' #D3D3D3' ,
204
- strokeWidth : 1 ,
205
- } ,
232
+ fill : " #D3D3D3" ,
233
+ stroke : " #D3D3D3" ,
234
+ strokeWidth : 1
235
+ }
206
236
} ,
207
237
leafNode : {
208
238
name : {
209
- fill : ' #D3D3D3' ,
210
- stroke : ' #D3D3D3' ,
211
- strokeWidth : 1 ,
212
- } ,
213
- } ,
214
- } ,
239
+ fill : " #D3D3D3" ,
240
+ stroke : " #D3D3D3" ,
241
+ strokeWidth : 1
242
+ }
243
+ }
244
+ }
215
245
} }
216
246
/>
217
247
</ div >
218
248
) }
219
- { value === 1 && < CodePreview focusComponent = { focusComponent } components = { components } /> }
249
+ { value === 1 && (
250
+ < CodePreview
251
+ focusComponent = { focusComponent }
252
+ components = { components }
253
+ />
254
+ ) }
220
255
{ value === 2 && < Props /> }
221
- { value === 3 && focusChild . childType === ' HTML' && < HtmlAttr /> }
222
- { value === 3
223
- && focusChild . childType !== ' HTML' && (
256
+ { value === 3 && focusChild . childType === " HTML" && < HtmlAttr /> }
257
+ { value === 3 &&
258
+ focusChild . childType !== " HTML" && (
224
259
< p > Please select an HTML element to view attributes</ p >
225
- ) }
260
+ ) }
226
261
</ div >
227
262
) ;
228
263
}
0 commit comments