1
|
|
|
import React from "react"; |
2
|
|
|
import { FieldProps, getIn } from "formik"; |
3
|
|
|
import TextArea, { TextAreaProps } from "../TextArea"; |
4
|
|
|
|
5
|
|
|
interface TextAreaInputProps |
6
|
|
|
extends Exclude<TextAreaProps, "name" | "value" | "onChange" | "onBlur"> { |
7
|
|
|
// Formik field prop of the shape { name, value, onChange, onBlur } |
8
|
|
|
field: FieldProps["field"]; |
9
|
|
|
// Formik form prop of the shape { errors } |
10
|
|
|
form: FieldProps["form"]; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
const TextAreaInput: React.FunctionComponent<TextAreaInputProps> = ({ |
14
|
|
|
id, |
15
|
|
|
label, |
16
|
|
|
className, |
17
|
|
|
grid, |
18
|
|
|
required, |
19
|
|
|
placeholder, |
20
|
|
|
field: { name, value, onChange, onBlur }, |
21
|
|
|
form: { errors, touched }, |
22
|
|
|
...props |
23
|
|
|
}): React.ReactElement => { |
24
|
|
|
const specificError = errors ? getIn(errors, name) : null; |
25
|
|
|
const errorText = specificError ? specificError.toString() : undefined; |
26
|
|
|
const invalid = getIn(touched, name) && specificError ? true : null; |
27
|
|
|
// Workaround for new TS error https://github.com/microsoft/TypeScript/issues/37559 |
28
|
|
|
const { name: passedName, onChange: passedChange, ...otherProps } = props; |
29
|
|
|
|
30
|
|
|
return ( |
31
|
|
|
<TextArea |
32
|
|
|
id={id} |
33
|
|
|
label={label} |
34
|
|
|
className={className} |
35
|
|
|
grid={grid} |
36
|
|
|
required={required} |
37
|
|
|
placeholder={placeholder} |
38
|
|
|
name={name} |
39
|
|
|
value={value} |
40
|
|
|
errorText={errorText} |
41
|
|
|
invalid={invalid} |
42
|
|
|
onChange={onChange} |
43
|
|
|
onBlur={onBlur} |
44
|
|
|
{...otherProps} |
45
|
|
|
/> |
46
|
|
|
); |
47
|
|
|
}; |
48
|
|
|
|
49
|
|
|
export default TextAreaInput; |
50
|
|
|
|