import type { FC } from 'react' import { useContext } from 'use-context-selector' import type { Field, FormValue } from '../declarations' import { ValidatedSuccessIcon } from '../../key-validator/ValidateStatus' import { ValidatedStatus } from '../../key-validator/declarations' import type { ValidatedStatusState } from '../../key-validator/declarations' import I18n from '@/context/i18n' type InputProps = { field: Field value: FormValue onChange: (v: FormValue) => void onFocus: () => void validatedStatusState: ValidatedStatusState } const Input: FC = ({ field, value, onChange, onFocus, validatedStatusState, }) => { const { locale } = useContext(I18n) const showValidatedIcon = validatedStatusState.status === ValidatedStatus.Success && value[field.key] const getValidatedIcon = () => { if (showValidatedIcon) return
} const handleChange = (v: string) => { const newFormValue = { ...value, [field.key]: v } onChange(newFormValue) } return (
handleChange(e.target.value)} onFocus={onFocus} value={value[field.key] || ''} /> {getValidatedIcon()}
) } export default Input