feat(ui): Add color form component

This commit is contained in:
robin 2022-11-11 10:23:02 +08:00
parent ac76c3af0f
commit e0d3b671c8
1 changed files with 23 additions and 2 deletions

View File

@ -274,17 +274,38 @@ const SchemaForm: FC<IProps> = ({
); );
} }
const as = widget === 'textarea' ? 'textarea' : 'input'; if (widget === 'textarea') {
return (
<Form.Group controlId={key} key={key} className="mb-3">
<Form.Label>{title}</Form.Label>
<Form.Control
as="textarea"
name={key}
placeholder={options?.placeholder || ''}
type={options?.type || 'text'}
value={formData[key]?.value}
onChange={handleInputChange}
isInvalid={formData[key].isInvalid}
rows={options?.rows || 3}
/>
<Form.Control.Feedback type="invalid">
{formData[key]?.errorMsg}
</Form.Control.Feedback>
<Form.Text className="text-muted">{description}</Form.Text>
</Form.Group>
);
}
return ( return (
<Form.Group controlId={key} key={key} className="mb-3"> <Form.Group controlId={key} key={key} className="mb-3">
<Form.Label>{title}</Form.Label> <Form.Label>{title}</Form.Label>
<Form.Control <Form.Control
as={as}
name={key} name={key}
placeholder={options?.placeholder || ''} placeholder={options?.placeholder || ''}
type={options?.type || 'text'} type={options?.type || 'text'}
value={formData[key]?.value} value={formData[key]?.value}
onChange={handleInputChange} onChange={handleInputChange}
style={options?.type === 'color' ? { width: '6rem' } : {}}
isInvalid={formData[key].isInvalid} isInvalid={formData[key].isInvalid}
/> />
<Form.Control.Feedback type="invalid"> <Form.Control.Feedback type="invalid">