Created
June 24, 2022 22:25
-
-
Save ruanlinos/0567b79dabab7dfbda6cf38de1aebba3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import {DivError, DivFieldTools, LabelInputAddTool, TextareaDescriptionAddTool} from "./modal/Modal.styles"; | |
import {Field, FieldAttributes, FormikErrors, FormikTouched, useFormikContext} from "formik"; | |
interface InputProps extends FieldAttributes<any> { | |
name: string; | |
label: string; | |
} | |
export function Input({name, label, ...props}: InputProps) { | |
const {errors, touched} = useFormikContext(); | |
return ( | |
<DivFieldTools> | |
<LabelInputAddTool htmlFor={name}> | |
{label} | |
</LabelInputAddTool> | |
<Field | |
{...props} | |
as={TextareaDescriptionAddTool} | |
id={name + "-test"} | |
name={name} | |
placeholder="Descreva a ferramenta." | |
/> | |
{errors[name as keyof FormikErrors<unknown>] && touched[name as keyof FormikTouched<unknown>] ? ( | |
<DivError>{errors[name as keyof FormikErrors<unknown>]}</DivError> | |
) : null} | |
</DivFieldTools> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment