index.js 1.68 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 8 9 10 11 12 13 14 15 16 17 18
const renderTotal = (total) => {
  let totalDom;
  switch (typeof total) {
    case undefined:
      totalDom = null;
      break;
    default:
      totalDom = <div className={styles.total}>{total}</div>;
  }
  return totalDom;
};

19
const ChartCard = ({
20
  loading = false, contentHeight, title, avatar, action, total, footer, children, ...rest
21
}) => {
22
  const content = (
23
    <div className={styles.chartCard}>
24 25 26 27 28 29 30 31 32 33 34 35 36
      <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>
37
          {renderTotal(total)}
38
        </div>
39 40
      </div>
      {
41 42 43 44 45 46 47
        children && (
          <div className={styles.content} style={{ height: contentHeight || 'auto' }}>
            <div className={contentHeight && styles.contentFixed}>
              {children}
            </div>
          </div>
        )
48 49
      }
      {
afc163's avatar
afc163 committed
50
        footer && (
51
          <div className={classNames(styles.footer, { [styles.footerMargin]: !children })}>
afc163's avatar
afc163 committed
52 53 54
            {footer}
          </div>
        )
55 56
      }
    </div>
57 58 59 60 61 62 63
  );

  return (
    <Card
      bodyStyle={{ padding: '20px 24px 8px 24px' }}
      {...rest}
    >
afc163's avatar
afc163 committed
64
      {<Spin spinning={loading} wrapperClassName={styles.spin}>{content}</Spin>}
65 66 67
    </Card>
  );
};
68 69

export default ChartCard;