Passed
Push — feature/post-covid-application... ( 4340d4...92a3aa )
by Yonathan
08:31 queued 01:05
created

resources/assets/js/components/Form/DateInput.tsx   A

Complexity

Total Complexity 3
Complexity/F 0

Size

Lines of Code 58
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 43
mnd 3
bc 3
fnc 0
dl 0
loc 58
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
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