Total Complexity | 3 |
Complexity/F | 0 |
Lines of Code | 48 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 | |||
28 | return ( |
||
29 | <TextArea |
||
30 | id={id} |
||
31 | label={label} |
||
32 | className={className} |
||
33 | grid={grid} |
||
34 | required={required} |
||
35 | placeholder={placeholder} |
||
36 | name={name} |
||
37 | value={value} |
||
38 | errorText={errorText} |
||
39 | invalid={invalid} |
||
40 | onChange={onChange} |
||
41 | onBlur={onBlur} |
||
42 | {...props} |
||
43 | /> |
||
44 | ); |
||
45 | }; |
||
46 | |||
47 | export default TextAreaInput; |
||
48 |