2020-03-05 10:41:55 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { Card } from 'reactstrap';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { faCircleNotch as preloader } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
|
2020-03-08 13:16:57 +03:00
|
|
|
const getClassForType = (type) => {
|
|
|
|
const map = {
|
|
|
|
error: 'bg-danger',
|
|
|
|
};
|
|
|
|
|
|
|
|
return map[type] || 'bg-light';
|
|
|
|
};
|
|
|
|
const getTextClassForType = (type) => {
|
|
|
|
const map = {
|
|
|
|
error: 'text-white',
|
|
|
|
};
|
|
|
|
|
|
|
|
return map[type] || 'text-muted';
|
|
|
|
};
|
|
|
|
|
2020-03-05 10:41:55 +03:00
|
|
|
const propTypes = {
|
|
|
|
noMargin: PropTypes.bool,
|
|
|
|
loading: PropTypes.bool,
|
|
|
|
children: PropTypes.node,
|
2020-03-08 13:16:57 +03:00
|
|
|
type: PropTypes.oneOf([ 'default', 'error' ]),
|
2020-03-05 10:41:55 +03:00
|
|
|
};
|
|
|
|
|
2020-03-08 13:16:57 +03:00
|
|
|
const Message = ({ children, loading = false, noMargin = false, type = 'default' }) => {
|
|
|
|
const cardClasses = classNames(getClassForType(type), { 'mt-4': !noMargin });
|
2020-03-05 10:41:55 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="col-md-10 offset-md-1">
|
|
|
|
<Card className={cardClasses} body>
|
2020-03-08 13:16:57 +03:00
|
|
|
<h3 className={classNames('text-center mb-0', getTextClassForType(type))}>
|
2020-03-05 10:41:55 +03:00
|
|
|
{loading && <FontAwesomeIcon icon={preloader} spin />}
|
|
|
|
{loading && !children && <span className="ml-2">Loading...</span>}
|
|
|
|
{children}
|
|
|
|
</h3>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-03-08 13:16:57 +03:00
|
|
|
Message.propTypes = propTypes;
|
2020-03-05 10:41:55 +03:00
|
|
|
|
2020-03-08 13:16:57 +03:00
|
|
|
export default Message;
|