36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
import React from 'react';
|
|
import { classNames } from 'primereact/utils';
|
|
import { Controller } from 'react-hook-form';
|
|
import { InputTextarea } from 'primereact/inputtextarea';
|
|
|
|
const TextArea = ({
|
|
fieldName,
|
|
label,
|
|
control,
|
|
rows = 4,
|
|
errors,
|
|
defaultValue,
|
|
config = {},
|
|
infoText = null
|
|
}) => {
|
|
return (
|
|
<>
|
|
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
|
|
{label}{config.required ? '*' : null}
|
|
</label>
|
|
<Controller
|
|
name={fieldName}
|
|
control={control}
|
|
defaultValue={defaultValue}
|
|
rules={config}
|
|
render={({ field, fieldState }) => (
|
|
<InputTextarea id={field.name}
|
|
rows={rows}
|
|
{...field}
|
|
className={classNames({ 'p-invalid': fieldState.invalid })}/>
|
|
)}/>
|
|
{infoText ? <small>{infoText}</small> : null}
|
|
</>)
|
|
}
|
|
|
|
export default TextArea; |