import React from 'react'; import cn from 'classnames'; import Flex from './Flex'; import { ErrorText } from './Typography'; import { useField } from 'react-final-form'; export default function Input({ // visuals type, name, label, className, accessory, disabled = false, mono = false, // callbacks onEnter, // state config, // extra ...rest }) { const { input, meta: { active, error, submitting, touched, valid }, } = useField(name, config); disabled = disabled || submitting; // notify parent of enter keypress iff not disabled and passing // TODO: integrate this into react-final-form submission // const onKeyPress = useCallback( // e => !disabled && valid && e.key === 'Enter' && onEnter && onEnter(), // [disabled, valid] // eslint-disable-line react-hooks/exhaustive-deps // ); return ( {label} {accessory && (
{accessory}
)}
{touched && !active && error && ( {error} )}
); }