Passed
Push — master ( c49fa8...c04ae7 )
by Guangyu
05:06 queued 11s
created

src/components/common/FalconCardHeader.js   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 66
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 56
mnd 2
bc 2
fnc 0
dl 0
loc 66
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React from 'react';
2
import PropTypes from 'prop-types';
3
import { Col, CardHeader, Row } from 'reactstrap';
4
import classNames from 'classnames';
5
6
const Title = ({ titleTag: TitleTag, className, breakPoint, children }) => (
7
  <TitleTag
8
    className={classNames(
9
      {
10
        'mb-0': !breakPoint,
11
        [`mb-${breakPoint}-0`]: !!breakPoint
12
      },
13
      className
14
    )}
15
  >
16
    {children}
17
  </TitleTag>
18
);
19
20
Title.propsType = {
21
  breakPoint: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', 'xxl']),
22
  titleTag: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
23
  className: PropTypes.string,
24
  children: PropTypes.node
25
};
26
27
Title.defaultProps = { titleTag: 'h5' };
28
29
const FalconCardHeader = ({ title, light, titleTag, titleClass, className, breakPoint, children }) => (
30
  <CardHeader className={classNames({ 'bg-light': light }, className)}>
31
    {children ? (
32
      <Row className="align-items-center">
33
        <Col>
34
          <Title breakPoint={breakPoint} titleTag={titleTag} className={titleClass}>
35
            {title}
36
          </Title>
37
        </Col>
38
        <Col
39
          {...{ [breakPoint ? breakPoint : 'xs']: 'auto' }}
40
          className={`text${breakPoint ? `-${breakPoint}` : ''}-right`}
41
        >
42
          {children}
43
        </Col>
44
      </Row>
45
    ) : (
46
      <Title breakPoint={breakPoint} titleTag={titleTag} className={titleClass}>
47
        {title}
48
      </Title>
49
    )}
50
  </CardHeader>
51
);
52
53
FalconCardHeader.propTypes = {
54
  title: PropTypes.node.isRequired,
55
  light: PropTypes.bool,
56
  breakPoint: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', 'xxl']),
57
  titleTag: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
58
  titleClass: PropTypes.string,
59
  className: PropTypes.string,
60
  children: PropTypes.node
61
};
62
63
FalconCardHeader.defaultProps = { light: true };
64
65
export default FalconCardHeader;
66