2020-11-14 00:44:26 +03:00
|
|
|
import { FC } from 'react';
|
2020-12-21 11:22:13 +03:00
|
|
|
import { Card, Row } from 'reactstrap';
|
2020-03-05 10:41:55 +03:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { faCircleNotch as preloader } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
|
2020-08-31 19:38:27 +03:00
|
|
|
type MessageType = 'default' | 'error';
|
|
|
|
|
|
|
|
const getClassForType = (type: MessageType) => {
|
|
|
|
const map: Record<MessageType, string> = {
|
2020-03-08 13:35:06 +03:00
|
|
|
error: 'border-danger',
|
2020-08-31 19:38:27 +03:00
|
|
|
default: '',
|
2020-03-08 13:16:57 +03:00
|
|
|
};
|
|
|
|
|
2020-08-31 19:38:27 +03:00
|
|
|
return map[type];
|
2020-03-08 13:16:57 +03:00
|
|
|
};
|
2020-08-31 19:38:27 +03:00
|
|
|
const getTextClassForType = (type: MessageType) => {
|
|
|
|
const map: Record<MessageType, string> = {
|
2020-03-08 13:35:06 +03:00
|
|
|
error: 'text-danger',
|
2020-08-31 19:38:27 +03:00
|
|
|
default: 'text-muted',
|
2020-03-08 13:16:57 +03:00
|
|
|
};
|
|
|
|
|
2020-08-31 19:38:27 +03:00
|
|
|
return map[type];
|
2020-03-08 13:16:57 +03:00
|
|
|
};
|
|
|
|
|
2020-12-21 11:57:46 +03:00
|
|
|
export interface MessageProps {
|
2020-12-21 11:22:13 +03:00
|
|
|
className?: string;
|
2020-08-31 19:38:27 +03:00
|
|
|
loading?: boolean;
|
2020-12-12 14:04:20 +03:00
|
|
|
fullWidth?: boolean;
|
2020-08-31 19:38:27 +03:00
|
|
|
type?: MessageType;
|
|
|
|
}
|
2020-03-05 10:41:55 +03:00
|
|
|
|
2020-12-21 11:22:13 +03:00
|
|
|
const Message: FC<MessageProps> = ({ className, children, loading = false, type = 'default', fullWidth = false }) => {
|
2020-12-12 14:04:20 +03:00
|
|
|
const classes = classNames({
|
|
|
|
'col-md-12': fullWidth,
|
|
|
|
'col-md-10 offset-md-1': !fullWidth,
|
|
|
|
});
|
2020-03-05 10:41:55 +03:00
|
|
|
|
|
|
|
return (
|
2020-12-21 11:22:13 +03:00
|
|
|
<Row noGutters className={className}>
|
|
|
|
<div className={classes}>
|
|
|
|
<Card className={getClassForType(type)} body>
|
|
|
|
<h3 className={classNames('text-center mb-0', getTextClassForType(type))}>
|
|
|
|
{loading && <FontAwesomeIcon icon={preloader} spin />}
|
|
|
|
{loading && <span className="ml-2">{children ?? 'Loading...'}</span>}
|
|
|
|
{!loading && children}
|
|
|
|
</h3>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
</Row>
|
2020-03-05 10:41:55 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-03-08 13:16:57 +03:00
|
|
|
export default Message;
|