@devopness/ui-react
Version:
Devopness Design System React Components - Painless essential DevOps to everyone
44 lines (43 loc) • 1.41 kB
TypeScript
/** Error with a type field that can be 'required' or any other string except 'required' */
type ErrorWithType = {
type: 'required' | Omit<string, 'required'>;
};
/** Error containing a direct message string */
type ErrorWithMessage = {
message: string;
};
/** API error response containing nested message */
type APIError = {
errors: {
message: string;
};
};
type ErrorMessageProps = {
/** Renders the following error formats, by first match:
*
* 1. { type: 'required' }
*
* 2. { message: string }
*
* 3. { errors: { message: string } } [1]
*
* 4. Record<string, any> [2]
*
* [1] API Error response
* [2] Custom error objects
*/
error?: ErrorWithType | ErrorWithMessage | APIError | Record<string, any> | null;
/** Additional CSS classes to apply to the error message container */
className?: string;
};
/**
* Component that displays error messages in a standardized format.
* Handles multiple error object formats and renders them consistently.
*
* @param props - Component props
* @param props.error - Error object in various possible formats
* @param props.className - Additional CSS classes to apply to the container
*/
declare const ErrorMessage: ({ error, className }: ErrorMessageProps) => import("react/jsx-runtime").JSX.Element;
export type { ErrorMessageProps };
export { ErrorMessage };