Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mastodon
GitHub Repository: mastodon/joinmastodon
Path: blob/main/components/Statistic.tsx
1006 views
1
import { useIntl } from "react-intl"
2
import { formatNumber, percIncrease } from "../utils/numbers"
3
import SkeletonText from "./SkeletonText"
4
5
const Statistic: React.FC<{
6
Icon?: (props: React.SVGProps<SVGElement>) => React.ReactElement
7
label?: any
8
currentValue?: number
9
prevValue?: number
10
}> = ({ Icon, label, currentValue, prevValue }) => {
11
const intl = useIntl()
12
const change = currentValue ? percIncrease(prevValue, currentValue) : 0
13
14
return (
15
<div className="flex items-center">
16
<div className="relative flex h-12 w-12 shrink-0 items-center justify-center rounded-md bg-blurple-500 text-white">
17
{Icon && <Icon className="h-5 w-5" />}
18
</div>
19
20
<div className="grow px-3">
21
<span className="b3 !font-extrabold text-gray-1">
22
{label || <SkeletonText className="w-[16ch]" />}
23
</span>
24
<span className="block">
25
<span className="h6">
26
{currentValue ? (
27
formatNumber(currentValue, intl.locale)
28
) : (
29
<SkeletonText className="w-[4ch]" />
30
)}
31
</span>
32
{change > 0 && (
33
<span className="b3 px-1 !font-extrabold text-nightshade-300">
34
+{Math.round(change * 100)}%
35
</span>
36
)}
37
</span>
38
</div>
39
</div>
40
)
41
}
42
43
export default Statistic
44
45