Jelajahi Sumber

fix ChartCard total issue close #1110

ddcat1115 7 tahun lalu
induk
melakukan
bf833b0360
1 mengubah file dengan 16 tambahan dan 4 penghapusan
  1. 16 4
      src/components/Charts/ChartCard/index.js

+ 16 - 4
src/components/Charts/ChartCard/index.js

@@ -4,6 +4,21 @@ import classNames from 'classnames';
 
 import styles from './index.less';
 
+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;
+};
+
 const ChartCard = ({
   loading = false, contentHeight, title, avatar, action, total, footer, children, ...rest
 }) => {
@@ -22,10 +37,7 @@ const ChartCard = ({
             <span className={styles.title}>{title}</span>
             <span className={styles.action}>{action}</span>
           </div>
-          {
-            // eslint-disable-next-line
-            (total !== undefined) && (<div className={styles.total} dangerouslySetInnerHTML={{ __html: total }} />)
-          }
+          {renderTotal(total)}
         </div>
       </div>
       {