Spaces:
Running
Running
File size: 886 Bytes
ba95018 | 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 | import { useForm } from '../../context/FormContext';
export default function TextInput({ field, sectionId }) {
const { formState, updateTextField } = useForm();
const value = formState.sections[sectionId]?.[field.id] || '';
return (
<div className="text-input" id={`field-${field.id}`}>
<label className="text-input__label" htmlFor={`input-${field.id}`}>
{field.label}
</label>
<input
id={`input-${field.id}`}
type={field.type === 'number' ? 'number' : 'text'}
className="text-input__field"
placeholder={field.placeholder || ''}
value={value}
onChange={e => updateTextField(sectionId, field.id, e.target.value)}
min={field.type === 'number' ? '0' : undefined}
/>
{field.sentence && (
<div className="text-input__sentence">{field.sentence}</div>
)}
</div>
);
}
|