Spaces:
Sleeping
Sleeping
File size: 3,186 Bytes
529c982 e058d03 529c982 e058d03 c7d096e 529c982 c7d096e 529c982 c7d096e 529c982 e058d03 529c982 c7d096e 529c982 e058d03 c7d096e e058d03 529c982 c7d096e 529c982 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | 'use client';
import { QuestionParameterConfig } from '@/types/questionConfig';
import { SelectInput, RangeInput, TextInput, CheckboxInput } from './inputs';
interface ParameterInputProps {
config: QuestionParameterConfig;
value: string | number | boolean | string[];
onChange: (value: string | number | boolean | string[]) => void;
className?: string;
disabled?: boolean;
}
export default function ParameterInput({
config,
value,
onChange,
className = '',
disabled = false
}: ParameterInputProps) {
const { type, label, options, min, max, step, placeholder, helpText, key } = config;
switch (type) {
case 'select':
return (
<SelectInput
label={label}
value={typeof value === 'string' || typeof value === 'number' ? value : undefined}
defaultValue={typeof config.defaultValue === 'string' || typeof config.defaultValue === 'number' ? config.defaultValue : undefined}
options={(options || []).filter(option =>
typeof option.value === 'string' || typeof option.value === 'number'
).map(option => ({
value: option.value as string | number,
label: option.label
}))}
onChange={onChange}
className={className}
disabled={disabled}
placeholder={placeholder}
helpText={helpText}
/>
);
case 'range':
return (
<RangeInput
label={label}
value={typeof value === 'number' ? value : undefined}
defaultValue={typeof config.defaultValue === 'number' ? config.defaultValue : undefined}
min={min || 1}
max={max || 10}
step={step}
onChange={onChange}
className={className}
disabled={disabled}
valueUnit={helpText}
showValue={true}
/>
);
case 'text':
return (
<TextInput
label={label}
value={typeof value === 'string' ? value : undefined}
defaultValue={typeof config.defaultValue === 'string' ? config.defaultValue : undefined}
onChange={onChange}
className={className}
disabled={disabled}
placeholder={placeholder}
helpText={helpText}
/>
);
case 'textarea':
return (
<TextInput
label={label}
value={typeof value === 'string' ? value : undefined}
defaultValue={typeof config.defaultValue === 'string' ? config.defaultValue : undefined}
onChange={onChange}
className={className}
disabled={disabled}
placeholder={placeholder}
helpText={helpText}
isTextarea={true}
/>
);
case 'checkbox':
return (
<CheckboxInput
label={label}
value={typeof value === 'boolean' ? value : undefined}
defaultValue={typeof config.defaultValue === 'boolean' ? config.defaultValue : undefined}
onChange={onChange}
className={className}
disabled={disabled}
helpText={helpText}
id={key}
/>
);
default:
return null;
}
} |