Skip to content

Commit 9b1575f

Browse files
committed
feat: add switch component
1 parent edec220 commit 9b1575f

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

site/src/DynamicForm.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ export function DynamicForm() {
296296
{param.display_name || param.name}
297297
{param.icon && <img src={param.icon} alt="" style={{ marginLeft: 6 }} />}
298298
</label>
299-
<output className="text-sm font-medium tabular-nums">{parameterValue(param.value)}</output>
300299
</div>
301300
{param.description && <div className="text-sm">{param.description}</div>}
302301
<Controller
@@ -320,6 +319,31 @@ export function DynamicForm() {
320319
/>
321320
</div>
322321
)
322+
case "switch":
323+
return (
324+
<div key={param.name} className="flex flex-col gap-2 items-center">
325+
<div className="flex items-center justify-between gap-2">
326+
<label>
327+
{param.display_name || param.name}
328+
{param.icon && <img src={param.icon} alt="" style={{ marginLeft: 6 }} />}
329+
</label>
330+
</div>
331+
{param.description && <div className="text-sm">{param.description}</div>}
332+
<Controller
333+
name={param.name}
334+
control={methods.control}
335+
render={({ field }) => (
336+
<div className="w-[300px]">
337+
<Switch
338+
checked={Boolean(field.value === "true")}
339+
onCheckedChange={(checked) => field.onChange(checked.toString())}
340+
disabled={(param.form_type_metadata as { disabled?: boolean })?.disabled}
341+
/>
342+
</div>
343+
)}
344+
/>
345+
</div>
346+
)
323347
}
324348
}
325349

0 commit comments

Comments
 (0)