-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStats.js
61 lines (54 loc) · 1.24 KB
/
Stats.js
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
import React from "react";
import "./Stats.css";
import classnames from "classnames";
import { humanizeCount, pluralize } from "./lang/humanize.js";
export const countStat = ({ count, what, id = "", divider = false, title }) => {
return {
id: `${what}:count:${id}`,
value: humanizeCount(count),
label: pluralize(count, what, false),
divider: divider,
title: title
};
};
const StatValue = ({ value }) => {
if (typeof value === "string") {
if (value.endsWith("%")) {
return (
<strong>
{value.substring(0, value.length - 1)}
<small className="percent">%</small>
</strong>
);
}
}
return <strong>{value}</strong>;
};
export const Stat = ({
value,
label,
className,
divider = false,
title = ""
}) => {
return (
<div
className={classnames("Stat", className, { WithDivider: divider })}
title={title}
>
<StatValue value={value} />
<small>{label}</small>
</div>
);
};
export const Stats = ({ stats, divided }) => {
return (
<div className={classnames("Stats", { WithDivider: divided })}>
{stats
.filter(s => s.value !== undefined)
.map(s => (
<Stat key={s.id} {...s} />
))}
</div>
);
};