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, FieldInputProps } from 'formik' import classNames from 'classnames/bind' const cx = classNames.bind(styles) export interface InputProps { name: string label?: string | ReactNode 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 max?: string disabled?: boolean readOnly?: boolean field?: FieldInputProps form?: any prefix?: string | ReactElement postfix?: string | ReactElement step?: string defaultChecked?: boolean small?: boolean } export default function Input(props: Partial): ReactElement { const { required, name, label, help, additionalComponent, small, field } = props const hasError = props.form?.touched[field.name] && props.form?.errors[field.name] const styleClasses = cx({ field: true, hasError: hasError }) return (
{field && field.name !== 'price' && hasError && (
)} {help && {help}} {additionalComponent && additionalComponent}
) }