Total Complexity | 3 |
Complexity/F | 0 |
Lines of Code | 58 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import React from "react"; |
||
2 | import { FieldProps } from "formik"; |
||
3 | import Input, { InputProps } from "../Input"; |
||
4 | |||
5 | interface DateInputProps |
||
6 | extends Exclude< |
||
7 | InputProps, |
||
8 | | "name" |
||
9 | | "value" |
||
10 | | "onChange" |
||
11 | | "onBlur" |
||
12 | | "minlength" |
||
13 | | "maxlength" |
||
14 | | "type" |
||
15 | > { |
||
16 | /** Formik field prop of the shape { name, value, onChange, onBlur } */ |
||
17 | field: FieldProps["field"]; |
||
18 | /** Formik form prop of the shape { errors } */ |
||
19 | form: FieldProps["form"]; |
||
20 | } |
||
21 | |||
22 | export const DateInput: React.FC<DateInputProps> = ({ |
||
23 | id, |
||
24 | label, |
||
25 | required, |
||
26 | placeholder, |
||
27 | grid, |
||
28 | field: { name, value, onChange, onBlur }, |
||
29 | form: { errors, touched }, |
||
30 | ...props |
||
31 | }) => { |
||
32 | const specificError = errors ? errors[name] : null; |
||
33 | const errorText = specificError ? specificError.toString() : undefined; |
||
34 | const invalid = touched[name] && errors[name] ? true : null; |
||
35 | // Workaround for new TS error https://github.com/microsoft/TypeScript/issues/37559 |
||
36 | const { name: passedName, onChange: passedChange, ...otherProps } = props; |
||
37 | |||
38 | return ( |
||
39 | <Input |
||
40 | id={id} |
||
41 | label={label} |
||
42 | type="date" |
||
43 | placeholder={placeholder} |
||
44 | required={required} |
||
45 | name={name} |
||
46 | value={value} |
||
47 | grid={grid} |
||
48 | onChange={onChange} |
||
49 | onBlur={onBlur} |
||
50 | errorText={errorText} |
||
51 | invalid={invalid} |
||
52 | {...otherProps} |
||
53 | /> |
||
54 | ); |
||
55 | }; |
||
56 | |||
57 | export default DateInput; |
||
58 |