Add a searchable combobox control for enum variables
select/radio don't scale to enums with dozens of choices. Reuses the same cmdk Command/Popover primitives multi-select already uses, just single-valued instead of an array.
This commit is contained in:
@@ -24,6 +24,7 @@ import {
|
||||
import { Slider } from "@/components/ui/slider";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { MultiSelect } from "./controls/multi-select";
|
||||
import { Combobox } from "./controls/combobox";
|
||||
import type { ClientVariable } from "@/lib/config/serialize";
|
||||
|
||||
export function FieldRenderer({ variable }: { variable: ClientVariable }) {
|
||||
@@ -211,6 +212,31 @@ export function FieldRenderer({ variable }: { variable: ClientVariable }) {
|
||||
</FormItem>
|
||||
);
|
||||
|
||||
case "combobox":
|
||||
return (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
{label}
|
||||
{variable.required && (
|
||||
<span className="text-destructive"> *</span>
|
||||
)}
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Combobox
|
||||
choices={
|
||||
variable.type === "enum" ? variable.choices : []
|
||||
}
|
||||
value={field.value ?? ""}
|
||||
onChange={(value) => field.onChange(value)}
|
||||
/>
|
||||
</FormControl>
|
||||
{variable.description && (
|
||||
<FormDescription>{variable.description}</FormDescription>
|
||||
)}
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
);
|
||||
|
||||
case "radio":
|
||||
return (
|
||||
<FormItem>
|
||||
|
||||
Reference in New Issue
Block a user