index.js 2.01 KB
Newer Older
1
import React from 'react';
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
2
import { Card } from 'antd';
3
import classNames from 'classnames';
4 5 6

import styles from './index.less';

jim's avatar
jim committed
7
const renderTotal = total => {
8 9
  let totalDom;
  switch (typeof total) {
Wei Zhu's avatar
Wei Zhu committed
10
    case 'undefined':
11 12
      totalDom = null;
      break;
niko's avatar
niko committed
13 14
    case 'function':
      totalDom = <div className={styles.total}>{total()}</div>;
15 16 17 18 19 20 21
      break;
    default:
      totalDom = <div className={styles.total}>{total}</div>;
  }
  return totalDom;
};

ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
22 23 24
class ChartCard extends React.PureComponent {
  renderConnet = () => {
    const { contentHeight, title, avatar, action, total, footer, children, loading } = this.props;
25
    if (loading) {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
26 27 28 29
      return false;
    }
    return (
      <div className={styles.chartCard}>
jim's avatar
jim committed
30
        <div
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
31 32
          className={classNames(styles.chartTop, {
            [styles.chartTopMargin]: !children && !footer,
jim's avatar
jim committed
33 34
          })}
        >
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
35 36 37 38 39 40 41 42
          <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>
            {renderTotal(total)}
          </div>
niko's avatar
niko committed
43
        </div>
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
        {children && (
          <div className={styles.content} style={{ height: contentHeight || 'auto' }}>
            <div className={contentHeight && styles.contentFixed}>{children}</div>
          </div>
        )}
        {footer && (
          <div
            className={classNames(styles.footer, {
              [styles.footerMargin]: !children,
            })}
          >
            {footer}
          </div>
        )}
      </div>
    );
  };
61

ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
62 63 64 65 66 67 68 69 70 71 72 73 74
  render() {
    const {
      loading = false,
      contentHeight,
      title,
      avatar,
      action,
      total,
      footer,
      children,
      ...rest
    } = this.props;
    return (
75
      <Card loading={loading} bodyStyle={{ padding: '20px 24px 8px 24px' }} {...rest}>
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
76 77 78 79 80
        {this.renderConnet()}
      </Card>
    );
  }
}
81 82

export default ChartCard;