| Total Complexity | 3 |
| Complexity/F | 0 |
| Lines of Code | 46 |
| 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 | nullSelection, |
||
| 20 | field: { name, value, onChange, onBlur }, |
||
| 21 | form: { errors, touched }, |
||
| 22 | }): React.ReactElement => { |
||
| 23 | const specificError = errors ? errors[name] : null; |
||
| 24 | const errorText = specificError ? specificError.toString() : undefined; |
||
| 25 | const invalid = touched[name] && errors[name] ? true : null; |
||
| 26 | |||
| 27 | return ( |
||
| 28 | <Select |
||
| 29 | id={id} |
||
| 30 | label={label} |
||
| 31 | name={name} |
||
| 32 | required={required} |
||
| 33 | nullSelection={nullSelection} |
||
| 34 | options={options} |
||
| 35 | grid={grid} |
||
| 36 | selected={value} |
||
| 37 | onChange={onChange} |
||
| 38 | onBlur={onBlur} |
||
| 39 | errorText={errorText} |
||
| 40 | invalid={invalid} |
||
| 41 | /> |
||
| 42 | ); |
||
| 43 | }; |
||
| 44 | |||
| 45 | export default SelectInput; |
||
| 46 |