22 lines
649 B
TypeScript
22 lines
649 B
TypeScript
import type { ControlType, VariableConfig } from "./schema";
|
|||
|
|
|
||
|
|
/** Resolves the effective shadcn control for a variable: explicit `control` wins, otherwise a type-based default. */
|
||
|
|
export function resolveControl(variable: VariableConfig): ControlType {
|
||
|
|
if (variable.control) return variable.control;
|
||
|
|
|
||
|
|
switch (variable.type) {
|
||
|
|
case "string":
|
||
|
|
if (variable.secret) return "password";
|
||
|
|
if (variable.multiline) return "textarea";
|
||
|
|
return "text";
|
||
|
|
case "number":
|
||
|
|
return "number";
|
||
|
|
case "boolean":
|
||
|
|
return "checkbox";
|
||
|
|
case "enum":
|
||
|
|
return "select";
|
||
|
|
case "multiselect":
|
||
|
|
return "multiselect";
|
||
|
|
}
|
||
|
|
}
|