1
1
import React , { Component , Fragment } from 'react' ;
2
2
import { connect } from 'react-redux' ;
3
- import { withStyles } from '@material-ui/core/styles' ;
3
+ import { withStyles , Theme } from '@material-ui/core/styles' ;
4
4
import FormControl from '@material-ui/core/FormControl' ;
5
5
import Grid from '@material-ui/core/Grid' ;
6
6
import TextField from '@material-ui/core/TextField' ;
@@ -10,9 +10,15 @@ import Switch from '@material-ui/core/Switch';
10
10
import InputLabel from '@material-ui/core/InputLabel' ;
11
11
import { addProp , deleteProp } from '../actions/components' ;
12
12
import DataTable from './DataTable' ;
13
- import { ComponentInt } from '../utils/Interfaces' ;
13
+ import { ComponentInt , PropInt , PropsInt } from '../utils/Interfaces' ;
14
14
15
- const styles = theme => ( {
15
+ interface PropsPropsInt extends PropsInt {
16
+ classes : any ;
17
+ addProp ( arg : PropInt ) : void ;
18
+ deleteProp ( propId : number ) : void ;
19
+ }
20
+
21
+ const styles = ( theme : Theme ) => ( {
16
22
root : {
17
23
display : 'flex' ,
18
24
justifyContent : 'center' ,
@@ -59,25 +65,7 @@ const styles = theme => ({
59
65
} ) ;
60
66
61
67
const mapDispatchToProps = ( dispatch : any ) => ( {
62
- addProp : ( {
63
- key,
64
- value,
65
- required,
66
- type
67
- } : {
68
- key : string ;
69
- value : string ;
70
- required : boolean ;
71
- type : string ;
72
- } ) =>
73
- dispatch (
74
- addProp ( {
75
- key,
76
- value,
77
- required,
78
- type
79
- } )
80
- ) ,
68
+ addProp : ( prop : PropInt ) => dispatch ( addProp ( prop ) ) ,
81
69
deleteProp : ( propId : number ) => dispatch ( deleteProp ( propId ) )
82
70
} ) ;
83
71
@@ -103,21 +91,29 @@ const availablePropTypes = {
103
91
104
92
// generates the various options for the prop type selection
105
93
const typeOptions = [
106
- < option value = '' key = '' /> ,
94
+ < option value = "" key = "" /> ,
107
95
...Object . keys ( availablePropTypes ) . map ( type => (
108
96
< option value = { type } key = { type } style = { { color : '#000' } } >
109
97
{ type }
110
98
</ option >
111
99
) )
112
100
] ;
113
-
114
- class Props extends Component {
115
- state = {
116
- propKey : '' ,
117
- propValue : '' ,
118
- propRequired : true ,
119
- propType : ''
120
- } ;
101
+ interface StateInt {
102
+ propKey : string ;
103
+ propValue : string ;
104
+ propRequired : boolean ;
105
+ propType : string ;
106
+ }
107
+ class Props extends Component < PropsPropsInt , StateInt > {
108
+ constructor ( props : PropsPropsInt ) {
109
+ super ( props ) ;
110
+ this . state = {
111
+ propKey : '' ,
112
+ propValue : '' ,
113
+ propRequired : true ,
114
+ propType : ''
115
+ } ;
116
+ }
121
117
122
118
handleChange = ( event : MouseEvent ) => {
123
119
if ( event . target . id === 'propKey' ) {
@@ -198,18 +194,18 @@ class Props extends Component {
198
194
) : (
199
195
< Fragment >
200
196
< div
201
- className = ' props-container'
197
+ className = " props-container"
202
198
style = { { marginTop : '20px' , width : '90%' , height : '80%' } }
203
199
>
204
200
< Grid container spacing = { 8 } >
205
201
< Grid item xs = { 3 } >
206
- < form className = ' props-input' onSubmit = { this . handleAddProp } >
202
+ < form className = " props-input" onSubmit = { this . handleAddProp } >
207
203
< Grid container spacing = { 8 } >
208
204
< Grid item xs = { 6 } >
209
205
< TextField
210
- id = ' propKey'
211
- label = ' Key'
212
- margin = ' normal'
206
+ id = " propKey"
207
+ label = " Key"
208
+ margin = " normal"
213
209
autoFocus
214
210
onChange = { this . handleChange }
215
211
value = { this . state . propKey }
@@ -224,9 +220,9 @@ class Props extends Component {
224
220
</ Grid >
225
221
< Grid item xs = { 6 } >
226
222
< TextField
227
- id = ' propValue'
228
- label = ' Value'
229
- margin = ' normal'
223
+ id = " propValue"
224
+ label = " Value"
225
+ margin = " normal"
230
226
onChange = { this . handleChange }
231
227
InputProps = { {
232
228
className : classes . input
@@ -239,17 +235,14 @@ class Props extends Component {
239
235
</ Grid >
240
236
< Grid item xs = { 6 } >
241
237
< FormControl required >
242
- < InputLabel
243
- className = { classes . light }
244
- htmlFor = 'propType'
245
- >
238
+ < InputLabel className = { classes . light } htmlFor = "propType" >
246
239
Type
247
240
</ InputLabel >
248
241
< Select
249
242
native
250
243
className = { classes . light }
251
- id = ' propType'
252
- placeholder = ' title'
244
+ id = " propType"
245
+ placeholder = " title"
253
246
onChange = { this . handleChange }
254
247
value = { this . state . propType }
255
248
required
@@ -260,29 +253,26 @@ class Props extends Component {
260
253
</ Grid >
261
254
< Grid item xs = { 6 } >
262
255
< div className = { classes . column } >
263
- < InputLabel
264
- className = { classes . light }
265
- htmlFor = 'propRequired'
266
- >
256
+ < InputLabel className = { classes . light } htmlFor = "propRequired" >
267
257
Required?
268
258
</ InputLabel >
269
259
< Switch
270
260
checked = { this . state . propRequired }
271
261
onChange = { this . togglePropRequired }
272
- value = ' propRequired'
273
- color = ' primary'
274
- id = ' propRequired'
262
+ value = " propRequired"
263
+ color = " primary"
264
+ id = " propRequired"
275
265
/>
276
266
</ div >
277
267
</ Grid >
278
268
< Grid item >
279
269
< Button
280
- color = ' primary'
281
- aria-label = ' Add'
282
- type = ' submit'
270
+ color = " primary"
271
+ aria-label = " Add"
272
+ type = " submit"
283
273
// disabled={!this.state.propKey || !this.state.propType}
284
- variant = ' contained'
285
- size = ' large'
274
+ variant = " contained"
275
+ size = " large"
286
276
>
287
277
ADD PROP
288
278
</ Button >
0 commit comments