@@ -2,7 +2,7 @@ import FormControlLabel from "@material-ui/core/FormControlLabel"
2
2
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
- import TextField from "@material-ui/core/TextField"
5
+ import TextField , { TextFieldProps } from "@material-ui/core/TextField"
6
6
import { Stack } from "components/Stack/Stack"
7
7
import { FC , useState } from "react"
8
8
import { TemplateVersionParameter } from "../../api/typesGenerated"
@@ -14,54 +14,48 @@ const isBoolean = (parameter: TemplateVersionParameter) => {
14
14
}
15
15
16
16
export interface ParameterLabelProps {
17
- index : number
17
+ id : string
18
18
parameter : TemplateVersionParameter
19
19
}
20
20
21
- const ParameterLabel : FC < ParameterLabelProps > = ( { index , parameter } ) => {
21
+ const ParameterLabel : FC < ParameterLabelProps > = ( { id , parameter } ) => {
22
22
const styles = useStyles ( )
23
+ const hasDescription = parameter . description && parameter . description !== ""
23
24
24
25
return (
25
- < span >
26
- < span className = { styles . labelNameWithIcon } >
26
+ < label htmlFor = { id } >
27
+ < Stack direction = "row" alignItems = "center" >
27
28
{ parameter . icon && (
28
- < span className = { styles . iconWrapper } >
29
+ < span className = { styles . labelIconWrapper } >
29
30
< img
30
- className = { styles . icon }
31
+ className = { styles . labelIcon }
31
32
alt = "Parameter icon"
32
33
src = { parameter . icon }
33
- style = { {
34
- pointerEvents : "none" ,
35
- } }
36
34
/>
37
35
</ span >
38
36
) }
39
- < span className = { styles . labelName } >
40
- < label htmlFor = { `rich_parameter_values[${ index } ].value` } >
41
- { parameter . name }
42
- </ label >
43
- </ span >
44
- </ span >
45
- { parameter . description && (
46
- < span className = { styles . labelDescription } >
47
- < MemoizedMarkdown > { parameter . description } </ MemoizedMarkdown >
48
- </ span >
49
- ) }
50
- { ! parameter . mutable && (
51
- < div className = { styles . labelImmutable } >
52
- This parameter cannot be changed after creating workspace.
53
- </ div >
54
- ) }
55
- </ span >
37
+
38
+ { hasDescription ? (
39
+ < Stack spacing = { 0.5 } >
40
+ < span className = { styles . labelCaption } > { parameter . name } </ span >
41
+ < span className = { styles . labelPrimary } >
42
+ < MemoizedMarkdown > { parameter . description } </ MemoizedMarkdown >
43
+ </ span >
44
+ </ Stack >
45
+ ) : (
46
+ < span className = { styles . labelPrimary } > { parameter . name } </ span >
47
+ ) }
48
+ </ Stack >
49
+ </ label >
56
50
)
57
51
}
58
52
59
- export interface RichParameterInputProps {
53
+ export type RichParameterInputProps = TextFieldProps & {
60
54
index : number
61
- disabled ?: boolean
62
55
parameter : TemplateVersionParameter
63
56
onChange : ( value : string ) => void
64
57
initialValue ?: string
58
+ id : string
65
59
}
66
60
67
61
export const RichParameterInput : FC < RichParameterInputProps > = ( {
@@ -70,16 +64,16 @@ export const RichParameterInput: FC<RichParameterInputProps> = ({
70
64
onChange,
71
65
parameter,
72
66
initialValue,
73
- ...props
67
+ ...fieldProps
74
68
} ) => {
75
69
const styles = useStyles ( )
76
70
77
71
return (
78
72
< Stack direction = "column" spacing = { 0.75 } >
79
- < ParameterLabel index = { index } parameter = { parameter } />
73
+ < ParameterLabel id = { fieldProps . id } parameter = { parameter } />
80
74
< div className = { styles . input } >
81
75
< RichParameterField
82
- { ...props }
76
+ { ...fieldProps }
83
77
index = { index }
84
78
disabled = { disabled }
85
79
onChange = { onChange }
@@ -140,7 +134,7 @@ const RichParameterField: React.FC<RichParameterInputProps> = ({
140
134
value = { option . value }
141
135
control = { < Radio color = "primary" size = "small" disableRipple /> }
142
136
label = {
143
- < span >
137
+ < span className = { styles . radioOption } >
144
138
{ option . icon && (
145
139
< img
146
140
className = { styles . optionIcon }
@@ -180,24 +174,25 @@ const RichParameterField: React.FC<RichParameterInputProps> = ({
180
174
)
181
175
}
182
176
183
- const iconSize = 20
184
- const optionIconSize = 24
177
+ const optionIconSize = 20
185
178
186
179
const useStyles = makeStyles ( ( theme ) => ( {
187
- labelName : {
180
+ label : {
181
+ marginBottom : theme . spacing ( 0.5 ) ,
182
+ } ,
183
+ labelCaption : {
188
184
fontSize : 14 ,
189
185
color : theme . palette . text . secondary ,
190
- display : "block" ,
191
- marginBottom : theme . spacing ( 1.0 ) ,
192
186
} ,
193
- labelNameWithIcon : {
194
- marginBottom : theme . spacing ( 0.5 ) ,
195
- } ,
196
- labelDescription : {
187
+ labelPrimary : {
197
188
fontSize : 16 ,
198
189
color : theme . palette . text . primary ,
199
- display : "block" ,
200
190
fontWeight : 600 ,
191
+
192
+ "& p" : {
193
+ margin : 0 ,
194
+ lineHeight : "20px" , // Keep the same as ParameterInput
195
+ } ,
201
196
} ,
202
197
labelImmutable : {
203
198
marginTop : theme . spacing ( 0.5 ) ,
@@ -213,18 +208,23 @@ const useStyles = makeStyles((theme) => ({
213
208
alignItems : "center" ,
214
209
gap : theme . spacing ( 1 ) ,
215
210
} ,
216
- iconWrapper : {
217
- float : "left" ,
211
+ labelIconWrapper : {
212
+ width : theme . spacing ( 2.5 ) ,
213
+ height : theme . spacing ( 2.5 ) ,
214
+ display : "block" ,
218
215
} ,
219
- icon : {
220
- maxHeight : iconSize ,
221
- width : iconSize ,
222
- marginRight : theme . spacing ( 1.0 ) ,
216
+ labelIcon : {
217
+ width : "100%" ,
218
+ height : "100%" ,
219
+ objectFit : "contain" ,
220
+ } ,
221
+ radioOption : {
222
+ display : "flex" ,
223
+ alignItems : "center" ,
224
+ gap : theme . spacing ( 1.5 ) ,
223
225
} ,
224
226
optionIcon : {
225
227
maxHeight : optionIconSize ,
226
228
width : optionIconSize ,
227
- marginRight : theme . spacing ( 1.0 ) ,
228
- float : "left" ,
229
229
} ,
230
230
} ) )
0 commit comments