File size: 1,907 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// @flow

import * as React from "react";
import cn from "classnames";

import { Card, Text, Header, Icon } from "../";

type Props = {|
  +className?: string,
  /**
   * The % amount by which your total has increased
   */
  +movement: number,
  /**
   * The main number displayed within the Card
   */
  +total: string,
  /**
   * The text label displayed within the Card
   */
  +label: string,
  /**
   * The layout to render
   */
  +layout?: 1 | 2,
  /**
   * A Chart to be included at the bottom of layout 2
   */
  +chart?: React.Node,
|};

/**
 * Used for dispaying an individual statistic/number with 2 potential layouts
 */
function StatsCard({
  className,
  movement,
  total,
  label,
  layout = 1,
  chart,
}: Props): React.Node {
  const classes = cn(className);
  const movementString = `${movement > 0 ? "+" : ""}${movement}%`;
  const movementColor = !movement ? "yellow" : movement > 0 ? "green" : "red";
  if (layout === 2) {
    return (
      <Card className={classes}>
        <Card.Body>
          <div className={`card-value float-right text-${movementColor}`}>
            {movementString}
          </div>
          <Header.H3 className="mb-1">{total}</Header.H3>
          <Text muted>{label}</Text>
        </Card.Body>
        {chart && <div className="card-chart-bg">{chart}</div>}
      </Card>
    );
  }

  return (
    <Card className={classes}>
      <Card.Body className="p-3 text-center">
        <Text color={movementColor} className="text-right">
          {movementString}
          <Icon
            name={
              !movement ? "minus" : movement > 0 ? "chevron-up" : "chevron-down"
            }
          />
        </Text>
        <Header className="m-0">{total}</Header>
        <Text color="muted" className=" mb-4">
          {label}
        </Text>
      </Card.Body>
    </Card>
  );
}

StatsCard.displayName = "StatsCard";

export default StatsCard;