Path: blob/1.0-develop/resources/scripts/components/elements/FormikFieldWrapper.tsx
7461 views
import React from 'react';1import { Field, FieldProps } from 'formik';2import InputError from '@/components/elements/InputError';3import Label from '@/components/elements/Label';45interface Props {6id?: string;7name: string;8children: React.ReactNode;9className?: string;10label?: string;11description?: string;12validate?: (value: any) => undefined | string | Promise<any>;13}1415const FormikFieldWrapper = ({ id, name, label, className, description, validate, children }: Props) => (16<Field name={name} validate={validate}>17{({ field, form: { errors, touched } }: FieldProps) => (18<div className={`${className} ${touched[field.name] && errors[field.name] ? 'has-error' : undefined}`}>19{label && <Label htmlFor={id}>{label}</Label>}20{children}21<InputError errors={errors} touched={touched} name={field.name}>22{description || null}23</InputError>24</div>25)}26</Field>27);2829export default FormikFieldWrapper;303132