@@ -3,10 +3,26 @@ import Radio from "@material-ui/core/Radio"
33import RadioGroup from "@material-ui/core/RadioGroup"
44import { makeStyles } from "@material-ui/core/styles"
55import TextField from "@material-ui/core/TextField"
6+ import { Stack } from "components/Stack/Stack"
67import { FC } from "react"
78import { ParameterSchema } from "../../api/typesGenerated"
89import { MONOSPACE_FONT_FAMILY } from "../../theme/constants"
910
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+
1026export interface ParameterInputProps {
1127 disabled ?: boolean
1228 schema : ParameterSchema
@@ -15,23 +31,22 @@ export interface ParameterInputProps {
1531
1632export const ParameterInput : FC < ParameterInputProps > = ( { disabled, onChange, schema } ) => {
1733 const styles = useStyles ( )
34+
1835 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 } />
2438 < div className = { styles . input } >
2539 < ParameterField disabled = { disabled } onChange = { onChange } schema = { schema } />
2640 </ div >
27- </ div >
41+ </ Stack >
2842 )
2943}
3044
3145const ParameterField : React . FC < ParameterInputProps > = ( { disabled, onChange, schema } ) => {
3246 if ( schema . validation_contains && schema . validation_contains . length > 0 ) {
3347 return (
3448 < RadioGroup
49+ id = { schema . name }
3550 defaultValue = { schema . default_source_value }
3651 onChange = { ( event ) => {
3752 onChange ( event . target . value )
@@ -50,11 +65,37 @@ const ParameterField: React.FC<ParameterInputProps> = ({ disabled, onChange, sch
5065 )
5166 }
5267
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+
5393 // A text field can technically handle all cases!
5494 // As other cases become more prominent (like filtering for numbers),
5595 // we should break this out into more finely scoped input fields.
5696 return (
5797 < TextField
98+ id = { schema . name }
5899 size = "small"
59100 disabled = { disabled }
60101 placeholder = { schema . default_source_value }
@@ -67,25 +108,26 @@ const ParameterField: React.FC<ParameterInputProps> = ({ disabled, onChange, sch
67108
68109const useStyles = makeStyles ( ( theme ) => ( {
69110 root : {
70- display : "flex" ,
71- flexDirection : "column" ,
72111 fontFamily : MONOSPACE_FONT_FAMILY ,
73112 paddingTop : theme . spacing ( 2 ) ,
74113 paddingBottom : theme . spacing ( 2 ) ,
75114 } ,
76- title : {
115+ label : {
77116 display : "flex" ,
78117 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 ) ,
85123 } ,
86124 input : {
87- marginTop : theme . spacing ( 2 ) ,
88125 display : "flex" ,
89126 flexDirection : "column" ,
90127 } ,
128+ checkbox : {
129+ display : "flex" ,
130+ alignItems : "center" ,
131+ gap : theme . spacing ( 1 ) ,
132+ } ,
91133} ) )
0 commit comments