Completed
Push — master ( e26cdc...da6d7a )
by Alejandro
17s queued 11s
created

src/utils/Message.js

Complexity

Total Complexity 0
Complexity/F 0

Size

Lines of Code 49
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 0
eloc 41
mnd 0
bc 0
fnc 0
dl 0
loc 49
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
ccs 11
cts 11
cp 1
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