Total Complexity | 0 |
Complexity/F | 0 |
Lines of Code | 49 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 0 |
1 | import React from 'react'; |
||
2 | import { Card } from 'reactstrap'; |
||
3 | import classNames from 'classnames'; |
||
4 | import PropTypes from 'prop-types'; |
||
5 | import { faCircleNotch as preloader } from '@fortawesome/free-solid-svg-icons'; |
||
6 | import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; |
||
7 | |||
8 | 4 | const getClassForType = (type) => { |
|
9 | 7 | const map = { |
|
10 | error: 'border-danger', |
||
11 | }; |
||
12 | |||
13 | 7 | return map[type] || ''; |
|
14 | }; |
||
15 | 4 | const getTextClassForType = (type) => { |
|
16 | 7 | const map = { |
|
17 | error: 'text-danger', |
||
18 | }; |
||
19 | |||
20 | 7 | return map[type] || 'text-muted'; |
|
21 | }; |
||
22 | |||
23 | 4 | const propTypes = { |
|
24 | noMargin: PropTypes.bool, |
||
25 | loading: PropTypes.bool, |
||
26 | children: PropTypes.node, |
||
27 | type: PropTypes.oneOf([ 'default', 'error' ]), |
||
28 | }; |
||
29 | |||
30 | 4 | const Message = ({ children, loading = false, noMargin = false, type = 'default' }) => { |
|
31 | 7 | const cardClasses = classNames('bg-light', getClassForType(type), { 'mt-4': !noMargin }); |
|
32 | |||
33 | 7 | return ( |
|
34 | <div className="col-md-10 offset-md-1"> |
||
35 | <Card className={cardClasses} body> |
||
36 | <h3 className={classNames('text-center mb-0', getTextClassForType(type))}> |
||
37 | {loading && <FontAwesomeIcon icon={preloader} spin />} |
||
38 | {loading && <span className="ml-2">{children || 'Loading...'}</span>} |
||
39 | {!loading && children} |
||
40 | </h3> |
||
41 | </Card> |
||
42 | </div> |
||
43 | ); |
||
44 | }; |
||
45 | |||
46 | 4 | Message.propTypes = propTypes; |
|
47 | |||
48 | export default Message; |
||
49 |