index.js 1.8 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 19 20 21
const renderTotal = (total) => {
  let totalDom;
  switch (typeof total) {
    case undefined:
      totalDom = null;
      break;
    case 'string':
      totalDom = <div className={styles.total} dangerouslySetInnerHTML={{ __html: total }} />;
      break;
    default:
      totalDom = <div className={styles.total}>{total}</div>;
  }
  return totalDom;
};

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

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

export default ChartCard;