@@ -3,10 +3,26 @@ import Radio from "@material-ui/core/Radio"
3
3
import RadioGroup from "@material-ui/core/RadioGroup"
4
4
import { makeStyles } from "@material-ui/core/styles"
5
5
import TextField from "@material-ui/core/TextField"
6
+ import { Stack } from "components/Stack/Stack"
6
7
import { FC } from "react"
7
8
import { ParameterSchema } from "../../api/typesGenerated"
8
9
import { MONOSPACE_FONT_FAMILY } from "../../theme/constants"
9
10
11
+ const isBoolean = ( schema : ParameterSchema ) => {
12
+ return schema . validation_value_type === "bool"
13
+ }
14
+
15
+ const ParameterLabel : React . FC < { schema : ParameterSchema } > = ( { schema } ) => {
16
+ const styles = useStyles ( )
17
+
18
+ return (
19
+ < label className = { styles . label } htmlFor = { schema . name } >
20
+ < strong > var.{ schema . name } </ strong >
21
+ { schema . description && < span className = { styles . labelDescription } > { schema . description } </ span > }
22
+ </ label >
23
+ )
24
+ }
25
+
10
26
export interface ParameterInputProps {
11
27
disabled ?: boolean
12
28
schema : ParameterSchema
@@ -15,23 +31,22 @@ export interface ParameterInputProps {
15
31
16
32
export const ParameterInput : FC < ParameterInputProps > = ( { disabled, onChange, schema } ) => {
17
33
const styles = useStyles ( )
34
+
18
35
return (
19
- < div className = { styles . root } >
20
- < div className = { styles . title } >
21
- < h2 > var.{ schema . name } </ h2 >
22
- { schema . description && < span > { schema . description } </ span > }
23
- </ div >
36
+ < Stack direction = "column" className = { styles . root } >
37
+ < ParameterLabel schema = { schema } />
24
38
< div className = { styles . input } >
25
39
< ParameterField disabled = { disabled } onChange = { onChange } schema = { schema } />
26
40
</ div >
27
- </ div >
41
+ </ Stack >
28
42
)
29
43
}
30
44
31
45
const ParameterField : React . FC < ParameterInputProps > = ( { disabled, onChange, schema } ) => {
32
46
if ( schema . validation_contains && schema . validation_contains . length > 0 ) {
33
47
return (
34
48
< RadioGroup
49
+ id = { schema . name }
35
50
defaultValue = { schema . default_source_value }
36
51
onChange = { ( event ) => {
37
52
onChange ( event . target . value )
@@ -50,11 +65,37 @@ const ParameterField: React.FC<ParameterInputProps> = ({ disabled, onChange, sch
50
65
)
51
66
}
52
67
68
+ if ( isBoolean ( schema ) ) {
69
+ return (
70
+ < RadioGroup
71
+ id = { schema . name }
72
+ defaultValue = { schema . default_source_value }
73
+ onChange = { ( event ) => {
74
+ onChange ( event . target . value )
75
+ } }
76
+ >
77
+ < FormControlLabel
78
+ disabled = { disabled }
79
+ value = "true"
80
+ control = { < Radio color = "primary" size = "small" disableRipple /> }
81
+ label = "True"
82
+ />
83
+ < FormControlLabel
84
+ disabled = { disabled }
85
+ value = "false"
86
+ control = { < Radio color = "primary" size = "small" disableRipple /> }
87
+ label = "False"
88
+ />
89
+ </ RadioGroup >
90
+ )
91
+ }
92
+
53
93
// A text field can technically handle all cases!
54
94
// As other cases become more prominent (like filtering for numbers),
55
95
// we should break this out into more finely scoped input fields.
56
96
return (
57
97
< TextField
98
+ id = { schema . name }
58
99
size = "small"
59
100
disabled = { disabled }
60
101
placeholder = { schema . default_source_value }
@@ -67,25 +108,26 @@ const ParameterField: React.FC<ParameterInputProps> = ({ disabled, onChange, sch
67
108
68
109
const useStyles = makeStyles ( ( theme ) => ( {
69
110
root : {
70
- display : "flex" ,
71
- flexDirection : "column" ,
72
111
fontFamily : MONOSPACE_FONT_FAMILY ,
73
112
paddingTop : theme . spacing ( 2 ) ,
74
113
paddingBottom : theme . spacing ( 2 ) ,
75
114
} ,
76
- title : {
115
+ label : {
77
116
display : "flex" ,
78
117
flexDirection : "column" ,
79
- "& h2" : {
80
- margin : 0 ,
81
- } ,
82
- "& span" : {
83
- paddingTop : theme . spacing ( 1 ) ,
84
- } ,
118
+ fontSize : 21 ,
119
+ } ,
120
+ labelDescription : {
121
+ fontSize : 14 ,
122
+ marginTop : theme . spacing ( 1 ) ,
85
123
} ,
86
124
input : {
87
- marginTop : theme . spacing ( 2 ) ,
88
125
display : "flex" ,
89
126
flexDirection : "column" ,
90
127
} ,
128
+ checkbox : {
129
+ display : "flex" ,
130
+ alignItems : "center" ,
131
+ gap : theme . spacing ( 1 ) ,
132
+ } ,
91
133
} ) )
0 commit comments