index.js 1.6 KB
Newer Older
1
import React from 'react';
2
import { Card, Spin } from 'antd';
3
import classNames from 'classnames';
4 5 6

import styles from './index.less';

7
const ChartCard = ({
8
  loading = false, contentHeight, title, avatar, action, total, footer, children, ...rest
9
}) => {
10
  const content = (
11
    <div className={styles.chartCard}>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
      <div
        className={classNames(styles.chartTop, { [styles.chartTopMargin]: (!children && !footer) })}
      >
        <div className={styles.avatar}>
          {
            avatar
          }
        </div>
        <div className={styles.metaWrap}>
          <div className={styles.meta}>
            <span className={styles.title}>{title}</span>
            <span className={styles.action}>{action}</span>
          </div>
          {
            // eslint-disable-next-line
27
            (total !== undefined) && (<div className={styles.total} dangerouslySetInnerHTML={{ __html: total }} />)
28 29
          }
        </div>
30 31
      </div>
      {
32 33 34 35 36 37 38
        children && (
          <div className={styles.content} style={{ height: contentHeight || 'auto' }}>
            <div className={contentHeight && styles.contentFixed}>
              {children}
            </div>
          </div>
        )
39 40
      }
      {
afc163's avatar
afc163 committed
41
        footer && (
42
          <div className={classNames(styles.footer, { [styles.footerMargin]: !children })}>
afc163's avatar
afc163 committed
43 44 45
            {footer}
          </div>
        )
46 47
      }
    </div>
48 49 50 51 52 53 54
  );

  return (
    <Card
      bodyStyle={{ padding: '20px 24px 8px 24px' }}
      {...rest}
    >
afc163's avatar
afc163 committed
55
      {<Spin spinning={loading} wrapperClassName={styles.spin}>{content}</Spin>}
56 57 58
    </Card>
  );
};
59 60

export default ChartCard;