mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-22 22:00:50 -04:00
37 lines
795 B
JavaScript
37 lines
795 B
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { Alert } from '@freecodecamp/react-bootstrap';
|
|
|
|
import './flash.css';
|
|
|
|
function createDismissHandler(fn, id) {
|
|
return () => fn(id);
|
|
}
|
|
|
|
function Flash({ messages, onClose }) {
|
|
return messages.map(({ type, message, id }) => (
|
|
<Alert
|
|
bsStyle={type}
|
|
className='flash-message'
|
|
key={id}
|
|
onDismiss={createDismissHandler(onClose, id)}
|
|
>
|
|
<div dangerouslySetInnerHTML={{ __html: message }} />
|
|
</Alert>
|
|
));
|
|
}
|
|
|
|
Flash.displayName = 'FlashMessages';
|
|
Flash.propTypes = {
|
|
messages: PropTypes.arrayOf(
|
|
PropTypes.shape({
|
|
id: PropTypes.string,
|
|
type: PropTypes.string,
|
|
message: PropTypes.string
|
|
})
|
|
),
|
|
onClose: PropTypes.func.isRequired
|
|
};
|
|
|
|
export default Flash;
|