Skip to content

Commit 2b8cd51

Browse files
committed
feat: show descriptions for parameter options
1 parent d504044 commit 2b8cd51

File tree

2 files changed

+68
-13
lines changed

2 files changed

+68
-13
lines changed

site/src/components/RichParameterInput/RichParameterInput.stories.tsx

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,39 @@ export const BooleanType: Story = {
6969
},
7070
};
7171

72-
export const OptionsType: Story = {
72+
export const Options: Story = {
73+
args: {
74+
value: "first_option",
75+
id: "options_parameter",
76+
parameter: createTemplateVersionParameter({
77+
name: "options_parameter",
78+
type: "string",
79+
description: "Parameter with options",
80+
options: [
81+
{
82+
name: "First option",
83+
value: "first_option",
84+
description: "",
85+
icon: "/icon/fedora.svg",
86+
},
87+
{
88+
name: "Second option",
89+
value: "second_option",
90+
description: "",
91+
icon: "/icon/database.svg",
92+
},
93+
{
94+
name: "Third option",
95+
value: "third_option",
96+
description: "",
97+
icon: "/icon/aws.png",
98+
},
99+
],
100+
}),
101+
},
102+
};
103+
104+
export const OptionsWithDescriptions: Story = {
73105
args: {
74106
value: "first_option",
75107
id: "options_parameter",
@@ -82,7 +114,7 @@ export const OptionsType: Story = {
82114
name: "First option",
83115
value: "first_option",
84116
description: "This is option 1",
85-
icon: "",
117+
icon: "/icon/fedora.svg",
86118
},
87119
{
88120
name: "Second option",
@@ -217,9 +249,16 @@ export const SmallBooleanType: Story = {
217249
},
218250
};
219251

220-
export const SmallOptionsType: Story = {
252+
export const SmallOptions: Story = {
253+
args: {
254+
...Options.args,
255+
size: "small",
256+
},
257+
};
258+
259+
export const SmallOptionsWithDescriptions: Story = {
221260
args: {
222-
...OptionsType.args,
261+
...OptionsWithDescriptions.args,
223262
size: "small",
224263
},
225264
};

site/src/components/RichParameterInput/RichParameterInput.tsx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { MemoizedMarkdown } from "components/Markdown/Markdown";
1111
import { MultiTextField } from "./MultiTextField";
1212
import Box from "@mui/material/Box";
1313
import { Theme } from "@mui/material/styles";
14+
import { InfoTooltip } from "components/InfoTooltip/InfoTooltip";
15+
import { useTheme } from "@emotion/react";
1416

1517
const isBoolean = (parameter: TemplateVersionParameter) => {
1618
return parameter.type === "bool";
@@ -95,6 +97,11 @@ const RichParameterField: React.FC<RichParameterInputProps> = ({
9597
...props
9698
}) => {
9799
const styles = useStyles();
100+
const theme = useTheme();
101+
102+
const small = size === "small";
103+
104+
console.log(size);
98105

99106
if (isBoolean(parameter)) {
100107
return (
@@ -137,19 +144,33 @@ const RichParameterField: React.FC<RichParameterInputProps> = ({
137144
value={option.value}
138145
control={<Radio size="small" />}
139146
label={
140-
<span className={styles.radioOption}>
147+
<Stack direction="row" alignItems="center">
141148
{option.icon && (
142149
<img
143150
className={styles.optionIcon}
144151
alt="Parameter icon"
145152
src={option.icon}
146-
style={{
153+
css={{
147154
pointerEvents: "none",
148155
}}
149156
/>
150157
)}
151-
{option.name}
152-
</span>
158+
{option.description ? (
159+
<Stack
160+
spacing={small ? 1 : 0}
161+
alignItems={small ? "center" : undefined}
162+
css={{ padding: `${theme.spacing(0.5)} 0` }}
163+
direction={small ? "row" : "column"}
164+
>
165+
<span>{option.name}</span>
166+
<MemoizedMarkdown className={styles.labelCaption}>
167+
{option.description}
168+
</MemoizedMarkdown>
169+
</Stack>
170+
) : (
171+
option.name
172+
)}
173+
</Stack>
153174
}
154175
/>
155176
))}
@@ -281,11 +302,6 @@ const useStyles = makeStyles<Theme>((theme) => ({
281302
height: "100%",
282303
objectFit: "contain",
283304
},
284-
radioOption: {
285-
display: "flex",
286-
alignItems: "center",
287-
gap: theme.spacing(1.5),
288-
},
289305
optionIcon: {
290306
maxHeight: 20,
291307
width: 20,

0 commit comments

Comments
 (0)