2025-02-20 20:22:05 +03:00
|
|
|
import { type FieldError, type GlobalError } from 'react-hook-form';
|
2025-02-12 21:36:03 +03:00
|
|
|
import clsx from 'clsx';
|
2025-01-31 21:04:21 +03:00
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
import { type Styling } from '../props';
|
2025-02-03 18:17:07 +03:00
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
interface ErrorFieldProps extends Styling {
|
2025-01-31 21:04:21 +03:00
|
|
|
error?: FieldError | GlobalError;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays an error message for input field.
|
|
|
|
*/
|
2025-02-07 10:53:49 +03:00
|
|
|
export function ErrorField({ error, className, ...restProps }: ErrorFieldProps): React.ReactElement | null {
|
2025-01-31 21:04:21 +03:00
|
|
|
if (!error) {
|
|
|
|
return null;
|
|
|
|
}
|
2025-02-03 18:17:07 +03:00
|
|
|
return (
|
2025-04-12 21:47:46 +03:00
|
|
|
<div className={clsx('text-sm text-destructive select-none', className)} {...restProps}>
|
2025-02-03 18:17:07 +03:00
|
|
|
{error.message}
|
|
|
|
</div>
|
|
|
|
);
|
2025-01-31 21:04:21 +03:00
|
|
|
}
|