import React, { FormEvent, ChangeEvent, ReactElement, ReactNode } from 'react' import InputElement from './InputElement' import Help from './Help' import Label from './Label' import styles from './index.module.css' import { ErrorMessage } from 'formik' import classNames from 'classnames/bind' const cx = classNames.bind(styles) export interface InputProps { name: string label?: string placeholder?: string required?: boolean help?: string tag?: string type?: string options?: string[] additionalComponent?: ReactElement value?: string onChange?( e: | FormEvent | ChangeEvent | ChangeEvent | ChangeEvent ): void rows?: number multiple?: boolean pattern?: string min?: string disabled?: boolean readOnly?: boolean field?: any form?: any prefix?: string postfix?: string step?: string } export default function Input(props: Partial): ReactElement { const { required, name, label, help, additionalComponent, field } = props const hasError = props.form && props.form.touched[field.name] && typeof props.form.errors[field.name] === 'string' const styleClasses = cx({ field: true, hasError: hasError }) return (
{field && (
)} {help && {help}} {additionalComponent && additionalComponent}
) }