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.ts" ;
1
+ import React , { Component } from ' react' ;
2
+ import { withStyles , Theme } 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' ;
7
+ import HtmlAttr from ' ./HtmlAttr' ;
8
+ import CodePreview from ' ./CodePreview' ;
9
+ import { ComponentInt , ComponentsInt , PropInt , PropsInt } from ' ../utils/Interfaces' ;
10
10
11
- interface PropsInt {
12
- focusChild : ChildInt ;
13
- components : ComponentsInt ;
14
- focusComponent : ComponentInt ;
15
- deleteProp : any ;
16
- addProp : any ;
11
+ interface BottomTabsPropsInt extends PropsInt {
12
+ deleteProp ( id : number ) : void ;
13
+ addProp ( prop : PropInt ) : void ;
17
14
classes : any ;
18
15
}
19
16
20
- interface TreeInt {
21
- name : string ;
22
- attributes : { [ key : string ] : { value : string } } ;
23
- children : TreeInt [ ] ;
17
+ // interface TreeInt {
18
+ // name: string;
19
+ // attributes: { [key: string]: { value: string } };
20
+ // children: TreeInt[];
21
+ // }
22
+
23
+ interface StateInt {
24
+ value : number ;
25
+ translate : { x : number ; y : number } ;
24
26
}
25
27
26
- const styles = ( theme : any ) : any => ( {
28
+ const styles = ( theme : Theme ) : any => ( {
27
29
root : {
28
30
flexGrow : 1 ,
29
- backgroundColor : " #333333" ,
30
- height : " 100%" ,
31
- color : " #fff" ,
32
- boxShadow : " 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)"
31
+ backgroundColor : ' #333333' ,
32
+ height : ' 100%' ,
33
+ color : ' #fff' ,
34
+ boxShadow : ' 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)'
33
35
} ,
34
36
tabsRoot : {
35
- borderBottom : " 0.5px solid #424242"
37
+ borderBottom : ' 0.5px solid #424242'
36
38
} ,
37
39
tabsIndicator : {
38
- backgroundColor : " #1de9b6"
40
+ backgroundColor : ' #1de9b6'
39
41
} ,
40
42
tabRoot : {
41
- textTransform : " initial" ,
43
+ textTransform : ' initial' ,
42
44
minWidth : 72 ,
43
45
fontWeight : theme . typography . fontWeightRegular ,
44
46
marginRight : theme . spacing . unit * 4 ,
45
47
46
48
fontFamily : [
47
- " -apple-system" ,
48
- " BlinkMacSystemFont" ,
49
+ ' -apple-system' ,
50
+ ' BlinkMacSystemFont' ,
49
51
'"Segoe UI"' ,
50
- " Roboto" ,
52
+ ' Roboto' ,
51
53
'"Helvetica Neue"' ,
52
- " Arial" ,
53
- " sans-serif" ,
54
+ ' Arial' ,
55
+ ' sans-serif' ,
54
56
'"Apple Color Emoji"' ,
55
57
'"Segoe UI Emoji"' ,
56
58
'"Segoe UI Symbol"'
57
- ] . join ( "," ) ,
58
- " &:hover" : {
59
- color : " #1de9b6" ,
59
+ ] . join ( ',' ) ,
60
+ ' &:hover' : {
61
+ color : ' #1de9b6' ,
60
62
opacity : 1
61
63
} ,
62
- " &$tabSelected" : {
63
- color : " #33eb91" ,
64
+ ' &$tabSelected' : {
65
+ color : ' #33eb91' ,
64
66
fontWeight : theme . typography . fontWeightMedium
65
67
} ,
66
- " &:focus" : {
67
- color : " #4aedc4"
68
+ ' &:focus' : {
69
+ color : ' #4aedc4'
68
70
}
69
71
} ,
70
72
tabSelected : { } ,
@@ -76,11 +78,15 @@ const styles = (theme: any): any => ({
76
78
}
77
79
} ) ;
78
80
79
- class BottomTabs extends Component < PropsInt > {
80
- state = {
81
- value : 0
82
- } ;
83
-
81
+ class BottomTabs extends Component < BottomTabsPropsInt , StateInt > {
82
+ constructor ( props : BottomTabsPropsInt ) {
83
+ super ( props ) ;
84
+ this . state = {
85
+ value : 0 ,
86
+ translate : { x : 0 , y : 0 }
87
+ } ;
88
+ }
89
+ treeWrapper : HTMLDivElement ;
84
90
componentDidMount ( ) {
85
91
// dynamically center the tree based on the div size
86
92
const dimensions = this . treeWrapper . getBoundingClientRect ( ) ;
@@ -98,13 +104,11 @@ class BottomTabs extends Component<PropsInt> {
98
104
99
105
generateComponentTree ( componentId : number , components : ComponentsInt ) {
100
106
const component = components . find ( comp => comp . id === componentId ) ;
101
- const tree = { name : component . title , attributes : { } , children : [ ] } ;
107
+ const tree : any = { name : component . title , attributes : { } , children : [ ] } ;
102
108
103
109
component . childrenArray . forEach ( child => {
104
- if ( child . childType === "COMP" ) {
105
- tree . children . push (
106
- this . generateComponentTree ( child . childComponentId , components )
107
- ) ;
110
+ if ( child . childType === 'COMP' ) {
111
+ tree . children . push ( this . generateComponentTree ( child . childComponentId , components ) ) ;
108
112
} else {
109
113
tree . children . push ( {
110
114
name : child . componentName ,
@@ -116,22 +120,14 @@ class BottomTabs extends Component<PropsInt> {
116
120
return tree ;
117
121
}
118
122
119
- render ( ) {
120
- const {
121
- classes,
122
- components,
123
- focusComponent,
124
- deleteProp,
125
- addProp,
126
- focusChild
127
- } = this . props ;
123
+ render ( ) : JSX . Element {
124
+ const { classes, components, focusComponent, deleteProp, addProp, focusChild } = this . props ;
128
125
const { value } = this . state ;
129
126
130
127
// display count on the tab. user can see without clicking into tab
131
128
const propCount = focusComponent . props . length ;
132
- const htmlAttribCount = focusComponent . childrenArray . filter (
133
- child => child . childType === "HTML"
134
- ) . length ;
129
+ const htmlAttribCount = focusComponent . childrenArray . filter ( child => child . childType === 'HTML' )
130
+ . length ;
135
131
136
132
return (
137
133
< div className = { classes . root } >
@@ -153,14 +149,12 @@ class BottomTabs extends Component<PropsInt> {
153
149
< Tab
154
150
disableRipple
155
151
classes = { { root : classes . tabRoot , selected : classes . tabSelected } }
156
- label = { `Component Props ${ propCount ? `(${ propCount } )` : "" } ` }
152
+ label = { `Component Props ${ propCount ? `(${ propCount } )` : '' } ` }
157
153
/>
158
154
< Tab
159
155
disableRipple
160
156
classes = { { root : classes . tabRoot , selected : classes . tabSelected } }
161
- label = { `HTML Element Attributes ${
162
- htmlAttribCount ? `(${ htmlAttribCount } )` : ""
163
- } `}
157
+ label = { `HTML Element Attributes ${ htmlAttribCount ? `(${ htmlAttribCount } )` : '' } ` }
164
158
/>
165
159
{ /* <Tab
166
160
disableRipple
@@ -173,8 +167,8 @@ class BottomTabs extends Component<PropsInt> {
173
167
< div
174
168
id = "treeWrapper"
175
169
style = { {
176
- width : " 100%" ,
177
- height : " 100%"
170
+ width : ' 100%' ,
171
+ height : ' 100%'
178
172
} }
179
173
ref = { node => ( this . treeWrapper = node ) }
180
174
>
@@ -187,15 +181,15 @@ class BottomTabs extends Component<PropsInt> {
187
181
nodes : {
188
182
node : {
189
183
name : {
190
- fill : " #D3D3D3" ,
191
- stroke : " #D3D3D3" ,
184
+ fill : ' #D3D3D3' ,
185
+ stroke : ' #D3D3D3' ,
192
186
strokeWidth : 1
193
187
}
194
188
} ,
195
189
leafNode : {
196
190
name : {
197
- fill : " #D3D3D3" ,
198
- stroke : " #D3D3D3" ,
191
+ fill : ' #D3D3D3' ,
192
+ stroke : ' #D3D3D3' ,
199
193
strokeWidth : 1
200
194
}
201
195
}
@@ -204,18 +198,12 @@ class BottomTabs extends Component<PropsInt> {
204
198
/>
205
199
</ div >
206
200
) }
207
- { value === 1 && (
208
- < CodePreview
209
- focusComponent = { focusComponent }
210
- components = { components }
211
- />
212
- ) }
201
+ { value === 1 && < CodePreview focusComponent = { focusComponent } components = { components } /> }
213
202
{ value === 2 && < Props /> }
214
- { value === 3 && focusChild . childType === "HTML" && < HtmlAttr /> }
215
- { value === 3 &&
216
- focusChild . childType !== "HTML" && (
217
- < p > Please select an HTML element to view attributes</ p >
218
- ) }
203
+ { value === 3 && focusChild . childType === 'HTML' && < HtmlAttr /> }
204
+ { value === 3 && focusChild . childType !== 'HTML' && (
205
+ < p > Please select an HTML element to view attributes</ p >
206
+ ) }
219
207
</ div >
220
208
) ;
221
209
}
0 commit comments