import type { PropTypes } from '@material-ui/core'; import FormControl from '@material-ui/core/FormControl'; import FormHelperText, { FormHelperTextProps, } from '@material-ui/core/FormHelperText'; import useTheme from '@material-ui/core/styles/useTheme'; import React from 'react'; import { Override, filterDOMProps, useForm } from 'uniforms'; export type ErrorsFieldProps = Override< FormHelperTextProps, { fullWidth?: boolean; margin?: PropTypes.Margin; variant?: 'standard' | 'outlined' | 'filled'; } >; function ErrorsField({ children, fullWidth, margin, variant, ...props }: ErrorsFieldProps) { const theme = useTheme(); const themeProps = theme.props?.MuiFormControl; const { error, schema } = useForm(); return !error && !children ? null : ( {!!children && ( {children} )} {schema.getErrorMessages(error).map((message, index) => ( {message} ))} ); } export default ErrorsField;