// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React from 'react'; // accepts either a single error or an array of errors type Props = { type?: React.ReactNode; error?: React.ReactNode; textClassName?: string; iconClassName?: string; margin?: boolean; errors?: React.ReactNode[]; } export default class FormError extends React.PureComponent { public static defaultProps = { error: null, errors: [], }; public render() { const {error = null, errors = [], iconClassName, margin, textClassName, type} = this.props; if (!error && errors.length === 0) { return null; } // look for the first truthy error to display let message = error; if (!message) { for (const err of errors) { if (err) { message = err; } } } if (!message) { return null; } if (type === 'modal') { return (
); } if (type === 'backstage') { return (
); } if (margin) { return (
); } return (
); } }