All files / components/Errors/FormError FormError.tsx

100% Statements 3/3
100% Branches 0/0
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                      108x 5763x     5x                
import { ErrorMessage } from 'formik'
import { Icon } from '../../Icon/Icon'
 
export type FormErrorProps = {
	/** Unique name of formik field. */
	fieldName: string
}
 
/**
 * Errormessage for inputs, can only be used with formik.
 */
export const FormError: React.FunctionComponent<FormErrorProps> = ({ fieldName }) => {
	return (
		<ErrorMessage name={fieldName}>
			{(errorMessage: string) => (
				<div datacy={`formerror-${fieldName}`} className="flex items-center text-red">
					<Icon icon="error" className="mr-2"></Icon>
					<span className="text-sm font-medium">{errorMessage}</span>
				</div>
			)}
		</ErrorMessage>
	)
}