mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-06 08:08:10 +08:00
29 lines
738 B
JavaScript
29 lines
738 B
JavaScript
import { React, PropTypes, RegExpUtils } from 'mailspring-exports';
|
|
|
|
const FormErrorMessage = props => {
|
|
const { message, empty } = props;
|
|
if (!message) {
|
|
return <div className="message empty">{empty}</div>;
|
|
}
|
|
|
|
const result = RegExpUtils.urlRegex({ matchEntireString: false }).exec(message);
|
|
if (result) {
|
|
const link = result[0];
|
|
return (
|
|
<div className="message error">
|
|
{message.substr(0, result.index)}
|
|
<a href={link}>{link}</a>
|
|
{message.substr(result.index + link.length)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return <div className="message error">{message}</div>;
|
|
};
|
|
|
|
FormErrorMessage.propTypes = {
|
|
empty: PropTypes.string,
|
|
message: PropTypes.string,
|
|
};
|
|
|
|
export default FormErrorMessage;
|