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 } from "formik"; |
||
3 | import Select, { SelectProps } from "../Select"; |
||
4 | |||
5 | interface SelectInputProps |
||
6 | extends Exclude<SelectProps, "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 SelectInput: React.FunctionComponent<SelectInputProps> = ({ |
||
14 | id, |
||
15 | label, |
||
16 | grid, |
||
17 | required, |
||
18 | options, |
||
19 | disabled, |
||
20 | nullSelection, |
||
21 | field: { name, value, onChange, onBlur }, |
||
22 | form: { errors, touched }, |
||
23 | }): React.ReactElement => { |
||
24 | const specificError = errors ? errors[name] : null; |
||
25 | const errorText = specificError ? specificError.toString() : undefined; |
||
26 | const invalid = touched[name] && errors[name] ? true : null; |
||
27 | |||
28 | return ( |
||
29 | <Select |
||
30 | id={id} |
||
31 | label={label} |
||
32 | name={name} |
||
33 | required={required} |
||
34 | nullSelection={nullSelection} |
||
35 | options={options} |
||
36 | grid={grid} |
||
37 | disabled={disabled} |
||
38 | selected={value} |
||
39 | onChange={onChange} |
||
40 | onBlur={onBlur} |
||
41 | errorText={errorText} |
||
42 | invalid={invalid} |
||
43 | /> |
||
44 | ); |
||
45 | }; |
||
46 | |||
47 | export default SelectInput; |
||
48 |