import React from 'react'; import PropTypes from 'prop-types'; const propTypes = { intent: PropTypes.string.isRequired, title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired, onRemove: PropTypes.func.isRequired, children: PropTypes.string, isRemovable: PropTypes.bool, }; class Alert extends React.PureComponent { getIconClass(intent) { switch (intent) { case 'success': return 'sf3-font sf3-font-check-circle'; case 'warning': return 'sf3-font sf3-font-exclamation-triangle'; case 'none': return 'sf3-font sf3-font-exclamation-circle'; case 'danger': return 'sf3-font sf3-font-exclamation-circle'; default: return 'sf3-font sf3-font-check-circle'; } } render() { const { intent, title, children, isRemovable, onRemove } = this.props; const iconClass = this.getIconClass(intent); return (

{title}

{children ?

{children}

: null}
{isRemovable && (
×
)}
); } } Alert.propTypes = propTypes; export default Alert;